I am a Mathematica novice trying to do some interactive segmentation of microscopy images. I've been trying to understand and build upon some code from a previous StackExchange discussion (Can individual locators in LocatorPane be temporarily disabled?) about creating layers of locators that don't interfere with each other that are overlayed on the same image. My goal is to use this approach to help speed up my image segmentation so I can take a colorized WatershedComponents or MorphologicalComponents label matrix and join components together by grouping and selecting each component with the same color (i.e. layer) of locator. For example, if an image had two objects of interest in it an the segmentation has oversegmented the image so that this results in 3 components for object #1 and 5 components for object #2, I would like to simply put 3 red locators on the components of object #1 and 5 blue locators on the components of object #2 and then pass these component lists to other functions that join these components.
Here's Where I'm Running Into Trouble with Building Upon the Code Below:
i.) How can I apply locPaneSimplified function to a colorized WatershedComponents matrix so the layers and points still show up?
ii.) How can I generate an arbitrary number of overlays as needed (i.e. new layers/colors of locators on demand as determined by the user viewing the segmented image) by pressing a "New Layer" button or something similar?
iii.) How can I get rid of the Manipulate and use just a Dynamic or DynamicModule instead?
Thanks for any suggestions or simple examples you can share with me! -GR
(*
The block of code below allows for adding arbitrary numbers of red and blue
locators by toggling between overlays and using LocatorAutoCreate->True.
This is simplifed from kguler's suggestions in previous StackExhange code discussion:
https://mathematica.stackexchange.com/questions/9148/can-individual-locators-in-
locatorpane-be-temporarily-disabled.
*)
(*locator appearance graphics*)
redCircle = Graphics[{Red, Disk[]}, ImageSize -> 10];
blueCircle = Graphics[{Blue, Disk[]}, ImageSize -> 10];
grayDisk = Graphics[{Lighter@Lighter@Gray, Disk[]},
ImageSize -> 10] (* used when locator is "grayed out" (i.e. made inactive)
when another layer is selected *);
locPaneSimple[Dynamic[pts_], shape_] :=
LocatorPane[Dynamic[pts],
Dynamic@Module[{},
Graphics[Point /@ pts, PlotRange -> m, Axes -> True,
ImageSize -> {300, 300}]],
Appearance -> shape (* "Appearance" gives the style/shape of the two Locators *),
LocatorAutoCreate -> True (* allows for creating more locators by pressing Alt+Click*)
];
Manipulate[m = 15 (* m sets PlotRange *);
Overlay[{locPaneSimple[Dynamic[pts],
Dynamic@If[layer == 1, redCircle, grayDisk]] (*
preceding [] contains arguments to locPane.
If layer==1 then you get red circles at pts if layer1!=1 you get grayDisk *)
,
locPaneSimple[Dynamic[pts2],
Dynamic@If[layer == 2, blueCircle, grayDisk]]},
All, Dynamic[layer]],
{{pts, {{6, 0}, {0, 9}}}, ControlType -> None},
{{pts2, {{7, 0}, {0, 7}}}, ControlType -> None},
{{layer, 1, "layer"}, {1, 2}} (* creates "layer" buttons to toggle between red and
blue locator layers that have beenoverlayed on same plot *)
](* Close Manipulate *)