Reputation: 437
I have written this matlab code (given below) for detecting text from an image. This code is detecting the text from the image, but now I want to create an output image for each detected letter from the image. Please tell how can I do that?
Code:
i = imread('text.png');
i1 = i;
imshow(i1);
i2 = edge(i1,'canny',0.3);
imshow(i2);
se = strel('square',2);
i3 = imdilate(i2,se);
imshow(i3);
i4 = imfill(i3,'holes');
imshow(i4);
[Ilabel num] = bwlabel(i4);
disp(num);
Iprops = regionprops(Ilabel);
Ibox = [Iprops.BoundingBox];
Ibox = reshape(Ibox,[4 92]);
imshow(i);
hold on;
for cnt = 1:92
rectangle('position',Ibox(:,cnt),'edgecolor','r');
end
Upvotes: 1
Views: 73
Reputation: 114816
You might want to look at the 'Image'
property of regionprops
:
Ipops = regionprops(Ilabel, 'Image');
PS,
when calling regionprops
it is better to explicitly define the requested properties, otherwise you waste resources computing all properties - includeing those you don't even need.
For instance, your code should look like
Iprops = regionprops(Ilabel, 'BoundingBox');
Ibox = vertcat(Iprops.BoundingBox); % no need for "reshape" here...
Upvotes: 1