Skip to content

Commit a1f9c48

Browse files
committed
ImgMath: Compute.intoArrayImg properly returns an ArrayImg
rather than a RandomAccessibleInterval.
1 parent 77cbc08 commit a1f9c48

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/main/java/net/imglib2/algorithm/math/Compute.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,18 @@ public Compute( final IFunction operation )
5555
this.params = Compute.validate( this.operation );
5656
}
5757

58-
public < O extends RealType< O > & NativeType< O > > RandomAccessibleInterval< O >
58+
public < O extends RealType< O > & NativeType< O > > ArrayImg< O, ? >
5959
intoArrayImg()
6060
{
6161
@SuppressWarnings("unchecked")
6262
final RandomAccessibleInterval< O > rai = ( RandomAccessibleInterval< O > )Util.findImg( operation ).iterator().next();
6363
final ArrayImg< O, ? > target = new ArrayImgFactory< O >( rai.randomAccess().get().createVariable() ).create( rai );
6464
this.params.compatible_iteration_order = Util.compatibleIterationOrder( Arrays.asList( rai, target ) );
65-
return this.into( target );
65+
this.into( target );
66+
return target;
6667
}
6768

68-
public < O extends RealType< O > & NativeType< O >, C extends RealType< C > & NativeType< C > > RandomAccessibleInterval< O >
69+
public < O extends RealType< O > & NativeType< O >, C extends RealType< C > & NativeType< C > > ArrayImg< O, ? >
6970
intoArrayImg( final C computeType, final O outputType )
7071
{
7172
final Set< RandomAccessibleInterval< ? > > imgs = Util.findImg( operation );
@@ -84,10 +85,11 @@ public Compute( final IFunction operation )
8485
final ArrayImg< O, ? > target = new ArrayImgFactory< O >( outputType ).create( interval );
8586
ls.add( target );
8687
this.params.compatible_iteration_order = Util.compatibleIterationOrder( ls );
87-
return this.into( target, null, computeType, null );
88+
this.into( target, null, computeType, null );
89+
return target;
8890
}
8991

90-
public < O extends RealType< O > & NativeType< O >, C extends RealType< C > > RandomAccessibleInterval< O >
92+
public < O extends RealType< O > & NativeType< O >, C extends RealType< C > > ArrayImg< O, ? >
9193
intoArrayImg( final O outputType )
9294
{
9395
return intoArrayImg( outputType.createVariable(), outputType );

src/test/java/net/imglib2/algorithm/math/ImgMathTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -811,7 +811,6 @@ static private final < T extends RealType< T > > boolean same( final Img< T > im
811811
return true;
812812
}
813813

814-
@SuppressWarnings("unchecked")
815814
@Test
816815
public void test10Logical() {
817816
System.out.println("test10Logical");
@@ -842,18 +841,18 @@ public void test10Logical() {
842841
img4 = into4x4Img( pixels4 );
843842

844843
// AND
845-
assertTrue( same( img1, ( Img< UnsignedByteType > )compute(AND(img1, img2)).intoArrayImg() ) );
844+
assertTrue( same( img1, compute(AND(img1, img2)).intoArrayImg( new UnsignedByteType() ) ) );
846845
// OR
847-
assertTrue( same( img2, ( Img< UnsignedByteType > )compute(OR(img1, img2)).intoArrayImg() ) );
846+
assertTrue( same( img2, compute(OR(img1, img2)).intoArrayImg( new UnsignedByteType() ) ) );
848847
// XOR
849-
assertTrue( same( img3, ( Img< UnsignedByteType > )compute(XOR(img1, img2)).intoArrayImg() ) );
848+
assertTrue( same( img3, compute(XOR(img1, img2)).intoArrayImg( new UnsignedByteType() ) ) );
850849
// NOT
851-
assertTrue( same( img4, ( Img< UnsignedByteType > )compute(NOT(img1)).intoArrayImg() ) );
850+
assertTrue( same( img4, compute(NOT(img1)).intoArrayImg( new UnsignedByteType() ) ) );
852851

853852
// Test LogicalAndBoolean
854853
final Img< UnsignedByteType> imgIFAND = ( Img< UnsignedByteType> )compute(IF(AND(LT(img1, 1), LT(img2, 1)),
855854
THEN(1),
856-
ELSE(0))).intoArrayImg();
855+
ELSE(0))).intoArrayImg( new UnsignedByteType() );
857856

858857
final byte[] pixels5 = new byte[ pixels1.length ];
859858
for ( int i = 0; i < pixels1.length; ++i )

0 commit comments

Comments
 (0)