Skip to content

Commit fdf9900

Browse files
committed
WIP: Variable Radius Transform Op
1 parent 78d4749 commit fdf9900

File tree

1 file changed

+39
-15
lines changed

1 file changed

+39
-15
lines changed

src/main/java/net/imagej/ops/segment/hough/CircleTransformVariableRadius.java

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -58,34 +58,58 @@
5858
*/
5959
@Plugin(type = HoughCircle.class, priority = Priority.HIGH_PRIORITY)
6060
public class CircleTransformVariableRadius<T extends RealType<T>> extends
61-
AbstractUnaryComputerOp<RandomAccessibleInterval<T>, List<Sphere>> implements
62-
Contingent, Ops.Segment.HoughCircle {
61+
AbstractUnaryComputerOp<RandomAccessibleInterval<T>, List<Sphere>> implements
62+
Contingent, Ops.Segment.HoughCircle
63+
{
6364

6465
@Parameter(min = "4", description = "The radius to search for, in pixels.")
6566
int minRadius;
66-
67+
6768
@Parameter(description = "The maximum radius to search for, in pixels.")
6869
int maxRadius;
69-
70-
@Parameter(description = "The increase in the radius between runs of the transform")
70+
71+
@Parameter(
72+
description = "The increase in the radius between runs of the transform")
7173
int stepRadius = 1;
72-
74+
7375
@Parameter(min = "2",
7476
description = "The number of points required to consider a circle.")
7577
int threshold;
76-
78+
79+
// checks the current sphere against all of the other spheres for center and
80+
// radius
81+
private boolean checkForSimilar(Sphere s, List<Sphere> output) {
82+
for (Sphere t : output) {
83+
double[] sCenter = s.center();
84+
double[] tCenter = t.center();
85+
double diff = Math.sqrt(Math.pow(tCenter[0] - sCenter[0], 2) + Math.pow(
86+
tCenter[1] - sCenter[1], 2));
87+
// if the centers are close to each other and the radii are pretty close,
88+
// then the two are too similar to be two different circles
89+
if (diff < Math.sqrt(s.radius()) || diff < Math.sqrt(t.radius())) {
90+
if (Math.abs(t.radius() - s.radius()) < 3) return true;
91+
}
92+
}
93+
return false;
94+
}
95+
7796
@Override
7897
public void compute(RandomAccessibleInterval<T> input, List<Sphere> output) {
79-
80-
// List of spheres generated during each iteration, added to output at end of iteration.
98+
99+
// List of spheres generated during each iteration, added to output at end
100+
// of iteration.
81101
List<Sphere> currentOutput;
82-
83-
//loop through radii, call set radius transform at each step, add step output to total output.
84-
for(int i = minRadius; i <= maxRadius; i += stepRadius) {
102+
103+
// loop through radii, call set radius transform at each step, add step
104+
// output to total output.
105+
for (int i = minRadius; i <= maxRadius; i += stepRadius) {
85106
currentOutput = new ArrayList<Sphere>();
86-
ops().run(net.imagej.ops.segment.hough.CircleTransform.class, currentOutput, input, i, threshold);
87-
88-
for(Sphere s: currentOutput) output.add(s);
107+
ops().run(net.imagej.ops.segment.hough.CircleTransform.class,
108+
currentOutput, input, i, threshold);
109+
110+
for (Sphere s : currentOutput) {
111+
if (!checkForSimilar(s, output)) output.add(s);
112+
}
89113
}
90114
}
91115

0 commit comments

Comments
 (0)