UPDATE: Added a few workarounds for bugs / features introduced in Mathematica v10 or later.
Main issue involved LocatorPane
whose Appearance
option no longer correctly handles more than one Graphics
object [CASE:4984027]. This bug was introduced somewhere after v11.3 and is present in v.13.1. Additional issues concerned the scaling of the graphics used in the various panels, which was incorrect. Perhaps a different default was introduced somewhere after v9 where the code worked as intended.
Original text
findMarkers[img_, pt_, thres_, minArea_] :=
ComponentMeasurements[
MorphologicalComponents[
ColorNegate[
Binarize[
ImageCorrelate[
imgImageCorrelate[img,
ImageTrim[img, pt],
NormalizedSquaredEuclideanDistance
], thresthres]
]
],
], {"Centroid", "Area"},
#2 > minArea &
][[All, 2, 1]];
SetAttributes[getMarkers, HoldRest];
getMarkers[img_, resMarkers_] :=
DynamicModule[
{
pt = {ImageDimensions[img]/4, ImageDimensions[img]/2},
axisDefinePane, defineMarkerPane, findMarkerPane, editMarkersPane,
finalResultPane, xAxisBegin, xAxisEnd, yAxisBegin, yAxisEnd,
myMarkers, myTransform,
xoy = {{1/2, 1/8} ImageDimensions[img],
{1/8, 1/8} ImageDimensions[img], ImageDimensions[
img], {1/8, 1/2} ImageDimensions[img]}},
axisDefinePane },=
Grid[
axisDefinePane = {
Grid[{ {
LocatorPane[
Dynamic[xoy],
Dynamic[
Show[
img,
Graphics[{Line[xoy]}],
ImageSize -> ImageDimensions[img]
]
],
Appearance ->
{Graphics[{Red, AbsolutePointSize[5], {
Graphics[{AbsolutePointSize[5], Red, Point[{0, 0}]}],
Graphics[{GreenAbsolutePointSize[5], AbsolutePointSize[5]Green, Point[{0, 0}]}],
Graphics[{BlueAbsolutePointSize[5], AbsolutePointSize[5]Blue, Point[{0, 0}]}]
}
]
},
{Row[{"x(1): ",
InputField[Dynamic[xAxisBegin], Number, FieldSize -> Tiny],
" x(2): ",
InputField[Dynamic[xAxisEnd], Number,
FieldSize -> Tiny]}]},
{Row[{"y(1): ",
InputField[Dynamic[yAxisBegin], Number, FieldSize -> Tiny],
" y(2): ",
InputField[Dynamic[yAxisEnd], Number, FieldSize
-> Tiny]}]}
}
FieldSize -> Tiny]}]}}];
defineMarkerPane =
LocatorPane[
Dynamic[pt],
Dynamic[
Show[
img,
Graphics[
{
EdgeForm[Black], FaceForm[], Rectangle @@ pt
}],
ImageSize ]-> ImageDimensions[img]
]
],
Appearance -> Graphics[{Red, AbsolutePointSize[5], Point[{0Style["\[FilledSmallCircle]", 0}]}]Red]
];
findMarkerPane =
Manipulate[
Show[
img,
Graphics[{Red,
Circle[#, 5] & /@ (myMarkers = findMarkers[img, pt, t, 1.05])}],
ImageSize -> ImageDimensions[img]
],
{{t, 0.2, "Threshold"}, 0, 1},
TrackedSymbols -> {t},
ControlPlacement -> Bottom
];
editMarkersPane =
LocatorPane[Dynamic[LocatorPane[
myMarkers] Dynamic[myMarkers],
img,
Appearance ->
Graphics[{Red, Circle[{0, 0}, 1]}, ImageSize -> 10],
LocatorAutoCreate -> True
];
finalResultPane =
Dynamic[myTransform = Dynamic[
FindGeometricTransform[
myTransform =
FindGeometricTransform[{{xAxisEnd, yAxisBegin}, {xAxisBegin, yAxisBegin},
yAxisBegin}, {xAxisBegin, yAxisEnd}
}, xoy
][[2]]xoy][[2]] // Quiet;
ListLinePlot[resMarkers = myTransform /@ Sort[myMarkers],
Frame -> True, Mesh -> All]All, ImageSize -> ImageDimensions[img]],
TrackedSymbols -> {myMarkers, xoy, xAxisEnd, yAxisBegin,
xAxisBegin, yAxisBegin, xAxisBegin, yAxisEnd}
];
TabView[
{
"Define axes" -> axisDefinePane,
"Define marker" -> defineMarkerPane,
"Find Markers" -> findMarkerPane,
"Edit Markers" -> editMarkersPane,
"Results" -> finalResultPane
}
]
]