如何删除二进制图像中大于阈值的白线? (matlab)
How can I remove white lines which is larger then Threshold value in binary image ? (matlab)
我有一个二值图像,我想删除大于阈值(如 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
只漏了一小部分,你还必须检查是否到达行尾:
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)
我有一个二值图像,我想删除大于阈值(如 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
只漏了一小部分,你还必须检查是否到达行尾:
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)