I just scanned a sample image and I’m trying to detect the first pixel which has a value of “0” in the binary-image.
I used paint to write a text and when i used the following prog, it always catches the bottom most pixel.
clear all;
x=imread('textjay.png');
y=im2bw(x);
height=size(y,1); % row
width=size(y,2); % col
valueoftheindex=0;
pixel_value=0;
for i=1:width
for j=1:height
pixel_value=y(j,i);
if (pixel_value==0)
valueofthewidth=i;
valueofthehieght=j;
break
end
end
end
valueofthewidth
valueofthehieght
imtool(y)
This depends a lot on what you consider to be “the first pixel”.
Assuming that you can live with the pixel order that MATLAB assigns you could use
For other measures of “firstness” you would have to either transpose the input matrix (the image), or resort to some more refined way of calculation.
And yes, the
breakwill only break the inner loop, as dawe already pointed out.