4
$\begingroup$

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 :)

$\endgroup$

1 Answer 1

6
$\begingroup$

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; 

Column[{
        LocatorPane[Dynamic@{x, y},
                    Colorize@Image[pic, ImageSize -> 1000], 
                   {{0.5, 0.5}, max, {1, 1}}],
        Dynamic@x,
        Dynamic@y,
        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.

$\endgroup$
3
  • $\begingroup$ 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 $\endgroup$
    – Jade
    Jul 29, 2013 at 16:20
  • $\begingroup$ @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. $\endgroup$
    – Kuba
    Jul 29, 2013 at 16:30
  • $\begingroup$ 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. $\endgroup$
    – Jade
    Jul 31, 2013 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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