A color image is a digital array of pixel containing a color information. Each image can be decomposed into three different layers according to the three color channels encoded: Red, Green and Blue.
For instance, a 8 eight bits color images encode the Red and Green channel with three bits and the blue with two. Which could encode 256 different colors.
EXERCISE:
Use the idea of color segmentation and color histogram in order to identify the pig and the tag in the image.
For Example:
There are many approaches to this problem. Mine is to get first the green tag in the image because it's easier to do it and then identify the pig. Below shows what I did to identify the green tag of the pig:
1. After reading the image, convert the image from RGB colorspace to HSV colorspace.
2. Define range of green color in HSV using color picker or color histogram. Hue, Saturation, Value or HSV is a color model that describes colors (hue or tint) in terms of their shade (saturation or amount of gray) and their brightness (value or luminance)
3. Threshold the HSV image to get only the green tag
4. Bitwise-AND the new image (mask) and the original image, then show the output image
Below is the code for the steps:
OUTPUT:
original image |
original image |
HSV |
TO IDENTIFY THE PIG:
Repeat the process above but change the HSV color range to identify the body of the pig.
These are some of the results:
As you can see in the above images, I got poor results in identifying the pig. Maybe because the images are diverse and don't have uniform background. Different lighting is applied to the images. These are some recommendations:
1. Capture a good images of pigs. As you can see in the above results, most of the result images don't capture the feet of the pig perhaps because the pig has dirty feet and it's hard to identify the pig's feet from the pig's body.
2. Pig images should have a uniform and distinct background to easily identify the pig from the background. Moreover, these images of pigs should have uniform lighting setup.
3. Use another colorspace to detect pig's skin. I only used HSV colorspace in this problem. Perhaps you can explore on using other colorspaces like YCbCr, etc.