拆分圖像是一個python軟件包,您可以從命令行中使用,將圖像拆分為圖塊。
pip install split-image
從命令行:
split-image [-h] [-s] image_path rows cols
作為常規模塊導入:
from split_image import split_image
split_image ( image_path , rows , cols , should_square , should_cleanup , [ output_dir ])
# e.g. split_image("bridge.jpg", 2, 2, True, False)
split-image cat.png 2 2
這將cat.png
圖像分成4個圖塊( 2
行和2
列)。
split-image bridge.png 3 4 -s
這將bridge.png
圖像分配為12個瓷磚( 3
行和4
列)。 -square
參數在將圖像分開之前將圖像調整為正方形。用於填充正方形的背景顏色是從圖像自動確定的。
split-image cat.jpg 2 2 -r
將嘗試合併類似命名的圖像圖塊與一個圖像。因此,如果您在當前目錄中有這些圖像:
cat_0.jpg
cat_1.jpg
cat_2.jpg
cat_3.jpg
他們將根據文件名合併:
split-image image_dir 4 2
將拆分image_dir
文件夾中包含的所有圖像。
split-image test.jpg 4 2 --cleanup
過程後將刪除原始圖像。
split-image test.jpg 4 2 --load-large-images
使用大圖像(超過178,956,970像素)時,您可能會遇到錯誤。傳遞此標誌以覆蓋此。
split-image test.jpg 2 2 --output-dir <dir-name>
為圖像圖塊設置輸出目錄(例如'Outp/images')。默認為當前工作目錄。
split-image test.jpg 3 4 --quiet
運行時會抑制所有日誌消息(錯誤和警告除外)。
positional arguments:
image_path The path to the image or directory with images to split.
rows How many rows to split the image into (horizontal split).
cols How many columns to split the image into (vertical split).
optional arguments:
-h, --help Show this help message and exit
-s, --square If the image should be resized into a square before splitting.
-r, --reverse Reverse the splitting process, i.e. merge multiple tiles of an image into one.
--cleanup After splitting or merging, delete the original image/images.
--load-large-images Pass this flag for use with really large images.
--output-dir <dir-name> Set the output directory for image tiles (e.g. 'outp/images').
--quiet Run without printing any messages.
貓照片由Manja Vitoloil在Unsplash上
蘭斯·阿斯珀(Lance Asper)的橋樑照片