Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- >> clear
- >> I = imread('target.jpg');
- figure, imshow(I);
- >> th = graythresh(I);
- BW = ~im2bw(I,th);
- figure, imshow(BW);
- >> bw_a = padarray(BW,[1 1],1,'pre');
- BW = imfill(bw_a,'holes');
- BW = BW(2:end,2:end);
- figure, imshow(BW);
- >> imgTwoAdjacent = bwareaopen(BW,5420); %figure, imshow(imgTwoAdjacent);
- imgRemain1 = imsubtract(BW,imgTwoAdjacent); %figure, imshow(imgRemain1);
- imgMedium = bwareaopen(imgRemain1,2275); %figure, imshow(imgMedium);
- imgSmall = imsubtract(logical(imgRemain1),imgMedium); %figure, imshow(imgSmall);
- >> [imgMedium,numMedium] = bwlabel(imgMedium);
- figure, imshow(imgMedium);
- title(['#medium: ' num2str(numMedium) '']);
- >> [imgSmall,numSmall] = bwlabel(imgSmall);
- figure, imshow(imgSmall);
- title(['#small: ' num2str(numSmall) '']);
- >> [imgTwoAdjacent,numTwoAdjacent] = bwlabel(imgTwoAdjacent);
- figure, imshow(imgTwoAdjacent);
- title(['#2 Cell: ' num2str(numTwoAdjacent) '']);
Advertisement
Add Comment
Please, Sign In to add comment