Skip to content

Commit f1fa478

Browse files
authored
Merge pull request #77 from scijava/imagej/imagej-ops2/copy-op-revamp
Ensure CopyII, CopyRAI match 'copy.img' alias
2 parents e855522 + 31cb3f5 commit f1fa478

File tree

8 files changed

+249
-116
lines changed

8 files changed

+249
-116
lines changed

imagej/imagej-ops2/src/main/java/net/imagej/ops2/copy/CopyII.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*
4545
* @author Christian Dietz (University of Konstanz)
4646
* @param <T>
47-
* @implNote op names='copy, copy.iterableInterval', priority='1.0'
47+
* @implNote op names='copy, copy.iterableInterval, copy.img', priority='1.0'
4848
*/
4949
public class CopyII<T> implements Computers.Arity1<IterableInterval<T>, IterableInterval<T>> {
5050

imagej/imagej-ops2/src/main/java/net/imagej/ops2/copy/CopyRAI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
*
4343
* @author Christian Dietz (University of Konstanz)
4444
* @param <T>
45-
* @implNote op names='copy, copy.rai', priority='1.0'
45+
* @implNote op names='copy, copy.rai, copy.img', priority='10.0'
4646
*/
4747
public class CopyRAI<T> implements Computers.Arity1<RandomAccessibleInterval<T>, RandomAccessibleInterval<T>> {
4848

imagej/imagej-ops2/src/test/java/net/imagej/ops2/OpRegressionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public class OpRegressionTest extends AbstractOpTest {
3939

4040
@Test
4141
public void opDiscoveryRegressionIT() {
42-
long expected = 1444;
42+
long expected = 1457;
4343
long actual = StreamSupport.stream(ops.infos().spliterator(), false).count();
4444
assertEquals(expected, actual);
4545
}

imagej/imagej-ops2/src/test/java/net/imagej/ops2/copy/CopyArrayImgTest.java

Lines changed: 0 additions & 98 deletions
This file was deleted.
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/*
2+
* #%L
3+
* ImageJ2 software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2022 ImageJ2 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+
package net.imagej.ops2.copy;
30+
31+
import static org.junit.jupiter.api.Assertions.assertEquals;
32+
33+
import org.junit.jupiter.api.Test;
34+
import org.scijava.util.MersenneTwisterFast;
35+
36+
import net.imagej.ops2.AbstractOpTest;
37+
import net.imglib2.Cursor;
38+
import net.imglib2.RandomAccess;
39+
import net.imglib2.RandomAccessibleInterval;
40+
import net.imglib2.img.Img;
41+
import net.imglib2.img.array.ArrayImgFactory;
42+
import net.imglib2.img.cell.CellImgFactory;
43+
import net.imglib2.img.planar.PlanarImgFactory;
44+
import net.imglib2.type.numeric.RealType;
45+
import net.imglib2.type.numeric.integer.UnsignedByteType;
46+
47+
/**
48+
* Test copying of various Image types
49+
*
50+
* @author Christian Dietz (University of Konstanz)
51+
*/
52+
public class CopyImgsTest extends AbstractOpTest {
53+
54+
private <T extends RealType<T>> void populateData(Img<T> data) {
55+
final MersenneTwisterFast r = new MersenneTwisterFast(System.currentTimeMillis());
56+
final Cursor<T> inc = data.cursor();
57+
while (inc.hasNext()) {
58+
inc.next().setReal(r.nextDouble() * 255);
59+
}
60+
}
61+
62+
@Test
63+
public void copyArrayImgNoOutputTest() {
64+
var data = new ArrayImgFactory<>(new UnsignedByteType()).create(10, 10);
65+
populateData(data);
66+
@SuppressWarnings("unchecked")
67+
final RandomAccessibleInterval<UnsignedByteType> output =
68+
(RandomAccessibleInterval<UnsignedByteType>) ops.op("copy.img").arity1().input(
69+
data).apply();
70+
71+
final Cursor<UnsignedByteType> inc = data.localizingCursor();
72+
final RandomAccess<UnsignedByteType> outRA = output.randomAccess();
73+
74+
while (inc.hasNext()) {
75+
inc.fwd();
76+
outRA.setPosition(inc);
77+
assertEquals(inc.get().get(), outRA.get().get());
78+
}
79+
}
80+
81+
@Test
82+
public void copyArrayImgWithOutputTest() {
83+
var data = new ArrayImgFactory<>(new UnsignedByteType()).create(10, 10);
84+
populateData(data);
85+
final Img<UnsignedByteType> output = data.factory().create(data.dimensionsAsLongArray());
86+
87+
ops.op("copy.img").arity1().input(data).output(output).compute();
88+
89+
final Cursor<UnsignedByteType> inc = data.cursor();
90+
final Cursor<UnsignedByteType> outc = output.cursor();
91+
92+
while (inc.hasNext()) {
93+
assertEquals(outc.next(), inc.next());
94+
}
95+
}
96+
97+
@Test
98+
public void copyPlanarImgNoOutputTest() {
99+
var data = new PlanarImgFactory<>(new UnsignedByteType()).create(10, 10);
100+
populateData(data);
101+
@SuppressWarnings("unchecked")
102+
final RandomAccessibleInterval<UnsignedByteType> output =
103+
(RandomAccessibleInterval<UnsignedByteType>) ops.op("copy.img").arity1().input(
104+
data).apply();
105+
106+
final Cursor<UnsignedByteType> inc = data.localizingCursor();
107+
final RandomAccess<UnsignedByteType> outRA = output.randomAccess();
108+
109+
while (inc.hasNext()) {
110+
inc.fwd();
111+
outRA.setPosition(inc);
112+
assertEquals(inc.get().get(), outRA.get().get());
113+
}
114+
}
115+
116+
@Test
117+
public void copyPlanarImgWithOutputTest() {
118+
var data = new PlanarImgFactory<>(new UnsignedByteType()).create(10, 10);
119+
populateData(data);
120+
final Img<UnsignedByteType> output = data.factory().create(data.dimensionsAsLongArray());
121+
122+
ops.op("copy.img").arity1().input(data).output(output).compute();
123+
124+
final Cursor<UnsignedByteType> inc = data.cursor();
125+
final Cursor<UnsignedByteType> outc = output.cursor();
126+
127+
while (inc.hasNext()) {
128+
assertEquals(outc.next(), inc.next());
129+
}
130+
}
131+
132+
@Test
133+
public void copyCellImgNoOutputTest() {
134+
var data = new CellImgFactory<>(new UnsignedByteType()).create(10, 10);
135+
populateData(data);
136+
@SuppressWarnings("unchecked")
137+
final RandomAccessibleInterval<UnsignedByteType> output =
138+
(RandomAccessibleInterval<UnsignedByteType>) ops.op("copy.img").arity1().input(
139+
data).apply();
140+
141+
final Cursor<UnsignedByteType> inc = data.localizingCursor();
142+
final RandomAccess<UnsignedByteType> outRA = output.randomAccess();
143+
144+
while (inc.hasNext()) {
145+
inc.fwd();
146+
outRA.setPosition(inc);
147+
assertEquals(inc.get().get(), outRA.get().get());
148+
}
149+
}
150+
151+
@Test
152+
public void copyCellImgWithOutputTest() {
153+
var data = new CellImgFactory<>(new UnsignedByteType()).create(10, 10);
154+
populateData(data);
155+
final Img<UnsignedByteType> output = data.factory().create(data.dimensionsAsLongArray());
156+
157+
ops.op("copy.img").arity1().input(data).output(output).compute();
158+
159+
final Cursor<UnsignedByteType> inc = data.cursor();
160+
final Cursor<UnsignedByteType> outc = output.cursor();
161+
162+
while (inc.hasNext()) {
163+
assertEquals(outc.next(), inc.next());
164+
}
165+
}
166+
}

0 commit comments

Comments
 (0)