1
$\begingroup$

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:

enter image description here

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:

enter image description here

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.

$\endgroup$
3
  • 1
    $\begingroup$ Please focus on just one question, and try to strip your code down to a minimal example which demonstrates the problem and include the code. $\endgroup$ Aug 25, 2014 at 17:50
  • $\begingroup$ @ Simon Woods I have scaled back my post to just focus on the sluggish LocatorPane performance when the labeled overlay is toggled on outside of the LocatorPane. Please let me know if you have any suggestions for improving this. $\endgroup$
    – user13999
    Aug 25, 2014 at 21:23
  • $\begingroup$ To be really helpful the code should be complete, ie someone should be able to copy and paste it into a Mathematica notebook and run it. This means including definitions for things like watershedMatrix - it doesn't have to be your actual data, some simple code to generate fake data will be just as good. $\endgroup$ Aug 26, 2014 at 16:11

1 Answer 1

2
$\begingroup$

After some further experimentation it turns out that the sluggishness of the locators in the LocatorPane can be overcome by eliminating the explicit Return statement from the PlotLabelerFunction. I changed the code as follows:

(* updated Dynamic Overlay Code *)

Dynamic[

 Which[  (* 
  this Which statement is used for responding to toggling of label overlay
on/off *)

  showLabels == False,


  Column[
   {

    Dynamic[Image[Colorize[watershedMatrix[[currentFrame]]], 
      ImageSize -> 450]]

    }
   ] (* close showLabels==False Column *)
  ,

  showLabels == True,

  Column[
   {


    Dynamic[


     Show[Colorize[watershedMatrix[[currentFrame]]], 
      PlotLabelerFunction[
       watershedMatrix[[currentFrame]]], ImageSize -> 450]

        ]



    }
   ]   (* close showLabels==True Column *)
  ] (* close showLabels Which *)

 ]  (* close Dynamic wrapping whole showLabels Which *)




PlotLabelerFunction[matrixIn_List] :=

 Block[{medoids, textTable, labelsOnlyPlot},


  medoids = ComponentMeasurements[matrixIn, "Medoid"];

  textTable = Table[


    Text[Style[medoids[[i, 1]], Large, Red, Bold], N[medoids[[i, 2]]]],


    {i, 1, Length[medoids]}];


(* removed semicolon so labelsOnlyPlot will be returned from function *)  

        labelsOnlyPlot = 
   Graphics[textTable, Axes -> False, AxesOrigin -> {1, 1}, 
    PlotRange -> {{1, Dimensions[matrixIn][[1]]}, {1, 
       Dimensions[matrixIn][[2]]}}]


  (*  commented out this part of code and now locators in LocatorPane do not slow down:

  Return[{textTable,labelsOnlyPlot}];

  *)


  ] (* close Block *)

Although this works to prevent the sluggish locator responsiveness it is still not clear to me why this works or why the LocatorPane should have had the slow down in the first place.

Anyone have any insight into this odd LocatorPane behavior?

$\endgroup$

Your Answer

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

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