Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
57 changes: 56 additions & 1 deletion src/main/java/net/imagej/ops/transform/TransformNamespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
import net.imglib2.img.array.ArrayImg;
import net.imglib2.interpolation.InterpolatorFactory;
import net.imglib2.outofbounds.OutOfBoundsFactory;
import net.imglib2.realtransform.RealTransform;
import net.imglib2.realtransform.InvertibleRealTransform;
import net.imglib2.transform.integer.shear.InverseShearTransform;
import net.imglib2.transform.integer.shear.ShearTransform;
import net.imglib2.type.Type;
Expand Down Expand Up @@ -1207,4 +1207,59 @@ public <T extends Type<T>> RandomAccessibleInterval<T> concatenateView(
ConcatenateViewWithAccessMode.class, source, concatenationAxis, mode);
}

@OpMethod(
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
final RandomAccessibleInterval<T> in,
final InvertibleRealTransform transform)
{
final RandomAccessibleInterval<T> result =
(RandomAccessibleInterval<T>) ops().run(
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
transform);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be ops().run(Ops.Transform.RealTransform.class, in, transform). That way, in the future, someone could write an op which is a specialized version of this and it could also be matched.

Please change this for all your other realTransform(...) namespace methods as well.

return result;
}

@OpMethod(
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
final RandomAccessibleInterval<T> in,
final InvertibleRealTransform transform, final Interval outputInterval)
{
final RandomAccessibleInterval<T> result =
(RandomAccessibleInterval<T>) ops().run(
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
transform, outputInterval);
return result;
}

@OpMethod(
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
final RandomAccessibleInterval<T> in,
final InvertibleRealTransform transform, final Interval outputInterval,
final InterpolatorFactory<T, RandomAccessible<T>> interpolator)
{
final RandomAccessibleInterval<T> result =
(RandomAccessibleInterval<T>) ops().run(
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
transform, outputInterval, interpolator);
return result;
}

@OpMethod(
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
final RandomAccessibleInterval<T> in,
final InvertibleRealTransform transform, final Interval outputInterval,
final InterpolatorFactory<T, RandomAccessible<T>> interpolator,
final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBoundsFactory)
{
final RandomAccessibleInterval<T> result =
(RandomAccessibleInterval<T>) ops().run(
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
transform, outputInterval, interpolator, outOfBoundsFactory);
return result;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*
* #%L
* ImageJ software for multidimensional image processing and analysis.
* %%
* Copyright (C) 2014 - 2018 ImageJ developers.
* %%
* 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
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

package net.imagej.ops.transform.realTransform;

import net.imagej.ops.Ops;
import net.imagej.ops.special.function.AbstractUnaryFunctionOp;
import net.imglib2.FinalInterval;
import net.imglib2.Interval;
import net.imglib2.RandomAccessible;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.interpolation.InterpolatorFactory;
import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory;
import net.imglib2.outofbounds.OutOfBoundsFactory;
import net.imglib2.outofbounds.OutOfBoundsMirrorFactory;
import net.imglib2.realtransform.InvertibleRealTransform;
import net.imglib2.realtransform.RealViews;
import net.imglib2.type.numeric.NumericType;
import net.imglib2.type.numeric.RealType;
import net.imglib2.view.IntervalView;
import net.imglib2.view.Views;

import org.scijava.Priority;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

/**
* Applies an Affine transform to a {@link RandomAccessibleInterval}
*
* @author Brian Northan (True North Intelligent Algorithms)
* @author Martin Horn (University of Konstanz)
* @author Stefan Helfrich (University of Konstanz)
*/
@Plugin(type = Ops.Transform.RealTransform.class, priority = Priority.HIGH + 1)
public class DefaultTransformView<T extends NumericType<T> & RealType<T>>
extends
AbstractUnaryFunctionOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>>
implements Ops.Transform.RealTransform
{

/**
* The transform to apply
*/
@Parameter
InvertibleRealTransform transform;

@Parameter(required = false)
private Interval outputInterval = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't need to be explicitly set to null. You can just have private Interval outputInterval.


@Parameter(required = false)
private InterpolatorFactory<T, RandomAccessible<T>> interpolator = null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just be private InterpolatorFactory<T, RandomAccessible<T>> interpolator;. There's no need for the = null.


@Parameter(required = false)
private OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBoundsFactory =
new OutOfBoundsMirrorFactory<>(OutOfBoundsMirrorFactory.Boundary.SINGLE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't used (unless I'm missing something?). On line 97 you call Views.extendZero(input), so zero padding is always the out of bounds strategy. Do you want the user to be able to specify their own out of bounds strategy?


@Override
public RandomAccessibleInterval<T> calculate(
final RandomAccessibleInterval<T> input)
{

if (outputInterval == null) {
outputInterval = new FinalInterval(input);
}

if (interpolator == null) {
interpolator = new LanczosInterpolatorFactory<>();
}

final IntervalView<T> interval = Views.interval(Views.raster(RealViews
.transformReal(Views.interpolate(Views.extendZero(input), interpolator),
transform)), outputInterval);

return interval;
}

}
1 change: 1 addition & 0 deletions src/main/templates/net/imagej/ops/Ops.list
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ namespaces = ```
[name: "translateView", iface: "TranslateView"],
[name: "unshearView", iface: "UnshearView"],
[name: "zeroMinView", iface: "ZeroMinView"],
[name: "realTransform", iface: "RealTransform"],
]],
[name: "zernike", iface: "Zernike", ops: [
[name: "magnitude", iface: "Magnitude"],
Expand Down