maygapixel

Untitled

Dec 17th, 2017
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.93 KB | None | 0 0
  1. >> clear
  2. >> I = imread('target.jpg');
  3. figure, imshow(I);
  4. >> th = graythresh(I);
  5. BW = ~im2bw(I,th);
  6. figure, imshow(BW);
  7. >> bw_a = padarray(BW,[1 1],1,'pre');
  8. BW = imfill(bw_a,'holes');
  9. BW = BW(2:end,2:end);
  10. figure, imshow(BW);
  11. >> imgTwoAdjacent = bwareaopen(BW,5420); %figure, imshow(imgTwoAdjacent);
  12. imgRemain1 = imsubtract(BW,imgTwoAdjacent);        %figure, imshow(imgRemain1);
  13. imgMedium = bwareaopen(imgRemain1,2275);                 %figure, imshow(imgMedium);
  14. imgSmall = imsubtract(logical(imgRemain1),imgMedium);   %figure, imshow(imgSmall);
  15. >> [imgMedium,numMedium] = bwlabel(imgMedium);
  16. figure, imshow(imgMedium);
  17. title(['#medium: ' num2str(numMedium) '']);
  18. >> [imgSmall,numSmall] = bwlabel(imgSmall);
  19. figure, imshow(imgSmall);
  20. title(['#small: ' num2str(numSmall) '']);
  21. >> [imgTwoAdjacent,numTwoAdjacent] = bwlabel(imgTwoAdjacent);
  22. figure, imshow(imgTwoAdjacent);
  23. title(['#2 Cell: ' num2str(numTwoAdjacent) '']);
Advertisement
Add Comment
Please, Sign In to add comment