Row by Row character extraction

后端 未结 1 1049
逝去的感伤
逝去的感伤 2021-01-23 01:53

I am working on handwritten character recognition from input image. Here is the code which extracts characters from input image

  %% Label connected components
          


        
1条回答
  •  天涯浪人
    2021-01-23 02:36

    Assumption: There is enough separation between rows of characters, such that there is at least one image row that is completely blank between two rows of characters.

    Code

    %%// Input binary image
    BW = Ifill;
    
    %%// Label connected blobs
    [L,NUM] = bwlabel(BW);
    
    %%// Find centroid points for each blob
    cc = bwconncomp(BW);
    stats = regionprops(cc, 'Centroid');
    cent_rowcol = vertcat(stats.Centroid);
    
    %%// Find transitions of characters starts and ends along the rows
    trans1 = [0 ;diff(sum(BW,2)>0)]; 
    
    %%// Find row midpoints for each row
    row_midpts = (find(trans1==1) + find(trans1==-1))/2;
    
    %%// Find the new labels based on row by row sorting
    [~,row_id] = min(abs(bsxfun(@minus,cent_rowcol(:,2),row_midpts')),[],2); %%//'
    [~,sortedInd] = sort((row_id-1)*size(BW,1)+cent_rowcol(:,1));
    
    %%// Assign the new labels
    L1 = zeros(size(L));
    for k=1:numel(sortedInd)
        L1(L==sortedInd(k))=k;
    end
    
    %%// Testing: Show all the characters one by one row by row
    figure,
    for k=1:numel(sortedInd)
        imshow(L1==k);
        pause(0.2);
    end
    

    How to use the output, L1: You can get the first character with L1==1, second with L1==2 and so on, as shown in the Testing section at the end of code.

    0 讨论(0)
提交回复
热议问题