Classify chicken parts in breast, legs+tights and wings
The input image is a gray-scale image of many different chicken parts. The purpose is to classify them in breast, legs+tights, tights and wings.
The input image is read.
1. a = mmreadgray('chickparts.tif'); 2. mmshow(a);
Thresholding and labeling
Convert to binary objects by thresholding and then labeling the objects.
1. from ia870 import iacmp 2. from ia870 import ialabel 3. from ia870 import iaglblshow 4. 5. 6. b = iacmp(a,'>=', uint8(100)); 7. mmshow(b); 8. c = ialabel(b); 9. adshow(iaglblshow(c,'border'));
Measure the area o each object and put this value as the pixel object value. For displaying purpose, overlay the background as red in the right image below.
1. from ia870 import iablob 2. 3. 4. d = iablob(c,'area'); 5. mmshow(d); 6. mmshow(d, iacmp(d,'==',0));
Warning: downcasting image from int32 to uint16 (may lose precision) Warning: downcasting image from int32 to uint16 (may lose precision)
Select the wings and tights
The wings are detected by finding objects with area 100 and 2500 pixels. The tights are selected as connected objects with area between 2500 and 5500 pixels.
1. wings = iacmp( uint16(100),'<=',d, '<=', uint16(2500)); 2. mmshow(wings); 3. tights = iacmp( uint16(2500),'<',d, '<=', uint16(5500)); 4. mmshow(tights);
Select the legs and breast
The legs+tights have area larger than 5500 and smaller than 8500 pixels and the breast is the largest connected object with area larger than 8500 pixels
1. legs = iacmp( uint16(5500), '<', d, '<=', uint16(8500)); 2. mmshow(legs); 3. breast = iacmp( d,'>', uint16(8500)); 4. mmshow(breast);
Overlay the contour of the detected parts over the original image
1. from ia870 import iagradm 2. 3. 4. mmshow(a, iagradm(wings), iagradm(tights), iagradm(legs),iagradm(breast));