how to scan binary image and stop if value image=0

clear all; clc;
img = imread('asmfx.jpg');
[m,n,p] = size(img);
figure; imshow(img);
[xreg yreg value] = ginput(1);
title(['Row',num2str(xreg),'Col',num2str(yreg)])
if (length(xreg) < 1)
i want to snanning image with first set point with mouse like black rectangle. how can i scan up with row. and stop if value setpoint = 0. thanks before
return%break
end
%% inisialisasi posisi awal
sisiKanan = [xreg+10 yreg];
sisiTengah = [xreg yreg];
sisiKiri = [xreg-10 yreg];
%% scan tengah
markedTengah = insertMarker(img,[xreg yreg],'star','color','r','size',5);
for scanTengahY = xreg
for scanTengahX = yreg : yreg-100
%rr=[r(scanTengahX,scanTengahY),g(scanTengahX,scanTengahY),b(scanTengahX,scanTengahY)];
if scanTengahX == sum(cumprod(a~=0))+1
break;
markedTengah = insertMarker(img,[scanTengahX scanTengahY],'star','color','r','size',5);
imshow(markedTengah);
end
end
end
%marked = insertMarker(img,[xreg yreg],'star','color','r','size',5);

 Accepted Answer

Try this
[x,y] = ginput(1);
row = round(y);
column = round(x);
thisColumn = binaryImage(:, column); % Extract this one column from the binary image.
while row >= 1 && thisColumn(row)
row = row - 1;
end
When it's done, row will equal the row of the first 0 above the clicked point (which may be the clicked pint itself if you clicked on a black place). If you want the last white pixel before we hit black, add 1 to row. If row = 0, then there were no black pixels in the column above the clicked point.

5 Comments

thank you very much sir
twice I ask here and you always give the right answer. may Allah bless you.
do you have youtube channel or online class or website so i can learn a lot from you about image processing.
thank a lot sir
Sorry, no. I do have a small portion of my demos in my File Exchange.
how to scan with many points with fixed line points but coloum points starting at 1:10. and stop with new position in every point in last white area? help me sir
how to save value for loop in matrix. thank you

Sign in to comment.

More Answers (1)

I = imread(myimage) ;
I1 = rgb2gray(I) ;
[y,x] = find(I) ; % this will gives points/ indices which have pixel value 1
imshow(I) ;
hold on
plot(x,y,'.r')
You can pick the matrix I1, and pick any column, and use find to know the positions if you want the first value when 1 starts.

3 Comments

sorry if my explanation is unclear.
I use binary image. my initial point is initializing with my mouse with input ginput (). after that I want to scan up and the scanning process will stop when the set point value = 0 because it passes through the black part of the image. can you help me how can I scan and stop when the pixel set point value = 0?
thank you
may Allah bless you. in shaa allah
When you click, you will get the indices...i,e (x,y)..you can get the respective row or column using
I(x,:)
I(:,Y)
From the row or column, you can use find, and get the indices of the pixel value you want.
is find () placed in the for loop function for scanning?

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!