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
52 changes: 49 additions & 3 deletions src/main/java/net/imagej/ops/transform/TransformNamespace.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import net.imglib2.img.array.ArrayImg;
import net.imglib2.interpolation.InterpolatorFactory;
import net.imglib2.outofbounds.OutOfBoundsFactory;
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 @@ -173,7 +174,8 @@ public <T> MixedTransformView<T> addDimensionView(
@OpMethod(
op = net.imagej.ops.transform.collapseNumericView.DefaultCollapseNumeric2CompositeView.class)
public <N extends NumericType<N>> CompositeView<N, NumericComposite<N>>
collapseNumericView(final RandomAccessible<N> input, final int numChannels)
collapseNumericView(final RandomAccessible<N> input,
final int numChannels)
{
return (CompositeView<N, NumericComposite<N>>) ops().run(
Ops.Transform.CollapseNumericView.class, input, numChannels);
Expand Down Expand Up @@ -335,7 +337,8 @@ ExtendedRandomAccessibleInterval<T, F> extendBorderView(final F input)
@OpMethod(
op = net.imagej.ops.transform.extendMirrorDoubleView.DefaultExtendMirrorDoubleView.class)
public <T, F extends RandomAccessibleInterval<T>>
ExtendedRandomAccessibleInterval<T, F> extendMirrorDoubleView(final F input)
ExtendedRandomAccessibleInterval<T, F> extendMirrorDoubleView(
final F input)
{
return (ExtendedRandomAccessibleInterval<T, F>) ops().run(
Ops.Transform.ExtendMirrorDoubleView.class, input);
Expand All @@ -354,7 +357,8 @@ ExtendedRandomAccessibleInterval<T, F> extendMirrorDoubleView(final F input)
@OpMethod(
op = net.imagej.ops.transform.extendMirrorSingleView.DefaultExtendMirrorSingleView.class)
public <T extends Type<T>, F extends RandomAccessibleInterval<T>>
ExtendedRandomAccessibleInterval<T, F> extendMirrorSingleView(final F input)
ExtendedRandomAccessibleInterval<T, F> extendMirrorSingleView(
final F input)
{
return (ExtendedRandomAccessibleInterval<T, F>) ops().run(
Ops.Transform.ExtendMirrorSingleView.class, input);
Expand Down Expand Up @@ -1203,4 +1207,46 @@ 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(
Ops.Transform.RealTransform.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(
Ops.Transform.RealTransform.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(
Ops.Transform.RealTransform.class, in,
transform, outputInterval, interpolator);
return result;
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
* #%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;

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

@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
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
/*-
* #%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 static org.junit.Assert.assertEquals;

import net.imagej.ops.AbstractOpTest;
import net.imglib2.Cursor;
import net.imglib2.RandomAccess;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.Img;
import net.imglib2.realtransform.AffineTransform2D;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.view.Views;

import org.junit.Test;

public class RealTransformTest extends AbstractOpTest {

@Test
public void regressionTest() throws Exception {

final Img<UnsignedByteType> image = openUnsignedByteType(getClass(),
"lowresbridge.tif");
final Img<UnsignedByteType> expectedOutput = openUnsignedByteType(
getClass(), "rotatedscaledcenter.tif");

final AffineTransform2D transform = new AffineTransform2D();

transform.translate(-image.dimension(0) / 2, -image.dimension(0) / 2);
transform.rotate(1);
transform.scale(0.5);
transform.translate(image.dimension(0) / 2, image.dimension(0) / 2);

@SuppressWarnings("unchecked")
final RandomAccessibleInterval<UnsignedByteType> actualOutput =
(RandomAccessibleInterval<UnsignedByteType>) ops.run(
net.imagej.ops.transform.realTransform.DefaultTransformView.class,
image, transform);

// compare the output image data to that stored in the file.
final Cursor<UnsignedByteType> cursor = Views.iterable(actualOutput)
.localizingCursor();
final RandomAccess<UnsignedByteType> actualRA = actualOutput.randomAccess();
final RandomAccess<UnsignedByteType> expectedRA = expectedOutput
.randomAccess();

while (cursor.hasNext()) {
cursor.fwd();
actualRA.setPosition(cursor);
expectedRA.setPosition(cursor);
assertEquals(expectedRA.get().get(), actualRA.get().get(), 0);
}

}

}
Binary file not shown.
Binary file not shown.