【问题标题】:Row by Row character extraction逐行字符提取
【发布时间】:2014-04-08 20:34:38
【问题描述】:

我正在从输入图像中识别手写字符。这是从输入图像中提取字符的代码

  %% Label connected components
  [L Ne]=bwlabel(Ifill);
  disp(Ne);
  %% Measure properties of image regions
  propied=regionprops(L,'BoundingBox');
  hold on

  %% Plot Bounding Box
  for n=1:size(propied,1)
  rectangle('Position',propied(n).BoundingBox,'EdgeColor','g','LineWidth',2)
  end
  hold off

  %% Characters being Extracted
  figure
  for n=1:Ne
  [r,c] = find(L==n);
  n1=imagen(min(r):max(r),min(c):max(c));
  imshow(~n1);
  end

但此代码是从输入图像中随机提取字符。谁能告诉我如何逐行提取字符?

Original code

【问题讨论】:

  • 这不是随机的 - bwlabel 基本上是从最左边到最右边对对象进行编号。您需要根据它们的位置将它们分类为“行”。无论是简单的 y 值合并还是更复杂的聚类,都取决于图像。

标签: matlab image-processing image-segmentation


【解决方案1】:

假设:字符行之间有足够的间隔,使得两行字符之间至少有一个完全空白的图像行。

代码

%%// 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

如何使用输出,L1:你可以用L1==1得到第一个字符,用L1==2得到第二个,依此类推,如测试代码末尾的部分。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-11-08
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多