Guest User

Untitled

a guest
Jul 16th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. A=imread( '1.jpg'); % Original Image
  2. A1=rgb2gray(A); % Convert to grayscale
  3. ABi=imbinarize(A1); % Convert the grayscale image to binary
  4. AF=imfill(ABi,'holes'); % Fill the holes of the binary image
  5. figure(1);
  6. imshow(AF)
  7. AC=imcomplement(ABi); % Invert the filled image
  8. C=intersect(AF,AC); % Intersection of the filled image and the inverted image
  9. intersection = (double(AF) - double(AC)) == 0;
  10. figure(2)
  11. imshow(intersection);
  12. CC = bwconncomp(intersection); % Connected components of the intersect image
  13.  
  14. stat=regionprops(CC, 'Area','Centroid'); % Calculate properties of the intersect image
  15. area = cat(1, stat.Area);
  16. area_sorted=sort(area,'descend'); % sort areas of the connected components in descending order
  17. centroids = cat(1, stat.Centroid);
  18. centroids_sorted=sort(centroids,'descend');% sort centroids of the connected components in descending order
  19. desired_points= centroids_sorted(1:3,:);
Add Comment
Please, Sign In to add comment