【问题标题】:How can I remove white lines which is larger then Threshold value in binary image ? (matlab) [closed]如何删除大于二值图像中阈值的白线? (matlab)[关闭]
【发布时间】:2015-10-11 10:27:39
【问题描述】:

我有一个二进制图像,我想删除大于阈值(如 50 像素)的白线。

原图:

输入输出图像:

我的想法:

我想计算位于每行中的白色像素,如果((白色像素数>阈值))则删除该行。

编辑完成我的代码。

  close all;clear all;clc;

  I =imread('http://www.mathworks.com/matlabcentral/answers/uploaded_files/34446/1.jpg');
  I=im2bw(I);
  figure,
  imshow(I);title('original');
  ThresholdValue=50;
  [row,col]=size(I);
  count=0;     % count number of white pixel
  indexx=[];   % determine location of white lines which larger..
  for i=1:col
      for j=1:row

          if I(i,j)==1
              count=count+1; %count number of white pixel in each line
        % I should determine line here
        %need help here
          else
              count=0;
              indexx=0;
          end
          if count>ThresholdValue
          %remove corresponding line
          %need help here
          end
      end
  end

【问题讨论】:

  • @Andy Jones 我应该删除我的问题吗?我遇到了问题,有人帮我解决了。

标签: image matlab binary noise-reduction


【解决方案1】:

只少了一小部分,你还必须检查你是否到达了行尾:

    if count>ThresholdValue
        %Check if end of line is reached
        if j==row || I(i,j+1)==0
            I(i,j-count+1:j)=0;
        end
    end

关于评论的更新代码:

I =imread(pp);
I=im2bw(I);
figure,
imshow(I);title('original');
ThresholdValue=50;
[row,col]=size(I);
count=0;     % count number of white pixel
indexx=[];   % determine location of white lines which larger..
for i=1:row %row and col was swapped in the loop
    count=0; %count must be retest at the beginning of each line 
    for j=1:col %row and col was swapped in the loop

        if I(i,j)==1
            count=count+1; %count number of white pixel in each line
            % I should determine line here
            %need help here
        else
            count=0;
            indexx=0;
        end
        if count>ThresholdValue
            %Check if end of line is reached
            if j==col || I(i,j+1)==0
                I(i,j-count+1:j)=0;
            end
        end
    end
end
imshow(I)

【讨论】:

  • 确实感谢你的帮助,你能告诉我为什么我在这个例子中出错了吗? 2end 示例图片:dropbox.com/s/n5sdx26drbsu6ay/sample.jpg?dl=0
  • @KaroAmini: count 必须在每一行之后重置,并且您交换了行和列。后者在第一种情况下没有引起问题,因为您的图像是方形的。
  • ,我很感激你为我所做的一切。我给你带来了麻烦。
猜你喜欢
  • 2012-09-27
  • 2013-12-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-11-02
  • 2014-05-09
相关资源
最近更新 更多