userDS - 2 months ago 5x

Python Question

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

Answer

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'.

Source (Stackoverflow)

Comments