Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@
<artifactId>scifio</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.imagej</groupId>
<artifactId>imagej-ui-swing</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<!-- Do not remove - Maven incorrectly identifies it as an unused dependency! -->
<groupId>org.scijava</groupId>
Expand Down
168 changes: 155 additions & 13 deletions src/main/java/net/imagej/ops/segment/SegmentNamespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Expand All @@ -35,16 +35,23 @@
import net.imagej.ops.Namespace;
import net.imagej.ops.OpMethod;
import net.imagej.ops.Ops;
import net.imagej.ops.segment.hough.HoughCircle;
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.RealPoint;
import net.imglib2.img.Img;
import net.imglib2.roi.geom.real.WritablePolyline;
import net.imglib2.type.BooleanType;
import net.imglib2.type.NativeType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.type.numeric.real.DoubleType;

import org.scijava.plugin.Plugin;

/**
* The segment namespace contains segmentation operations.
*
*
* @author Gabe Selzer
*/
@Plugin(type = Namespace.class)
Expand All @@ -61,28 +68,32 @@ public <T extends RealType<T>> List<? extends WritablePolyline> detectRidges(
final int ridgeLengthMin)
{
@SuppressWarnings("unchecked")
final List<? extends WritablePolyline> result = (List<? extends WritablePolyline>) ops().run(
Ops.Segment.DetectRidges.class, input, width, lowerThreshold,
higherThreshold, ridgeLengthMin);
final List<? extends WritablePolyline> result =
(List<? extends WritablePolyline>) ops().run(
Ops.Segment.DetectRidges.class, input, width, lowerThreshold,
higherThreshold, ridgeLengthMin);

return result;
}

// -- detectJunctions --

@OpMethod(op = net.imagej.ops.segment.detectJunctions.DefaultDetectJunctions.class)
public List<RealPoint> detectJunctions(final List<? extends WritablePolyline> lines)

@OpMethod(
op = net.imagej.ops.segment.detectJunctions.DefaultDetectJunctions.class)
public List<RealPoint> detectJunctions(
final List<? extends WritablePolyline> lines)
{
@SuppressWarnings("unchecked")
final List<RealPoint> result = (List<RealPoint>) ops().run(
Ops.Segment.DetectJunctions.class, lines);

return result;
}

@OpMethod(op = net.imagej.ops.segment.detectJunctions.DefaultDetectJunctions.class)
public List<RealPoint> detectJunctions(final List<? extends WritablePolyline> lines,
final double threshold)

@OpMethod(
op = net.imagej.ops.segment.detectJunctions.DefaultDetectJunctions.class)
public List<RealPoint> detectJunctions(
final List<? extends WritablePolyline> lines, final double threshold)
{
@SuppressWarnings("unchecked")
final List<RealPoint> result = (List<RealPoint>) ops().run(
Expand All @@ -91,6 +102,137 @@ public List<RealPoint> detectJunctions(final List<? extends WritablePolyline> li
return result;
}

// -- detectHoughCircleDoG --

@OpMethod(op = net.imagej.ops.segment.hough.HoughCircleDetectorDogOp.class)
public <T extends RealType<T> & NativeType<T>> List<HoughCircle>
detectHoughCircleDoG(final RandomAccessibleInterval<T> in,
final double circleThickness, final double minRadius,
final double stepRadius, final double sigma)
{
@SuppressWarnings("unchecked")
final List<HoughCircle> result = (List<HoughCircle>) ops().run(
net.imagej.ops.Ops.Segment.DetectHoughCircleDoG.class, in,
circleThickness, minRadius, stepRadius, sigma);
return result;
}

@OpMethod(op = net.imagej.ops.segment.hough.HoughCircleDetectorDogOp.class)
public <T extends RealType<T> & NativeType<T>> List<HoughCircle>
detectHoughCircleDoG(final RandomAccessibleInterval<T> in,
final double circleThickness, final double minRadius,
final double stepRadius, final double sigma, final double sensitivity)
{
@SuppressWarnings("unchecked")
final List<HoughCircle> result = (List<HoughCircle>) ops().run(
net.imagej.ops.Ops.Segment.DetectHoughCircleDoG.class, in,
circleThickness, minRadius, stepRadius, sigma, sensitivity);
return result;
}

// -- detectHoughCircleLE --

@OpMethod(
op = net.imagej.ops.segment.hough.HoughCircleDetectorLocalExtremaOp.class)
public <T extends RealType<T> & NativeType<T>> List<HoughCircle>
detectHoughCircleLE(final RandomAccessibleInterval<T> in,
final double minRadius, final double stepRadius)
{
@SuppressWarnings("unchecked")
final List<HoughCircle> result = (List<HoughCircle>) ops().run(
net.imagej.ops.Ops.Segment.DetectHoughCircleLE.class, in, minRadius,
stepRadius);
return result;
}

@OpMethod(
op = net.imagej.ops.segment.hough.HoughCircleDetectorLocalExtremaOp.class)
public <T extends RealType<T> & NativeType<T>> List<HoughCircle>
detectHoughCircleLE(final RandomAccessibleInterval<T> in,
final double minRadius, final double stepRadius, final double sensitivity)
{
@SuppressWarnings("unchecked")
final List<HoughCircle> result = (List<HoughCircle>) ops().run(
net.imagej.ops.Ops.Segment.DetectHoughCircleLE.class, in, minRadius,
stepRadius, sensitivity);
return result;
}

// -- transformHoughCircle --

@OpMethod(op = net.imagej.ops.segment.hough.HoughTransformOpNoWeights.class)
public <T extends BooleanType<T>> Img<DoubleType> transformHoughCircle(
final IterableInterval<T> in, final long minRadius, final long maxRadius)
{
@SuppressWarnings("unchecked")
final Img<DoubleType> result = (Img<DoubleType>) ops().run(
net.imagej.ops.Ops.Segment.TransformHoughCircle.class, in, minRadius,
maxRadius);
return result;
}

@OpMethod(op = net.imagej.ops.segment.hough.HoughTransformOpNoWeights.class)
public <T extends BooleanType<T>> Img<DoubleType> transformHoughCircle(
final Img<DoubleType> out, final IterableInterval<T> in,
final long minRadius, final long maxRadius)
{
@SuppressWarnings("unchecked")
final Img<DoubleType> result = (Img<DoubleType>) ops().run(
net.imagej.ops.Ops.Segment.TransformHoughCircle.class, out, in, minRadius,
maxRadius);
return result;
}

@OpMethod(op = net.imagej.ops.segment.hough.HoughTransformOpNoWeights.class)
public <T extends BooleanType<T>> Img<DoubleType> transformHoughCircle(
final Img<DoubleType> out, final IterableInterval<T> in,
final long minRadius, final long maxRadius, final long stepRadius)
{
@SuppressWarnings("unchecked")
final Img<DoubleType> result = (Img<DoubleType>) ops().run(
net.imagej.ops.Ops.Segment.TransformHoughCircle.class, out, in, minRadius,
maxRadius, stepRadius);
return result;
}

@OpMethod(op = net.imagej.ops.segment.hough.HoughTransformOpWeights.class)
public <T extends BooleanType<T>, R extends RealType<R>> Img<DoubleType>
transformHoughCircle(final IterableInterval<T> in, final long minRadius,
final long maxRadius, final RandomAccessible<R> weights)
{
@SuppressWarnings("unchecked")
final Img<DoubleType> result = (Img<DoubleType>) ops().run(
net.imagej.ops.Ops.Segment.TransformHoughCircle.class, in, minRadius,
maxRadius, weights);
return result;
}

@OpMethod(op = net.imagej.ops.segment.hough.HoughTransformOpWeights.class)
public <T extends BooleanType<T>, R extends RealType<R>> Img<DoubleType>
transformHoughCircle(final Img<DoubleType> out,
final IterableInterval<T> in, final long minRadius, final long maxRadius,
final RandomAccessible<R> weights)
{
@SuppressWarnings("unchecked")
final Img<DoubleType> result = (Img<DoubleType>) ops().run(
net.imagej.ops.Ops.Segment.TransformHoughCircle.class, out, in, minRadius,
maxRadius, weights);
return result;
}

@OpMethod(op = net.imagej.ops.segment.hough.HoughTransformOpWeights.class)
public <T extends BooleanType<T>, R extends RealType<R>> Img<DoubleType>
transformHoughCircle(final Img<DoubleType> out,
final IterableInterval<T> in, final long minRadius, final long maxRadius,
final long stepRadius, final RandomAccessible<R> weights)
{
@SuppressWarnings("unchecked")
final Img<DoubleType> result = (Img<DoubleType>) ops().run(
net.imagej.ops.Ops.Segment.TransformHoughCircle.class, out, in, minRadius,
maxRadius, stepRadius, weights);
return result;
}

// -- Namespace methods --

@Override
Expand Down
81 changes: 81 additions & 0 deletions src/main/java/net/imagej/ops/segment/hough/HoughCircle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package net.imagej.ops.segment.hough;

import net.imglib2.RealLocalizable;
import net.imglib2.roi.geom.real.AbstractWritableSphere;

/**
* Representation of a circle segmented via Hough circle transformation.
* <p>
* Instances are {@link RealLocalizable} and have a radius (in pixel units) and
* a sensitivity. The sensitivity factor is used to report a quality of the
* Hough circle detection, the smallest the better the circle. The sensitivity
* can be used to sort a list of circles.
*
* @author Jean-Yves Tinevez.
* @author Gabe Selzer.
*
*/
public class HoughCircle extends AbstractWritableSphere implements
Comparable<HoughCircle>
{

private final double sensitivity;

public HoughCircle( final RealLocalizable pos, final double radius, final double sensitivity )
{
super( getCenter(pos) , radius);
this.radius = radius;
this.sensitivity = sensitivity;
}

private static double[] getCenter(RealLocalizable l) {
double[] center = new double[l.numDimensions()];
l.localize(center);
return center;
}

@Override
public String toString()
{
final StringBuilder sb = new StringBuilder();
char c = '(';
for ( int i = 0; i < numDimensions(); i++ )
{
sb.append( c );
sb.append( String.format( "%.1f", center[ i ] ) );
c = ',';
}
sb.append( ")" );
return String.format( "%s\tR=%.1f\tSensitivity=%.1f", sb.toString(), radius, sensitivity );
}

public double getRadius()
{
return radius;
}

public double getSensitivity()
{
return sensitivity;
}

@Override
public int compareTo( final HoughCircle o )
{
return sensitivity < o.sensitivity ? -1 : sensitivity > o.sensitivity ? +1 : 0;
}

@Override
public boolean test( final RealLocalizable point )
{
final double dx = center[0] - point.getDoublePosition( 0 );
final double dy = center[1] - point.getDoublePosition( 1 );
final double dr2 = dx * dx + dy * dy;

if ( dr2 < radius * radius )
return false;

return true;
}

}
Loading