First off, I am not sure if this is the correct stackexchange site to ask this question on, so moderators can feel free to move it.

I am working on an application that identifies an object in an image. For example, let's say that the object is an apple, and the apple can be green, red, or both.

My plan is to create an array the same size as the image, then scan through the image, pixel by pixel, and if the current pixel is within my range of colors (green-ish or red-ish), add a 1 to the corresponding location in the array, else add a 0.

After this scan through the array, I will have an array of 1s and 0s, which will hopefully contain a concentration of 1s, representing the apple.

I am a computer science student, but have yet to take an AI class. So my question is: is this a good way to go about doing this? Or are there more established AI methods (or algorithms) for identifying objects in an image based on color?

EDIT: I should clarify that the problem isn't identifying if the image contains an apple, the problem is identifying where the apple is in the image.

  • $\begingroup$ If you will convert your image into HSV space, it would be more easy to classify objects based on their colors. $\endgroup$ – Eddy_Em Apr 22 '13 at 16:12
  • $\begingroup$ Do you think HSV would be better than HSL ? (I was planning on using HSL). $\endgroup$ – TylerAndFriends Apr 22 '13 at 16:19
  • $\begingroup$ There's no much difference between them. $\endgroup$ – Eddy_Em Apr 22 '13 at 16:22

The general class for this problem is Template matching. The most common approach is performing a cross correlation of the template, in your example an apple, and an image which may contain the template.

A Google search for "template matching fast normalized cross correlation" will bring up some literature that should be helpful.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.