I have coded up a little interactive DynamicModule to help me with image processing/segmentation of stacks of timelapse microscopy images. I am experiencing a crippling slow down in the responsiveness of the locators in the LocatorPane after I display a labeled overlay outside of the LocatorPane. Below is a screenshot of the DynamicModule as the user sees it with the LocatorPane in the center of the screen (with the red locator disk on the blue cell), smaller images that show labels and highlighted contours on the left-side and buttons that call functions on the right side:
In the above LocatorPane the red locator is reasonably responsive and can be used to mouseover and select various components for functions like joining, swapping and relabeling the components. However, when I toggle an overlay of components labels on in the upperleft panel (toggle control using the CheckBox is below the left panel image) the locators in the central LocatorPane becomes terribly sluggish (almost unusable). Here is what the screenshot looks like with the label overlay toggled on:
All I am doing is here is displaying an overlay of the labels on the centroids of the components on the same colorized watershed components image that is used for the LocatorPane (I wanted to put the overlay of the labels in a different display than the LocatorPane to keep the LocatorPane display from being too busy). It is unclear to me why overlaying the labels on an image outside of the LocatorPane should slow down the locator responsiveness within the LocatorPane. Note that when I toggle the overlay of the labels off the LocatorPane becomes responsive again. I have also tried to use ImageCompose instead of Show[Overlay[...]] and get the same results with the unresponsive LocatorPane. Here is the stripped down code showing how I am implementing the overlay, the plot labeling function and the LocatorPane:
(* Dynamic Overlay Code*)
Dynamic[
Which[
(* this Which statement is used for responding to toggling the
labels on/off *)
showLabels == False,
Column[
{
Dynamic[Image[Colorize[watershedMatrix[[currentFrame]]],
ImageSize -> 450]]
}
] (* close showLabels==False Column *)
,
showLabels == True,
Column[
{
plotLabelerFunctionOutput =
Setting[Dynamic[
PlotLabelerFunction[watershedMatrix[[currentFrame]]]]];
Dynamic[
Show[Colorize[watershedMatrix[[currentFrame]]],
plotLabelerFunctionOutput[[2]], ImageSize -> 450]
] (* close Dynamic enclosing overlay *)
}
] (* close showLabels==True Column *)
] (* close showLabels Which *)
] (* close Dynamic wrapping whole showLabels Which *)
(* labeling function code that generates the text overlay of labels at the centroid positions of the components *)
PlotLabelerFunction[matrixIn_List] :=
Block[{centroids, areas, textTable, labelsOnlyPlot, riffledList,
riffledSortedList},
centroids = ComponentMeasurements[matrixIn, "Centroid"];
textTable = ParallelTable[
Text[Style[centroids[[i, 1]], Large, Red, Bold],
N[centroids[[i, 2]]]],
{i, 1, Length[centroids]}];
labelsOnlyPlot =
Graphics[textTable, Axes -> False, AxesOrigin -> {1, 1},
PlotRange -> {{1, Dimensions[matrixIn][[1]]}, {1,
Dimensions[matrixIn][[2]]}}];
(* note that I have also tried to generate labeled plot with with ImageCompose as follows:
Return[ImageCompose[matrixIn//Colorize,labelsOnlyPlot]]
*)
Return[{textTable, labelsOnlyPlot}];
] (* close Block *)
(* LocatorPane Code *)
LocatorPane[Dynamic[pts],
Dynamic@Image[Colorize[watershedMatrix[[currentFrame]]],
ImageSize -> 800], LocatorAutoCreate -> True,
Appearance -> {Graphics[{Red, Disk[]}, ImageSize -> 10],
Graphics[{Blue, Disk[]}, ImageSize -> 10]}]
The sluggishness of the locators when the labels are toggled on really limits the usefulness of this code. Any ideas for restoring the locator's responsiveness would be most appreciated. Thanks.
watershedMatrix
- it doesn't have to be your actual data, some simple code to generate fake data will be just as good. $\endgroup$