1 view (last 30 days)

Show older comments

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'.

Image Analyst
on 5 May 2013

Image Analyst
on 5 May 2013

% 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);

Image Analyst
on 5 May 2013

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);

Youssef Khmou
on 5 May 2013

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

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

Start Hunting!