From: abhi on
I want to find out distance between points x1,x2,y1,y2... I want to find out length between those points plz help...


grayImage = imread('moon.tif');
thresholdLevel = graythresh(grayImage);
binaryImage = grayImage > thresholdLevel * 255;
horizontalProfile =max(binaryImage, [], 1);
x1 = find(horizontalProfile, 1, 'first');
x2 = find(horizontalProfile, 1, 'last');
verticalProfile =max(binaryImage, [], 2);
y1 = find(verticalProfile, 1, 'first');
y2 = find(verticalProfile, 1, 'last');
a=distance(x1,y1);
b=distance(y1,x2);
c=distance(x2,y2);
d=distance(x1,y2);
From: blup_00 on
If you need distance between 2 points (x1,y1) and (x2,y2) use this d=sqrt((x2-x1)^2+(y2-y1)^2)
But if you want distance between x1 and y1 use pitagoras theorem ( d(x1,y1)=sqrt(x1^2+y1^2) )
From: ImageAnalyst on
Depends on what you mean. With images, "distance" is not necessarily
the same as "length." Can you tell me this...In the array below, what
do you consider to be the "length" of the line of four 1's in the
image array?

0 0 0 0 0 0
0 1 1 1 1 0
0 0 0 0 0 0

Is the length of the line 4 pixels, or is it 3 pixels? Think about
it.
Now, what is the "distance" between the left endpoint of the line and
the right endpoint of the line?
See..... not so clear is it?

If you're counting whole pixels, the length is 4, but if you go from
pixel center to pixel center, the length is 3. Neither is right or
wrong, it's just a matter of how you define it. The Pythagorean
theorem may come in useful for you, as may the hypot() function.

From: Walter Roberson on
ImageAnalyst wrote:
> Can you tell me this...In the array below, what
> do you consider to be the "length" of the line of four 1's in the
> image array?
>
> 0 0 0 0 0 0
> 0 1 1 1 1 0
> 0 0 0 0 0 0

> If you're counting whole pixels, the length is 4, but if you go from
> pixel center to pixel center, the length is 3. Neither is right or
> wrong, it's just a matter of how you define it.

If you are counting whole pixels, you could count from the left boundary to
the right boundary, or from the right boundary to the left boundary. That is
right twice, whereas counting from pixel center to pixel center is never
counting right. ;-)
From: ImageAnalyst on
And of course you should remember that two wrongs don't make a right,
but three lefts do.