‹›Image and Signal ProcessingInteractive Image Measurements
DynamicImage facilitates the construction of custom interfaces to interactively measure objects in images.
Consider the measurement of a cell radius .
Use Alt+click to position the center of a yellow measurement circle.
Move the slider to change the circle radius .
show complete Wolfram Language 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
]
]
Measure the length of a DNA strand by tracing it manually.
Use Alt+click to place the vertices of a line. Alt+Shift+click deletes the last vertex.
show complete Wolfram Language 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"]]]
]
]