Wolfram Language

Image and Signal Processing

Interactive Image Measurements

DynamicImage facilitates the construction of custom interfaces to interactively measure objects in images.

Consider the measurement of a cell radius r.

In[1]:=
Click for copyable input

Use Alt+click to position the center of a yellow measurement circle. Move the slider to change the circle radius r.

show complete Wolfram Language input
In[2]:=
Click for copyable input
measurementCircle[Dynamic[center_], Dynamic[r_]] := {Yellow, Thick, Dynamic@Circle[center, r], Dynamic@Text[ Style[StringJoin[ToString@Round@r, "px"], FontSize -> 18], Scaled@{0.1, 0.9}, Background -> RGBColor[0, 0, 0, 0.5]]}; DynamicModule[ {center = ImageDimensions[img1]/2, r}, Manipulate[ EventHandler[ DynamicImage[ img1, Epilog -> measurementCircle[Dynamic[center], Dynamic[r]] ], {"MouseDown" :> If[CurrentValue["OptionKey"], center = MousePosition["Graphics"]]}, PassEventsDown -> Dynamic[Not[CurrentValue["OptionKey"]]] ], {{r, 32}, 8, 800}, FrameMargins -> 0 ] ]
Play Animation
Stop Animation

Measure the length of a DNA strand by tracing it manually.

In[3]:=
Click for copyable input

Use Alt+click to place the vertices of a line. Alt+Shift+click deletes the last vertex.

show complete Wolfram Language input
In[4]:=
Click for copyable input
measurementLine[Dynamic[pts_], Dynamic[length_]] := {Yellow, Thick, Dynamic@Line[pts], Dynamic@Text[ Style[StringJoin[ToString@Round@length, "px"], FontSize -> 18], Scaled@{0.1, 0.9}, Background -> RGBColor[0, 0, 0, 0.5]]} DynamicModule[ {pts = {}, length = 0}, Panel@EventHandler[ DynamicImage[ img2, Epilog -> measurementLine[Dynamic[pts], Dynamic[length]] ], {"MouseDown" :> If[CurrentValue["OptionKey"], If[CurrentValue["ShiftKey"], pts = Most[pts], AppendTo[pts, MousePosition["Graphics"]]]; length = Total@Apply[EuclideanDistance, Partition[pts, 2, 1], {1}]]}, PassEventsDown -> Dynamic[Not[CurrentValue["OptionKey"]]] ] ]
Play Animation
Stop Animation

Related Examples

de es fr ja ko pt-br ru zh