python image - ignore values in resize

  • Thread starter Travis Kirstine
  • Start date
T

Travis Kirstine

I have be attempting to resize (downsample) a RGB image using the
python image library resize function. Everything works fine but I
would like to exclude black values 0,0,0 from the calculations. I
have tried creating a alpha mask based on black values then performing
the resize but that only create partially transparent tiles in the
regions that had black values

im = Image.open('src.tif')
multi = im.split
mask = im.point(lambda i: i == 0 and 255) # get 0 values
mask = mask.convert('L')
mask = ImageChops.invert(mask) # make the 0 values 255 for transparency
out_im = Image.merge('RGBA', (multi[0], multi[1], multi[2], mask))
out_im = out_im.resize((100, 100), Image.ANTIALIAS)
out_im = out_im.convert('RGB')
out_im.save('dst.tif')



Any help would be great
 
L

Lie Ryan

Travis said:
I have be attempting to resize (downsample) a RGB image using the
python image library resize function. Everything works fine but I
would like to exclude black values 0,0,0 from the calculations. I
have tried creating a alpha mask based on black values then performing
the resize but that only create partially transparent tiles in the
regions that had black values

Crop the image first.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top