2015-07-21 151 views
-1

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

原始图像:

enter image description here

输入和输出的图像:

enter image description here

我的想法:

我要算位于每一个行,如果白色像素((白色像素数>阈值))然后删除该行。

编辑完成我的代码。

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 
+0

@Andy Jones我应该删除我的问题?我有一个problrm,有人帮我解决它。 –

回答

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) 
+0

非常感谢您的帮助,您能否告诉我为什么我在这个例子中出错? 2end示例图像:https://www.dropbox.com/s/n5sdx26drbsu6ay/sample.jpg?dl=0 –

+1

@KaroAmini:'count'必须在每行之后重置,并且您交换了行和列。后者在第一种情况下不会造成问题,因为您的图像是平方的。 – Daniel

+0

,我非常感谢你为我所做的一切,让你陷入困境。 –