1

I am trying to do some image processing in Python using PIL. I need to raise a flag is the picture is has red colour in it. Can someone please give me some pointers?

I figured one can use split function on an image and split it into the individual channels. After this, I am not sure what to do.

3
  • 2
    A single red pixel? Large red region? Pure red or some close (pink)? Elaborate some clear criteria. Commented Nov 25, 2015 at 7:23
  • Well I am not sure yet. I meant read as an example. Sorry, should have been clearer! Its not a single red pixel but is a large region. And I am not sure about the colour yet. I am just looking for some very general approach to solve this sort of problem. Thanks a lot! Commented Nov 26, 2015 at 2:57
  • the general approach depends on the application: detecting skin (nudity) is one thing, classifying galaxies is another, counting nuclei yet another, etc. Commented Nov 26, 2015 at 15:31

1 Answer 1

1

Try something like this. It iterates over each pixel and checks if it's the one you want.

from PIL import Image
desired_colour = (255, 0, 0)
im = Image.open("myfile.jpg")
w, h = im.size
pix = im.load()
found = False
for i in range(w):
    for j in range(h):
        if pix[i, j] == desired_colour:
            # Bingo! Found it!
            found = True
            break
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.