I use python to work with image processing. I'm used to cut, draw and other things, but for one image. Like in the script below, how can i aply a loop in the script to do for several images?
import PIL
import Image
im=Image.open('test.tif')
box=(50, 50, 200, 200)
im_crop=im.crop(box)
im_crop.show()
You need to wrap it in a for
loop, and give that loop a list of files.
One very easy way to get a list of all the TIF files in the current directory is with glob
, like this:
import PIL
import Image
import glob
for filename in glob.glob("*.tif"):
im=Image.open(filename)
box=(50, 50, 200, 200)
im_crop=im.crop(box)
im_crop.show()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With