1

的單獨的圖像爲從圖像中檢測文字。該代碼被從圖像檢測的文本,但現在我想從圖像每個檢測到的信創建的輸出圖像。請告訴我該怎麼做?得到我寫了這個MATLAB代碼(下面給出)每個檢測到的信

代碼:

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 
+0

這是最好的[不要使用'i'作爲在Matlab變量名(http://stackoverflow.com/q/14790740/1714410)。 – Shai

回答

1

你可能想看看regionprops'Image'屬性:

Ipops = regionprops(Ilabel, 'Image'); 

PS,
調用regionprops時,最好是明確定義要求的屬性,否則你浪費資源計算所有屬性 - 包括那些你甚至不需要的屬性。
例如,你的代碼應該看起來像

Iprops = regionprops(Ilabel, 'BoundingBox'); 
Ibox = vertcat(Iprops.BoundingBox); % no need for "reshape" here... 
相關問題