I am working with a database of images with dimensions of 4000 x 3000 pixels, and I wish to slice each image in a directory based on a pixel size (1000 x 1000). I am using the glob
and image_slicer
modules currently, and am currently performing trial-and-error to get the images to the preferred pixel size.
import glob, os
import image_slicer
for file in glob.glob('~\\test_folder\\*.jpg'):
image_slicer.slice(file, 15)
A slice of 15 generates output photos with dimensions of 1000 x 750, which is close but still no cigar. Is there a way I can specify the specific dimensions?
If you have a look at the source code for image_slicer.slice there are two parameters row
and col
that you can specify. The source code shows how they are used to calculate the number of tiles in the horizontal and vertical directions. You can work backwards from this to see how many rows and columns you need to get 1000x1000 pixel tiles. In your case (based on getting 4000x3000 images to 1000x1000 tiles) it is row=3
and col=4
. i.e.
import glob, os
import image_slicer
for file in glob.glob('~\\test_folder\\*.jpg'):
image_slicer.slice(file, row=3, col=4)