Take the 2-minute tour ×

Is there a way to do this? What I am trying to do is allow a user to take a lineout averaged over the rows of a user defined ROI (Region of Interest) of an image. I have the bit of code that allows for the lineout but at present the only way I can get the indices of the ROI is to use the right click Get Indices function and then copy and pasting them into the function. I would like to eliminate the need for the copy and paste. I would like the user to click on the image in two locations with locators (or some sort of marker) appearing on the click, then have the lineout be plotted as an output.

I need to have the image be full size (1000 x 2000) so that the user can see detail. I will also need to write the indices and the lineout to user defined variables so that multiple lineouts can be plotted together as the user needs them and the image reproduced with the markers overlay-ed on top. I have the code to do the lineouts and the plotting but I am hung up on a way to pass the indices cleanly out of a Module/DynamicModule structure.

Would it be cleaner to do this all in 1 Manipulate structure? There will be 50 or so images each with there own lineout that my be compared to one another or all at once. Thanks

share|improve this question
Could you please formulate in more detail what you need and what issues your are experiencing ? –  Vitaliy Kaurov Jan 8 '13 at 2:14
Take a look at CoordinatesToolOptions. It might be helpful. What does ROI mean? –  Szabolcs Jan 8 '13 at 21:36
@VitaliyKaurov edited and thank you. –  EdM Jan 8 '13 at 22:00
@Szabolcs ROI is the Region of Interest. I have edited the question to reflect this. Thank you. –  EdM Jan 8 '13 at 22:01
add comment

2 Answers

up vote 1 down vote accepted


Did you try setting a global variable? Below when the mouse is clicked, the global variable pts is set (in the seventh line down). It doesn't do the other things you want, but I'm not sure what a "lineout" is, or how you want to process the 50 images.

$file = "http://cdn.sstatic.net/mathematica/img/apple-touch-icon.png";
pic = Import[$file, "Data"]/255.;
imgConvert[p_] := {Mod[Max[1, Ceiling[p[[1]]]], Dimensions[pic][[2]], 1],
   Mod[Dimensions[pic][[1]] + 1 - Max[1, Ceiling[p[[2]]]], Dimensions[pic][[1]], 1]};
  If[file =!= "",
    pts = imgConvert /@ pts0;
      Image[pic, ColorSpace -> "RGB"],
      Graphics[{Opacity[0], EdgeForm[{Dashing[Small], Thin}], Rectangle @@ pts0}],
      ImagePadding -> 0, ImageSize -> Dimensions[pic][[{2, 1}]]
    "Select file"
  {{file, $file}, 
    Row[{FileNameSetter[Dynamic[file, (file = #; pic = Import[file, "Data"]/255.) &]],
      InputField[Dynamic[file, (file = #; pic = Import[file, "Data"]/255.) &], String]}] &},
  {{pts0, {{1, 1}, {1, 1}}}, Locator}

Manipulate output

The points are stored in pts, which you can monitor them with

  (* {{139, 38}, {66, 82}} *)

I hope that can get you started.

[Modified from something I wrote to pick colors out of an image.]

share|improve this answer
Thanks. This is what I was looking for! I will post back here when I get something working. Thanks again. –  EdM Jan 10 '13 at 18:27
add comment

Almost from the help (but it responds to both buttons):

DynamicModule[{p = {0, 0}, c = Green},
     Graphics[{c, Disk[p, 0.2]}, 
      PlotRange -> 2]], {"MouseDown" :> (p = MousePosition["Graphics"])}]}]

Mathematica graphics

share|improve this answer
Why not simply use a LocatorPane instead? –  nikie Jan 8 '13 at 8:03
@nikie I was trying to detect the "right click" and went this way –  belisarius Jan 8 '13 at 13:30
Thank you for the response! I looked at this but I had two problems:1. The image is an imported jpg or tif and needs to be full size so that detail can be seen. When done in this manner (inside the {}) it appears too small. 2. I need to be able to write the indices to a global variable for use later. I can't figure out how to pass information outside of the Module structure. Thanks again. –  EdM Jan 8 '13 at 20:33
@EdM Please add that info to your question –  belisarius Jan 8 '13 at 20:41
@belisarius Info added. Thank you. –  EdM Jan 8 '13 at 22:02
add comment

Your Answer


