pipa
pipa

Reputation: 11

Line Matrix code in Matlab

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 matrix  
        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

Upvotes: 0

Views: 688

Answers (1)

Jonas
Jonas

Reputation: 74940

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.

Upvotes: 1

Related Questions