Finding 3 consecutive zero values row by row in an image.
4 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I would like to be able to go through every row in an image looking for when there are 3 consecutive pixels with a zero value. What I need is it to print the row(X) and column(Y) for the pixel before those 3 pixels. And then continue to move through the rest of the rows. So in the end I would have a list for the Xs and Ys. Can anyone help me make this loop?
Thanks
6 件のコメント
Image Analyst
2012 年 4 月 9 日
Care to post the image (so we can see it), and let us know why you want/need to find locations of exactly 3 (no more and no less) black pixels? What are you going to do once you know the location of the pixels before the black line starts?
回答 (2 件)
Andrei Bobrov
2012 年 4 月 10 日
x1 = all(img==0,3);
rst = conv2(x1+0,[1 1 1],'same');
[ii,jj] = find(rst == 3);
jj = bsxfun(@plus,jj,-1:1);
Geoff
2012 年 4 月 9 日
Simplest (and rather inefficient) approach:
for y = 1:size(img,1)
blacks = 0;
for x = 1:size(img,2)
if all(squeeze(img(y,x,:)) == 0)
blacks = blacks + 1;
if blacks == 3
% BTW, what do you do if first three pixels in the row are black??
disp( [x-blacks, y] );
break; % Stop processing row
end
else
blacks = 0;
end
end
end
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Graphics Performance についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!