Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %// Read in image and convert to a binary one
- im = imread('Line.jpg');
- bw = im2bw(im);
- %// There seems to be a thin white boundary across the image, make it false(black)
- bw1 = false(size(bw));
- bw1(5:end-5,5:end-5) = bw(5:end-5,5:end-5);
- bw1(biggest_blob(bw1)) = 0; %// remove biggest blob (bottom left corner one)
- SE = strel('disk', 11, 8); %// structuring element for dilation
- bw2 = imdilate(bw1,SE); %// dilate the image
- bw3 = bwmorph(bw2,'thin',Inf); %// thin it
- out = biggest_blob(bw3); %// out of many thinned lines, select the biggest one
- function out = biggest_blob(BW)
- %// Find and labels blobs in the binary image BW
- [L, num] = bwlabel(BW, 8);
- %// Count of pixels in each blob, basically this should give the area of each blob
- counts = sum(bsxfun(@eq,L(:),1:num));
- %// Get the label(ind) cooresponding to blob with the maximum area
- %// which would be the biggest blob
- [~,ind] = max(counts);
- %// Get only the logical mask of the biggest blob by comparing all labels
- %// to the label(ind) of the biggest blob
- out = (L==ind);
- return;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement