Page 1 of 1

distance between two points in an image

Posted: 2011-05-04T21:32:58-07:00
by sin
hi,
i am using imagemagick.i have doubt on how to find the distance between any two point in an image. for example, if we take the picture of a tree how can i find the distance between its root and any leaves,distance from one branch to another(all these are clearly visible in the image) like that distance between any two points. if finding out distance is not possible getting the coordinates of any point in the image would also be of great help. so please help in finding out this. if im able to crack this my project will have some base. so please reply me..

Re: distance between two points in an image

Posted: 2011-05-04T21:41:34-07:00
by fmw42
What version of IM and more important what platform. In Linux/Mac, the X11 display allows one to locate the coordinates of any point in the image.

display image

then hold the option key (Mac) down and hold down the left mouse button and drag it around. Get your two coordinates. Then use fx calculations

x1=10
y1=100
x2=200
y2=20
dist=`convert xc: -format "%[fx:hypot(($x2-$x1),($y2-$y1))]" info:`

see http://www.imagemagick.org/script/fx.php

Re: distance between two points in an image

Posted: 2011-05-04T22:11:52-07:00
by anthony
Distance is actually trival (unless you are actually after a minimum distance with a confining object)
Just use Pythagoras Theorem to get a 'Euclidean Distance'. Fred given one way of calculating that above.

What you seem to really want is a way to get the coordinates of the points.

You say an image of a tree. what type of tree! a photo of a real tree, or a line drawing? If a line drawing then how would you determine what is the 'root'? did you draw the image, in which case you have coordinates already.

The easiest (non-automated) way is of course, just load the image in some display program. point to the parts and note the coordinates, just as Fred pointed out in his response.

Automatic methods will be more image specific. So an example is going to be required if we are to help you further.

Re: distance between two points in an image

Posted: 2011-05-05T05:43:22-07:00
by sin
fmw42 wrote:What version of IM and more important what platform. In Linux/Mac, the X11 display allows one to locate the coordinates of any point in the image.

display image

then hold the option key (Mac) down and hold down the left mouse button and drag it around. Get your two coordinates. Then use fx calculations

x1=10
y1=100
x2=200
y2=20
dist=`convert xc: -format "%[fx:hypot(($x2-$x1),($y2-$y1))]" info:`

see http://www.imagemagick.org/script/fx.php


im using Windows 7 and latest version of IM.so please tell for that

Re: distance between two points in an image

Posted: 2011-05-05T05:49:32-07:00
by sin
anthony wrote:Distance is actually trival (unless you are actually after a minimum distance with a confining object)
Just use Pythagoras Theorem to get a 'Euclidean Distance'. Fred given one way of calculating that above.

What you seem to really want is a way to get the coordinates of the points.

You say an image of a tree. what type of tree! a photo of a real tree, or a line drawing? If a line drawing then how would you determine what is the 'root'? did you draw the image, in which case you have coordinates already.

The easiest (non-automated) way is of course, just load the image in some display program. point to the parts and note the coordinates, just as Fred pointed out in his response.

Automatic methods will be more image specific. So an example is going to be required if we are to help you further.



It is a photograph of a tree. if we consider a real time example like photograph of a table(a four legged table - not drawn) then how can we get it measurements(may not be the same as real time but general coordinates of its edges,distance between any two edges etc). i am using Windows7 so will it b possible to get that or else should i have to go for any other scripting language(please suggest) ? ?

Re: distance between two points in an image

Posted: 2011-05-05T09:53:30-07:00
by fmw42
im using Windows 7 and latest version of IM.so please tell for that
Sorry I am not a Windows user. The fx command is windows compatible. The variables are different in Windows. See http://www.imagemagick.org/Usage/windows/

Re: distance between two points in an image

Posted: 2011-05-05T19:42:07-07:00
by anthony
getting information from a real photo (not in a controlled situation) is VERY hard without a user specifying the location of the desired coordinates.

I also am not a windows user, but most things in IM can be converted to windows, as per the 'Windows' section of IM examples
http://www.imagemagick.org/Usage/windows/

Re: distance between two points in an image

Posted: 2012-03-27T09:37:52-07:00
by goldskif
And how can the coordinates to pass to your script do not manually? (Linux)
open the file - "display image.png"
note the coordinates
get the coordinates in the script

Re: distance between two points in an image

Posted: 2012-03-28T19:28:13-07:00
by anthony
Automatic determination of coordinates is known as 'Image registration'. Their are lots of research papers on this, in particu;ar in locating the position of facial features.

Typically methods involve using things like Morphology, and Hough transforms (finding lines and circles).

For example -- finding junctions of three (thin) lines...
http://www.imagemagick.org/Usage/morpho ... ejunctions

The Image is then read to find the 'peaks' in image.
For example: output the resulting grayscale image as a TXT: (enumerated text file), and finding the pixel with the highest intensity.

Sub-image Image comparing also finds 'peaks' in images.