MATLAB: Edit-rectangle box for each word

imageprocessing

I have an image
in that i want to draw rectangle box for each word ,please help

Best Answer

i0 = imread('image1.bmp');
i1 = im2bw(i0,graythresh(i0));
i2 = imfill(i1,'holes');
s = regionprops(i2,'Area','BoundingBox' );
[~,idx] = max([s.Area]);
i3 = imcrop(i1,s(idx).BoundingBox);
i4 = imcrop(i2,s(idx).BoundingBox);
i3(~i4) = true;
i4 = ~i3;
s1 = regionprops(i4,'BoundingBox');
c = cat(1,s1.BoundingBox);
imshow(i3);
hold on
for jj = 1:size(c,1)
x = [1;1]*(c(jj,1:2:end)+ [0 c(jj,1)]);
y = (c(jj,2:2:end)+ [0 c(jj,2)]).'*[1 1];
plot([x(:);x(1)],y([1,2,4,3,1]),'r-');
end
Related Question