|
| 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.ops2.transform.realTransform; |
| 31 | + |
| 32 | +import net.imglib2.FinalInterval; |
| 33 | +import net.imglib2.Interval; |
| 34 | +import net.imglib2.RandomAccessible; |
| 35 | +import net.imglib2.RandomAccessibleInterval; |
| 36 | +import net.imglib2.interpolation.InterpolatorFactory; |
| 37 | +import net.imglib2.interpolation.randomaccess.LanczosInterpolatorFactory; |
| 38 | +import net.imglib2.realtransform.InvertibleRealTransform; |
| 39 | +import net.imglib2.realtransform.RealViews; |
| 40 | +import net.imglib2.type.numeric.NumericType; |
| 41 | +import net.imglib2.type.numeric.RealType; |
| 42 | +import net.imglib2.view.IntervalView; |
| 43 | +import net.imglib2.view.Views; |
| 44 | + |
| 45 | +import org.scijava.Priority; |
| 46 | +import org.scijava.ops.core.Op; |
| 47 | +import org.scijava.ops.function.Functions; |
| 48 | +import org.scijava.param.Parameter; |
| 49 | +import org.scijava.plugin.Plugin; |
| 50 | +import org.scijava.struct.ItemIO; |
| 51 | + |
| 52 | +/** |
| 53 | + * Applies an Affine transform to a {@link RandomAccessibleInterval} |
| 54 | + * |
| 55 | + * @author Brian Northan (True North Intelligent Algorithms) |
| 56 | + * @author Martin Horn (University of Konstanz) |
| 57 | + * @author Stefan Helfrich (University of Konstanz) |
| 58 | + */ |
| 59 | +@Plugin(type = Op.class, name = "transform.realTransform", |
| 60 | + priority = Priority.HIGH + 1) |
| 61 | +@Parameter(key = "input") |
| 62 | +@Parameter(key = "transform") |
| 63 | +@Parameter(key = "outputInterval") |
| 64 | +@Parameter(key = "interpolator") |
| 65 | +@Parameter(key = "output", itemIO = ItemIO.OUTPUT) |
| 66 | +public class DefaultTransformView<T extends NumericType<T> & RealType<T>> |
| 67 | + implements |
| 68 | + Functions.Arity4<RandomAccessibleInterval<T>, InvertibleRealTransform, Interval, InterpolatorFactory<T, RandomAccessible<T>>, RandomAccessibleInterval<T>> |
| 69 | +{ |
| 70 | + |
| 71 | + /** |
| 72 | + * TODO: declare {@code outputInterval}, {@code interpolator} as optional once |
| 73 | + * <a href=https://github.com/scijava/incubator/pull/32>this issue</a> has |
| 74 | + * been resolved. Until then, this op <b>must</b> be called as a |
| 75 | + * {@link org.scijava.ops.function.Functions.Arity4} |
| 76 | + * |
| 77 | + * @param input the input |
| 78 | + * @param transform the transform to apply |
| 79 | + * @param outputInterval the output interval |
| 80 | + * @param interpolator the {@link InterpolatorFactory} delegated to for |
| 81 | + * interpolation |
| 82 | + * @return the output |
| 83 | + */ |
| 84 | + @Override |
| 85 | + public RandomAccessibleInterval<T> apply(RandomAccessibleInterval<T> input, |
| 86 | + InvertibleRealTransform transform, Interval outputInterval, |
| 87 | + InterpolatorFactory<T, RandomAccessible<T>> interpolator) |
| 88 | + { |
| 89 | + if (outputInterval == null) { |
| 90 | + outputInterval = new FinalInterval(input); |
| 91 | + } |
| 92 | + |
| 93 | + if (interpolator == null) { |
| 94 | + interpolator = new LanczosInterpolatorFactory<>(); |
| 95 | + } |
| 96 | + |
| 97 | + final IntervalView<T> interval = Views.interval(Views.raster(RealViews |
| 98 | + .transformReal(Views.interpolate(Views.extendZero(input), interpolator), |
| 99 | + transform)), outputInterval); |
| 100 | + |
| 101 | + return interval; |
| 102 | + } |
| 103 | + |
| 104 | +} |
0 commit comments