Labeling object in a binary image MATLAB -
i trying label white objects in binary image using matlab. basically, aim detect water bodies in aerial map image , convert cimage binary , label bodies. here image example of output after detecting bodies , converting binary. how can possibly create create rectangle around white objects , label them text(using connected components)? thank you!
try -
%%// read in image file img = im2bw(imread(file)); %%// bounding box stats stats = regionprops(bwlabel(img),'area','centroid','perimeter','boundingbox'); boxes=cat(1,stats.boundingbox); %%// placeholder store final result maskm = false(size(img,1),size(img,2)); k1 = 1:size(boxes,1) %%// initialize mask representing each bounding box mask1 = false(size(img,1),size(img,2)); %%// coordinates of boxes starty = round(boxes(k1,1)); stopy = starty+round(boxes(k1,3))-1; startx = round(boxes(k1,2)); stopx = startx+round(boxes(k1,4))-1; %%// finaly create mask mask1(startx:stopx,starty:stopy) = true; maskm = maskm + imdilate(edge(mask1,'sobel'),strel('disk',2)); end %%// boxes around original blobs maskm = maskm + img; figure,imshow(maskm);
output
look text on how label boxes.
Comments
Post a Comment