0
$\begingroup$

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

$\endgroup$
3
  • 1
    $\begingroup$ Could you please formulate in more detail what you need and what issues your are experiencing ? $\endgroup$ Commented Jan 8, 2013 at 2:14
  • $\begingroup$ Take a look at CoordinatesToolOptions. It might be helpful. What does ROI mean? $\endgroup$ Commented Jan 8, 2013 at 21:36
  • $\begingroup$ @Szabolcs ROI is the Region of Interest. I have edited the question to reflect this. Thank you. $\endgroup$ Commented Jan 8, 2013 at 22:01

2 Answers 2

1
$\begingroup$

I am hung up on a way to pass the indices cleanly out of a Module/DynamicModule structure.

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]}; Manipulate[ If[file =!= "", pts = imgConvert /@ pts0; Show[ 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

Dynamic@pts (* {{139, 38}, {66, 82}} *) 

I hope that can get you started.

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

$\endgroup$
1
  • $\begingroup$ Thanks. This is what I was looking for! I will post back here when I get something working. Thanks again. $\endgroup$ Commented Jan 10, 2013 at 18:27
2
$\begingroup$

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

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

Mathematica graphics

$\endgroup$
5
  • $\begingroup$ Why not simply use a LocatorPane instead? $\endgroup$ Commented Jan 8, 2013 at 8:03
  • $\begingroup$ @nikie I was trying to detect the "right click" and went this way $\endgroup$ Commented Jan 8, 2013 at 13:30
  • $\begingroup$ 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. $\endgroup$ Commented Jan 8, 2013 at 20:33
  • $\begingroup$ @EdM Please add that info to your question $\endgroup$ Commented Jan 8, 2013 at 20:41
  • $\begingroup$ @belisarius Info added. Thank you. $\endgroup$ Commented Jan 8, 2013 at 22:02

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.