How to mark the (last row,this column) of finding the highest white pixels through each column.

the code for find the white pixels through each column,and mark into the point.
true
BWImage=imread('BWImage.png');
>> row=find(sum(BWImage,2)==0,1,'last')+1;
col=find(BWImage(row,:)~=0);
row=row*ones(size(col));
Points=[row(:) col(:)];
imshow(BWImage)
hold on
plot(Points(:,2),Points(:,1),'rs','MarkerSize',10)
how to mark both point of the row found and lastRow,this Column?(both red and green mark)

2 Comments

Where are the green marks? If they're not at the very last row, then where are they?
i want to find the distance from the mark(red) to the lastRow,thatColumn. Means i need to find the point on the lastRow of that point.

Sign in to comment.

Answers (1)

First get the size of your binary image:
[rows, columns] = size(binaryImage);
The last row is the value in "rows".

8 Comments

row=1:rows; col=1:columns;
my image is 320columns,240rowss. after that?here is the output of the firstpoint.BUt i want to mark also at the lastrow based on the firstpoint(greenmark)
if true
%point location1
[rows, column] = size(img8);
row=find(sum(img8,2)==0,1,'last')+1;
col=find(img8(row,:)~=0);
row=row(ones(size(col)));
Points=[row(:) col(:)];
imshow(img8);
title('Highest Point Location')
hold on
plot(Points(:,2),Points(:,1),'rp','MarkerSize',10)
a=text(Points(1,2),Points(1,1),['This is (',num2str(Points(1,2)),',',num2str(Points(1,1)),')']);
set(a, 'FontName', 'Arial' ,'FontWeight', 'bold', 'FontSize', 12,'Color', 'green');
%point location2
[lastrows, columns] = size(img8);
lastrow=find(sum(img8,2)==0,1,'last')+1;
col=find(img8(lastrow,:)~=0);
lastrow=row(ones(size(col)));
Points=[lastrow(:) col(:)];
imshow(img8);
title('Highest Point Location')
hold on
plot(Points(:,2),Points(:,1),'rp','MarkerSize',10)
b=text(Points(1,2),Points(1,1),['This is (',num2str(Points(1,2)),',',num2str(Points(1,1)),')']);
set(b, 'FontName', 'Arial' ,'FontWeight', 'bold', 'FontSize', 12,'Color', 'green');
im trying with this,but i got it wrong. im prosessing the image in realtime.im trying to do (above image)in offline.
The last point is x=Points(1,2) and y = rows, like I said before. Do you have some doubt that the last row is at the bottom of the image and that it will have a value of "rows" which is the number of rows in that image that you got from the size() function? If so, why do you doubt it?
if true
%point location2
[rows, columns] = size(img8);
row=find(sum(img8,2)==0,1,'last')+1;
col=find(img8(row,:)~=0);
row=row(ones(size(col)));
Points2=[lastrow(:) col(:)];
imshow(img8);
title('Highest Point Location')
hold on
plot(Points2(:,2),Points2(:,1),'rp','MarkerSize',10)
b=text(Points2(1,2),Points2(1,1),['This is (',num2str(Points2(1,2)),',',num2str(Points2(1,1)),')']);
set(b, 'FontName', 'Arial' ,'FontWeight', 'bold', 'FontSize', 12,'Color', 'yellow');
it still wrong with this...
I still don't understand why you don't see that the last white row is at the bottom of the image. I mean, where else do you think it would be - in the middle of the image?
means that distance=((lastRow,thisColumn)-(points(:,2),point(:,1))?
if true
true
%highest 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);
title('Highest Point Location')
hold on
plot(Points(:,2),Points(:,1),'rp','MarkerSize',10)
a=text(Points(1,2),Points(1,1),['This is (',num2str(Points(1,2)),',',num2str(Points(1,1)),')']);
set(a, 'FontName', 'Arial' ,'FontWeight', 'bold', 'FontSize', 12,'Color', 'green');
%highest distance
% Compute the ordinary Euclidean distance.
xd=240-Points(:,2);
yd=Points(:,1)-Points(:,1);
distance=sqrt(xd.*xd + yd.*yd);
Dmeter=distance.*3;%one row=3meter
D=text(['Distance is(',num2str(Dmeter),')']); %show result of distance
set(D, 'FontName', 'Arial' ,'FontWeight', 'bold', 'FontSize', 12, 'Color', 'yellow');
i got stack to show the result of the distance.

Sign in to comment.

Asked:

on 3 May 2015

Commented:

on 4 May 2015

Community Treasure Hunt

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

Start Hunting!