1
$\begingroup$

Consider an image (img) as

enter image description here

Using the following code I can dynamically change the value of t and see the updated components.

Manipulate[
 bin = MorphologicalBinarize[img,{t[[1]],t[[2]]}];
 Colorize[MorphologicalComponents[bin]],
{t, 0, 1}, ControlType -> IntervalSlider
]

I can switch to DynamicModule in the following way:

DynamicModule[{},
 bin = Dynamic@MorphologicalBinarize[img, t];
 c = Dynamic@Colorize[MorphologicalComponents[Setting@bin]];
 {c, Dynamic@IntervalSlider[Dynamic[t]]}
 ]

So far this is fine. However, I have several other lines of codes followed by this inside DynamicModule and every time I need to apply Dynamic to get the updated result and when one result is to be applied to the next line I need to use Setting.

Do I need to use Dynamic at each operation and followed by Setting or is there any better way to avoid this?

$\endgroup$
  • $\begingroup$ No, you do not need, DynamicModule[{}, c = Dynamic[ bin = MorphologicalBinarize[img, t]; Colorize[MorphologicalComponents[bin]] ]; {c, Dynamic@IntervalSlider[Dynamic[t]]}] $\endgroup$ – Kuba Feb 28 '18 at 20:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.