|
58 | 58 | */ |
59 | 59 | @Plugin(type = HoughCircle.class, priority = Priority.HIGH_PRIORITY) |
60 | 60 | 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 | +{ |
63 | 64 |
|
64 | 65 | @Parameter(min = "4", description = "The radius to search for, in pixels.") |
65 | 66 | int minRadius; |
66 | | - |
| 67 | + |
67 | 68 | @Parameter(description = "The maximum radius to search for, in pixels.") |
68 | 69 | 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") |
71 | 73 | int stepRadius = 1; |
72 | | - |
| 74 | + |
73 | 75 | @Parameter(min = "2", |
74 | 76 | description = "The number of points required to consider a circle.") |
75 | 77 | 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 | + |
77 | 96 | @Override |
78 | 97 | 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. |
81 | 101 | 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) { |
85 | 106 | 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 | + } |
89 | 113 | } |
90 | 114 | } |
91 | 115 |
|
|
0 commit comments