Determine the largest length along the width of the part

1 回表示 (過去 30 日間)
tarun
tarun 2013 年 5 月 5 日
I have a binary image
what I want to do is
1. Calculate the sum of black pixels along each and every individual row
2. Then compare the individual sums to get the largest value(which would be my answer).
or in other words
Determine the largest length along the width of the part.
I have another question
>>>>I want to count the number of black pixels in each individual row and then compare that result to get 'which row has highest number of black pixels'.
  1 件のコメント
Image Analyst
Image Analyst 2013 年 5 月 5 日
編集済み: Image Analyst 2013 年 5 月 5 日
Your final question was answered by the second comment I gave to my original answer. I give you both the count, AND the row at which that highest count happens at. Isn't that what you want?

サインインしてコメントする。

採用された回答

Image Analyst
Image Analyst 2013 年 5 月 5 日
% 1. Calculate the sum of black pixels along each and every individual row
verticalProfile = sum(binaryImage, 2);
% 2. Then compare the individual sums to get the largest value
% (which would be my answer).
[maxWidth, rowAtMaxWidth] = max(verticalProfile);
  2 件のコメント
Image Analyst
Image Analyst 2013 年 5 月 5 日
Sorry - use min() instead of max() if your binary image is the opposite of the normal, which it sounds like your is. Your foreground is black rather than white, as usual. So you'd do
% 1. Calculate the sum of black pixels along each and every individual row
verticalProfile = sum(binaryImage, 2);
% 2. Then compare the individual sums to get the largest value
% (which would be my answer).
[maxWidth, rowAtMaxWidth] = min(verticalProfile);
Image Analyst
Image Analyst 2013 年 5 月 5 日
If your binary image is the opposite of the normal, which it sounds like yours is. Your foreground is black rather than white, as usual. So to count the black pixels, you'd do
% 1. Calculate the sum of black pixels along each and every individual row
verticalProfile = sum(~binaryImage, 2);
% 2. Then compare the individual sums to get the largest value
% (which would be my answer).
[numberOfBlackPixels, rowAtMaxWidth] = max(verticalProfile);

サインインしてコメントする。

その他の回答 (1 件)

Youssef  Khmou
Youssef Khmou 2013 年 5 月 5 日
hi you can try as the following :
I=imread('circuit.tif'); % esample
B=im2bw(I);
S=sum(B);
figure, plot(S),
[y,x]=max(S)
% X= 252 in this case so the row 252 is the largest

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by