distance between two points in an image

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

distance between two points in an image

Post 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..
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: distance between two points in an image

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: distance between two points in an image

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: distance between two points in an image

Post 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
sin
Posts: 46
Joined: 2011-04-23T11:06:13-07:00
Authentication code: 8675308

Re: distance between two points in an image

Post 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) ? ?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: distance between two points in an image

Post 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/
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: distance between two points in an image

Post 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/
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
goldskif
Posts: 22
Joined: 2012-02-19T03:51:30-07:00
Authentication code: 8675308

Re: distance between two points in an image

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: distance between two points in an image

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply