E Laboratories
There are textbooks full of image processing and detection tasks. This is a very broad and active research area, so we are only getting an idea of what is possible.
An easy way of detecting shapes, e.g. distinguishing squares, rectangles, and circles in an image, is to calculate “moments”. First of all, you have to identify a continuous object from a pixel pattern in a binary (black and white) image. Then, you compute the object’s area and circumference. From the relationship between these two values you can distinguish several object categories such as circle, square, rectangle.
EXPERIMENT 22 Object Detection by Color
Another method for object detection is color recognition, as mentioned above. Here, the task is to detect a colored object from a background and possibly other objects (with different colors).
Color detection is simpler than shape detection in most cases, but it is not as straightforward as it seems. The bright yellow color of a tennis ball varies quite a bit over its circular image, because the reflection depends on the angle of the ball’s surface patch to the viewer. That is, the outer areas of the disk will be darker than the inner area. Also, the color values will not be the same when looking at the same ball from different directions, because the lighting (e.g. ceiling lights) will look different from a different point of view. If there are windows in your lab, the ball’s color values will change during the day because of the movement of the sun. So there are a number of problems to be aware of, and this is not even taking into account imperfections on the ball itself, like the manufacturer’s name printed on it, etc.
Many image sources return color values as RGB (red, green, blue). Because of the problems mentioned before, these RGB values will vary a lot for the same object, although its basic color has not changed. Therefore it is a good idea to convert all color values to HSV (hue, saturation, value) before processing and then mainly work with the more stable hue of a pixel.
The idea is to detect an area of hue values similar to the specified object hue that should be detected. It is important to analyze the image for a color “blob”, or a group of matching hue values in a neighborhood area. This can be achieved by the following steps:
a.Convert RGB input image to HSV.
b.Generate binary image by checking whether each pixel’s hue value is within a certain range to the desired object hue:
binaryi,j = | huei,j – hueobj | < H
c.For each row, calculate the matching binary pixels.
d.For each column, calculate the matching binary pixels.
e.The row and column counter form a basic histogram. Assuming there is only one object to detect, we can use these values directly: