【问题标题】:Word Segmentation in MATLABMATLAB 中的分词
【发布时间】:2017-01-19 19:20:19
【问题描述】:

代码:

img = imread ('G:\Stuff\RP\Database\0001_4.jpg');
%imshow(img);

bin_img = imcomplement(im2bw(img, 0.8)); %Binarizing
%figure;
%imshow(bin_img);

bin_img = bwareaopen(bin_img, 50); %for removing dots and commas

%%%%%%%% Line Segmentation %%%%%%%%
dbw_img = imdilate(bin_img, strel('line', 100, 0));%Dilating
[L, N]=bwlabel(dbw_img); %finding connected components
bbox = regionprops(L, 'BoundingBox');
lineSlopeMatrix=[N 0];
for i=1:N %must run for all the lines in an image
    bBox=bbox(i).BoundingBox;
    x=bBox(1)+0.5;
    y=bBox(2)+0.5;
    w=bBox(3);
    h=bBox(4);
    linePatch=bin_img(y:y+h,:); %Extracting line
    figure,imshow(linePatch) % Prints lines

    words_img = imdilate(linePatch, strel('line', 40, 0));%Dilating
    [R, C]=bwlabel(words_img); %finding connected components i.e. Words
    bounding = regionprops(R, 'BoundingBox');
    for j=1:C %nmust run for the words in a line
        bdBox=bounding(j).BoundingBox;
        xAxis=bdBox(1)+0.5;
        yAxis=bdBox(2)+0.5;
        width=bdBox(3);
        height=bdBox(4);
        %         [row col]=size(linePatch)
        %         yAxis,yAxis+height,xAxis,xAxis+width
        Patch=linePatch(yAxis:yAxis+height,xAxis:xAxis+width); 
        %Extracting Patch of Words

        figure,imshow(Patch) %Prints words
        Patch=[];
    end
    linePatch=[];
end

问题:我首先从输入图像中分割出一行,然后从该行中提取单词。我的算法将单词从第一行正确分割出来(来自输入图像,附在这篇文章中),然后它还会从第二行分割第一个单词,而不是给我以下错误:

??? Index exceeds matrix dimensions.

Error in ==> test_words_lines at 33
    Patch=linePatch(yAxis:yAxis+height,xAxis:xAxis+width);

我很容易理解错误,检查了矩阵的尺寸,它们看起来很好,或者我在那里找不到问题..

请看附上的图片: Segmentation of Words from Line 1// Segmentation of Words from Line 2

请告诉我此错误的正确原因并提出修复建议。 谢谢:)

【问题讨论】:

  • 尝试使用调试器并在Patch=linePatch(yAxis:yAxis+height,xAxis:xAxis+width) 行停止。检查xAxis, yAxis, etc. 的值。它们是否大于您的矩阵大小linePatch?
  • height, width, yAxis 和linePatch的大小?
  • @bushmills 我添加了条件i==2 && j==2 的断点,发现xAxis 的值是280,yAxis 104,width 是45,height 是5.. 而linePatch 是 108*2465。现在,yAxis+height=104+5=109 大于 no of rows,108.. 但这没有意义.. size(linePatch)=108*2465 不是表示 108 行和 2465 列吗?和xAxis 和yAxis 值,表示像素数?在此先感谢:)
  • @bushmills 大小为 linePatch= 108 * 2465, height =5 , width=45, yAxis= 104

标签: matlab image-processing matrix text-segmentation


【解决方案1】:

有关您正在使用的函数regionprops,请参阅以下文档:

http://de.mathworks.com/help/images/ref/regionprops.html#inputarg_properties

您可以在此处阅读属性 Bounding Box 的描述,返回值(您的 xAxis 和 yAxis)以 [xyz .. .]。 所以添加 height 来获取边界框是错误的。你必须减去height。

【讨论】:

  • 我知道 region props 的作用。我之前使用过相同的方法(添加高度和 yAxis)。不过,我已经尝试过减法,它返回空白图像,过了一会儿同样的错误..
  • 请向我们展示您尝试减法的代码行。是不是像这样:Patch=linePatch(yAxis-height:yAxis,xAxis:xAxis+width); 否则会很难,除非我们能重现您的问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-08-22
  • 1970-01-01
  • 1970-01-01
  • 2014-11-13
  • 1970-01-01
  • 2010-09-29
  • 1970-01-01
相关资源
最近更新 更多