How can remove white lines in bainary images which is larger that Threshold value ?

2 ビュー (過去 30 日間)
sara
sara 2015 年 7 月 21 日
回答済み: Image Analyst 2015 年 7 月 21 日
Hi all,
I have a binary image which I want to remove white lines larger then Threshold value (like 50 pixel).
original image :
input image and output image :
My idea: I want to count white pixels which located in each rows and if (( count> threshold value )) then remove that line.
please help me to complete this code and implement my Idea.
close all;clear all;clc
I =imread('1.jpg');
I=im2bw(I);
figure,imshow(I);title('original');
[row,col]=size(I);
count=0;
indexx=[];
for i=1:col
for j=1:row
if I(i,j)==1
count=count+1;
indexx=I(i,j);
else
count==0;
indexx=0;
end
end
end
% code
end
indexx % for detect first and last white pixel
count % count the number of white pixels

回答 (1 件)

Image Analyst
Image Analyst 2015 年 7 月 21 日
Try something like this (untested)
[rows, columns] = size(binaryImage);
for row = 1 : rows
thisLine = binaryImage(row, :);
[labeledImage, numRegions] = bwlabel(thisLine);
measurements = regionprops(labeledImage, 'Area', 'PixelIdxList');
for r = 1 : numRegions
if measurements(r).Area > threshold
% This line segment is long. Erase it
columnsToDelete = measurements(r).PixelIdxList;
binaryImage(r, columnsToDelete) = false;
end
end
end

タグ

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by