1

I have an image image.png and I want to find all clipped pixels. Here is what I have so far:

for i in range(1,width):
    for j in range(1, height):
        r,g,b = image.getpixel((i,j))
        If( ): # I don't know what should be the condition here
           # do something else

I use Python, Tkinter, Pil.

Thanks

userDS
  • 15
  • 5
  • Your pixel could be clipped in just one of R,G and B, or two, or all three. If the PIL `getpixel()` values are always scaled on `[0-255]`, the test would be if any of R,G or B is equal to 255. But you better watch out for 16-bit images that will be 65535 when saturated and also indexed/palettised images where the values you read may be indices rather than RGB values. – Mark Setchell Aug 22 '16 at 13:40

1 Answers1

0

If by 'clipped' you mean saturated, then you probably want to create a threshold based on the intensity of the pixel. There are a few equations that try to determine this, but I would recommend one of the Grayscale equations. Looking at the equation used in ATSC:

I=.2126*r+.7152*g+.0722*b

Then just figure out what range of values for I you considered 'clipped'.

Liam Kelly
  • 3,524
  • 1
  • 17
  • 41