how to mark the highest white pixel through bottom to the top? using grayscale image.

%point location
row=find(sum(img8,2)==0,1,'last')+1;
col=find(img8(row,:)~=0);
row=row(ones(size(col)));
Points=[row(:) col(:)];
imshow(img8);
hold on
plot(Points(:,2),Points(:,1)','rp','MarkerSize',12)
a=text(Points(1,2),Points(1,1),['This is (col,row)(',num2str(Points(1,2)),',',num2str(Points(1,1)),')']);
set(a, 'FontName', 'Arial' ,'FontWeight', 'bold', 'FontSize', 12,'Color', 'blue');
hold off

댓글 수: 2

What do you mean by highest? The lowest row value? Or the brightest gray level?
means that from the bottom image,I want to find the highest white pixel. or my misunderstanding about the grayscale image do not have fixed white value of pixel?

댓글을 달려면 로그인하십시오.

 채택된 답변

The white pixels are the ones where all three color components R, G, and B equal 255, so you can get a 2D logical matrix of either white or non-white pixels like this:
I = imread('test.png');
white = sum(I,3)==3*255;
The highest white pixel in the image corresponds to the first white pixel in each column, so you can loop through columns going from left to right to find the first white pixel in each column:
row = nan(1,size(white,2)); % preallocates the rows.
for k = 1:length(row)
try
row(k) = find(white(:,k),1,'first');
end
end
imshow(I)
hold on
plot(1:k,row,'b-')

추가 답변 (1개)

Stephen23
Stephen23 2015년 11월 1일
편집: Stephen23 2015년 11월 2일
Very simply without any loops, using vectorized code:
X = imread('grayscaleImage.png');
[R,C] = find(all(X==255,3));
[Y,Z] = unique(C,'first');
imshow(X);
hold on
plot(C(Z),R(Z),'-rx')
produces this:

질문:

2015년 11월 1일

댓글:

2015년 11월 3일

Community Treasure Hunt

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

Start Hunting!

Translated by