开发者

Line Matrix code in Matlab

开发者 https://www.devze.com 2023-02-09 20:17 出处:网络
function [fl re]=lines(im_text) %# Divide text in lines im_text=clip(im_text); num_filas=size(im_text,1);
function [fl re]=lines(im_text)  
%# Divide text in lines  
im_text=clip(im_text);  
num_filas=size(im_text,1);  
for s=1:num_filas  
    if sum(im_text(s,:))==0  
        nm=im_text(1:s-1, :); %# First line matr开发者_StackOverflowix  
        rm=im_text(s:end, :);%# Remain line matrix  
        fl = clip(nm);  
        re=clip(rm);  
        %#result  
        break  
    else  
        fl=im_text;%#Only one line.  
        re=[ ];  
    end  
end  
function img_out=clip(img_in)  
[f c]=find(img_in);  
img_out=img_in(min(f):max(f),min(c):max(c));%#Crops image  

Can anyone please provide with an explanantion of this code and how i can summarise it and simplify it without changing the function its performs? How i can implement same algorithm without making it a function on its own. adding this to another code. thanks


The function takes a binary image, then looks for a row in the image with no object (i.e. only black pixels), and splits the image along this line. In addition, it crops off all the empty (i.e. black) area around the objects in the subfunction clip.

You can simplify it to

cutRowIdx = find(all(~im_text,2),1,'first');
topPart = clip(im_text(1:cutRowIdx-1,:)); 
bottomPart = clip(im_text(cutRowIdx:end,:));

Put clip as a subfunction into your function, or make it into a standalone function and put it into your path.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号