[Image-SIG] threshold cutoff

Noah.org noahspurrier at gmail.com
Mon Jun 18 17:43:13 CEST 2007


How can I set the absolute white or black level of an image?
I want all pixels above or below a certain value clipped.
For example, I want all pixels brighter than 200 to be set to 255
(assuming an 8-bit gray-scale image).

It seems like ImageOps.autocontrast(image, cutoff=0) is close
to what I want, but I was frustrated in my attempts to use cutoff.
It didn't seem to do what I expected. If I set an extreme cutoff=50
I ended up with a pale, gray washed-out image. That is not totally
surprising since I am basically throwing away large parts of the image,
but what seemed odd is that I did not end up with any blacks.
The docs say that after applying the histogram cutoff that the
darkest remaining pixel becomes black, but I didn't get any blacks.

    im1 = Image.open("image1.jpg")
    im1.draft('L',(320,240))
    im1.load()
    im1 = ImageOps.autocontrast(im1, cutoff=50)

Yours,
Noah


More information about the Image-SIG mailing list