I want to get only the rectangles at the bottom, but the problem is that they are not all evenly divided by black. this is what I've got so far: http://i1016.photobucket.com/albums/af289/galga2010/Figure2_zps65020947.png
With this code:
clearclcclose allimg = '4Test.png';I = imread(img);Ibw = rgb2gray(I);imshow(Ibw);Ifill = imfill(Ibw,'holes');imshow(Ifill);Iarea = bwareaopen(Ifill,100);imshow(Iarea);Ifinal = bwlabel(Iarea);imshow(Ifinal);stat = regionprops(Ifinal,'boundingbox');imshow(I); hold on;shpNum = 0;green = 0;red = 0;for cnt = 1 : numel(stat) bb = stat(cnt).BoundingBox; if (bb(1,3)<800) x = bb(1,1); y = bb(1,2); Color = impixel(I,x + 2,y + 2); if Color == [28 131 4]; green = green +1; elseif Color == [237 28 36] red = red +1; end rectangle('position',bb,'edgecolor','b','linewidth',2); shpNum = shpNum + 1; endendformatSpec = 'There are %d rectangles \n';fprintf(formatSpec,shpNum);formatSpec = 'There are %d green rectanlges \n';fprintf(formatSpec,green);formatSpec = 'There are %d red rectangles \n';fprintf(formatSpec,red);
Any Ideas?
Thank you
Best Answer