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));
for k = 1:length(row)
try
row(k) = find(white(:,k),1,'first');
end
end
imshow(I)
hold on
plot(1:k,row,'b-')
Best Answer