-
Notifications
You must be signed in to change notification settings - Fork 42
Real transform #533
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bnorthan
wants to merge
6
commits into
master
Choose a base branch
from
real_transform
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Real transform #533
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9185384
Autoformat
bnorthan b882573
Add transform interface and default op
bnorthan adb01b8
Add transform test
bnorthan fec3621
Use RealTransform to match ops
bnorthan 58825ba
Remove extraneous code
bnorthan 24454d5
Make sure test calls DefaultTransformView
bnorthan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/net/imagej/ops/transform/realTransform/DefaultTransformView.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
src/test/java/net/imagej/ops/transform/realTransform/RealTransformTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 added
BIN
+64.1 KB
src/test/resources/net/imagej/ops/transform/realTransform/lowresbridge.tif
Binary file not shown.
Binary file added
BIN
+64.1 KB
src/test/resources/net/imagej/ops/transform/realTransform/rotatedscaledcenter.tif
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.