Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I have started off with importing a png image of size $512\times 1024$ px. I have then created two locators as demonstrated on the Wolfram tutorials:

length = DynamicModule[{p1 = {0, 0}, 
   p2 = {1, 1}}, {Dynamic@
    Graphics[{Arrow[{p1, p2}], Locator[Dynamic[p1]], 
      Locator[Dynamic[p2]]}, PlotRange -> 1024], 
   Dynamic[Grid[{{"Length:", EuclideanDistance[p1, p2]}, {"Slope:", 
       1/Divide @@ (p2 - p1)}}]]}]

I would like to be able to overlay these locators on to my png image and move them around, in order to measure the distance between two points on the image. I'm sure this should be possible but I really can't see how! Thanks for looking :)

share|improve this question
up vote 6 down vote accepted

Is this what you are looking for?

pic = Image@RandomReal[1, {5, 10}]
x = {1.5, 1.5}; y = {2.5, 3.5};
max = Dimensions@ImageData@pic - .5; 

        LocatorPane[Dynamic@{x, y},
                    Colorize@Image[pic, ImageSize -> 1000], 
                   {{0.5, 0.5}, max, {1, 1}}],
        Dynamic@EuclideanDistance[x, y]

enter image description here

There is always a question about coordinates but if you only need the distance between those points it does not matter.

Edit max added in order to make it more handy.

share|improve this answer
Thank you very much! I have replaced your code '"Colorize@Image[pic, ImageSize -> 1000], {{0.5, 0.5}, {9.5, 4.5}, {1, 1}}]' with the image I need to analyse and it has worked perfectly. Thanks again :) Jade – Jade Jul 29 '13 at 16:20
@Jade {{0.5, 0.5}, {9.5, 4.5}, {1, 1}} those are domain intervals, take a look at LocatorPane in documentation. It is not crucial but without those .5 endings Locators are constraind to the mesh not to the center of pixels. – Kuba Jul 29 '13 at 16:30
Ahh okay that makes sense - explains why I couldn't get the image to be displayed at its normal size even when using 'ImageSize'. All working fine now though - at least for what I'm doing :) Thanks again. – Jade Jul 31 '13 at 12:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.