Skip to content

Commit b882573

Browse files
bnorthanawalter17
authored andcommitted
Add transform interface and default op
1 parent 9185384 commit b882573

File tree

3 files changed

+160
-1
lines changed

3 files changed

+160
-1
lines changed

src/main/java/net/imagej/ops/transform/TransformNamespace.java

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
import net.imglib2.img.array.ArrayImg;
5151
import net.imglib2.interpolation.InterpolatorFactory;
5252
import net.imglib2.outofbounds.OutOfBoundsFactory;
53-
import net.imglib2.realtransform.RealTransform;
53+
import net.imglib2.realtransform.InvertibleRealTransform;
5454
import net.imglib2.transform.integer.shear.InverseShearTransform;
5555
import net.imglib2.transform.integer.shear.ShearTransform;
5656
import net.imglib2.type.Type;
@@ -1207,4 +1207,59 @@ public <T extends Type<T>> RandomAccessibleInterval<T> concatenateView(
12071207
ConcatenateViewWithAccessMode.class, source, concatenationAxis, mode);
12081208
}
12091209

1210+
@OpMethod(
1211+
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
1212+
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
1213+
final RandomAccessibleInterval<T> in,
1214+
final InvertibleRealTransform transform)
1215+
{
1216+
final RandomAccessibleInterval<T> result =
1217+
(RandomAccessibleInterval<T>) ops().run(
1218+
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
1219+
transform);
1220+
return result;
1221+
}
1222+
1223+
@OpMethod(
1224+
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
1225+
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
1226+
final RandomAccessibleInterval<T> in,
1227+
final InvertibleRealTransform transform, final Interval outputInterval)
1228+
{
1229+
final RandomAccessibleInterval<T> result =
1230+
(RandomAccessibleInterval<T>) ops().run(
1231+
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
1232+
transform, outputInterval);
1233+
return result;
1234+
}
1235+
1236+
@OpMethod(
1237+
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
1238+
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
1239+
final RandomAccessibleInterval<T> in,
1240+
final InvertibleRealTransform transform, final Interval outputInterval,
1241+
final InterpolatorFactory<T, RandomAccessible<T>> interpolator)
1242+
{
1243+
final RandomAccessibleInterval<T> result =
1244+
(RandomAccessibleInterval<T>) ops().run(
1245+
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
1246+
transform, outputInterval, interpolator);
1247+
return result;
1248+
}
1249+
1250+
@OpMethod(
1251+
op = net.imagej.ops.transform.realTransform.DefaultTransformView.class)
1252+
public <T extends RealType<T>> RandomAccessibleInterval<T> realTransform(
1253+
final RandomAccessibleInterval<T> in,
1254+
final InvertibleRealTransform transform, final Interval outputInterval,
1255+
final InterpolatorFactory<T, RandomAccessible<T>> interpolator,
1256+
final OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBoundsFactory)
1257+
{
1258+
final RandomAccessibleInterval<T> result =
1259+
(RandomAccessibleInterval<T>) ops().run(
1260+
net.imagej.ops.transform.realTransform.DefaultTransformView.class, in,
1261+
transform, outputInterval, interpolator, outOfBoundsFactory);
1262+
return result;
1263+
}
1264+
12101265
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2018 ImageJ developers.
6+
* %%
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions are met:
9+
*
10+
* 1. Redistributions of source code must retain the above copyright notice,
11+
* this list of conditions and the following disclaimer.
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
20+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26+
* POSSIBILITY OF SUCH DAMAGE.
27+
* #L%
28+
*/
29+
30+
package net.imagej.ops.transform.realTransform;
31+
32+
import net.imagej.ops.Ops;
33+
import net.imagej.ops.special.function.AbstractUnaryFunctionOp;
34+
import net.imglib2.FinalInterval;
35+
import net.imglib2.Interval;
36+
import net.imglib2.RandomAccessible;
37+
import net.imglib2.RandomAccessibleInterval;
38+
import net.imglib2.interpolation.InterpolatorFactory;
39+
import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory;
40+
import net.imglib2.outofbounds.OutOfBoundsFactory;
41+
import net.imglib2.outofbounds.OutOfBoundsMirrorFactory;
42+
import net.imglib2.realtransform.InvertibleRealTransform;
43+
import net.imglib2.realtransform.RealViews;
44+
import net.imglib2.type.numeric.NumericType;
45+
import net.imglib2.type.numeric.RealType;
46+
import net.imglib2.view.IntervalView;
47+
import net.imglib2.view.Views;
48+
49+
import org.scijava.Priority;
50+
import org.scijava.plugin.Parameter;
51+
import org.scijava.plugin.Plugin;
52+
53+
/**
54+
* Applies an Affine transform to a {@link RandomAccessibleInterval}
55+
*
56+
* @author Brian Northan (True North Intelligent Algorithms)
57+
* @author Martin Horn (University of Konstanz)
58+
* @author Stefan Helfrich (University of Konstanz)
59+
*/
60+
@Plugin(type = Ops.Transform.RealTransform.class, priority = Priority.HIGH + 1)
61+
public class DefaultTransformView<T extends NumericType<T> & RealType<T>>
62+
extends
63+
AbstractUnaryFunctionOp<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>>
64+
implements Ops.Transform.RealTransform
65+
{
66+
67+
/**
68+
* The transform to apply
69+
*/
70+
@Parameter
71+
InvertibleRealTransform transform;
72+
73+
@Parameter(required = false)
74+
private Interval outputInterval = null;
75+
76+
@Parameter(required = false)
77+
private InterpolatorFactory<T, RandomAccessible<T>> interpolator = null;
78+
79+
@Parameter(required = false)
80+
private OutOfBoundsFactory<T, RandomAccessibleInterval<T>> outOfBoundsFactory =
81+
new OutOfBoundsMirrorFactory<>(OutOfBoundsMirrorFactory.Boundary.SINGLE);
82+
83+
@Override
84+
public RandomAccessibleInterval<T> calculate(
85+
final RandomAccessibleInterval<T> input)
86+
{
87+
88+
if (outputInterval == null) {
89+
outputInterval = new FinalInterval(input);
90+
}
91+
92+
if (interpolator == null) {
93+
interpolator = new LanczosInterpolatorFactory<>();
94+
}
95+
96+
final IntervalView<T> interval = Views.interval(Views.raster(RealViews
97+
.transformReal(Views.interpolate(Views.extendZero(input), interpolator),
98+
transform)), outputInterval);
99+
100+
return interval;
101+
}
102+
103+
}

src/main/templates/net/imagej/ops/Ops.list

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ namespaces = ```
448448
[name: "translateView", iface: "TranslateView"],
449449
[name: "unshearView", iface: "UnshearView"],
450450
[name: "zeroMinView", iface: "ZeroMinView"],
451+
[name: "realTransform", iface: "RealTransform"],
451452
]],
452453
[name: "zernike", iface: "Zernike", ops: [
453454
[name: "magnitude", iface: "Magnitude"],

0 commit comments

Comments
 (0)