Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. %// Read in image and convert to a binary one
  2. im = imread('Line.jpg');
  3. bw = im2bw(im);
  4.  
  5. %// There seems to be a thin white boundary across the image, make it false(black)
  6. bw1 = false(size(bw));
  7. bw1(5:end-5,5:end-5) = bw(5:end-5,5:end-5);
  8.  
  9. bw1(biggest_blob(bw1)) = 0; %// remove biggest blob (bottom left corner one)
  10.  
  11. SE = strel('disk', 11, 8); %// structuring element for dilation
  12. bw2 = imdilate(bw1,SE); %// dilate the image
  13. bw3 = bwmorph(bw2,'thin',Inf); %// thin it
  14. out = biggest_blob(bw3); %// out of many thinned lines, select the biggest one
  15.  
  16. function out = biggest_blob(BW)
  17.  
  18. %// Find and labels blobs in the binary image BW
  19. [L, num] = bwlabel(BW, 8);
  20.  
  21. %// Count of pixels in each blob, basically this should give the area of each blob
  22. counts = sum(bsxfun(@eq,L(:),1:num));
  23.  
  24. %// Get the label(ind) cooresponding to blob with the maximum area
  25. %// which would be the biggest blob
  26. [~,ind] = max(counts);
  27.  
  28. %// Get only the logical mask of the biggest blob by comparing all labels
  29. %// to the label(ind) of the biggest blob
  30. out = (L==ind);
  31.  
  32. return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement