Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Java
uses: actions/setup-java@v3
with:
java-version: '8'
java-version: '11'
distribution: 'zulu'
cache: 'maven'
- name: Set up CI environment
Expand Down
21 changes: 15 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ Jean-Yves Tinevez and Michael Zinsmaier.</license.copyrightOwners>

<!-- NB: Deploy releases to the SciJava Maven repository. -->
<releaseProfiles>sign,deploy-to-scijava</releaseProfiles>

<!--
NB: Older versions of OpenJDK 11 have a bug in the javadoc tool,
which causes errors like:

[ERROR] javadoc: error - The code being documented uses packages
in the unnamed module, but the packages defined in
https://github.com/scijava/scijava/apidocs/ are in named modules.

The most recent version of OpenJDK 11 known to have this problem
is 11.0.8; the oldest version known to have fixed it is 11.0.17.
Therefore, we set the minimum build JDK version to 11.0.17 here.
-->
<scijava.jvm.build.version>[11.0.17,)</scijava.jvm.build.version>
<scijava.jvm.version>11</scijava.jvm.version>
</properties>

<repositories>
Expand Down Expand Up @@ -192,12 +207,6 @@ Jean-Yves Tinevez and Michael Zinsmaier.</license.copyrightOwners>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.openjdk.jmh</groupId>
<artifactId>jmh-core</artifactId>
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module net.imglib2.imagej {
requires net.imglib2;
requires ij;
requires net.imglib2.cache;
requires java.desktop;
exports net.imglib2.imagej;
}
23 changes: 10 additions & 13 deletions src/test/java/net/imglib2/imagej/imageplus/ImagePlusImgTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

import net.imglib2.img.array.ArrayImgFactory;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.ImgTestHelper;
import net.imglib2.util.Util;

import org.junit.Test;
Expand All @@ -56,17 +55,15 @@ public class ImagePlusImgTest
public void testImagePlusImg()
{
final long[][] dim = ImgTestHelper.dims();
for ( int i = 0; i < dim.length; ++i )
{
if ( dim[ i ].length < 6 )
{
assertTrue( "ArrayImg vs ImagePlusImg failed for dim = " + Util.printCoordinates( dim[ i ] ),
ImgTestHelper.testImg( dim[ i ], new ArrayImgFactory<>( new FloatType() ), new ImagePlusImgFactory<>( new FloatType() ) ) );
assertTrue( "ImagePlusImg vs ArrayImg failed for dim = " + Util.printCoordinates( dim[ i ] ),
ImgTestHelper.testImg( dim[ i ], new ImagePlusImgFactory<>( new FloatType() ), new ArrayImgFactory<>( new FloatType() ) ) );
assertTrue( "ImagePlusImg vs ImagePlusImg failed for dim = " + Util.printCoordinates( dim[ i ] ),
ImgTestHelper.testImg( dim[ i ], new ImagePlusImgFactory<>( new FloatType() ), new ImagePlusImgFactory<>( new FloatType() ) ) );
}
}
for (long[] longs : dim) {
if (longs.length < 6) {
assertTrue("ArrayImg vs ImagePlusImg failed for dim = " + Util.printCoordinates(longs),
ImgTestHelper.testImg(longs, new ArrayImgFactory<>(new FloatType()), new ImagePlusImgFactory<>(new FloatType())));
assertTrue("ImagePlusImg vs ArrayImg failed for dim = " + Util.printCoordinates(longs),
ImgTestHelper.testImg(longs, new ImagePlusImgFactory<>(new FloatType()), new ArrayImgFactory<>(new FloatType())));
assertTrue("ImagePlusImg vs ImagePlusImg failed for dim = " + Util.printCoordinates(longs),
ImgTestHelper.testImg(longs, new ImagePlusImgFactory<>(new FloatType()), new ImagePlusImgFactory<>(new FloatType())));
}
}
}
}
189 changes: 189 additions & 0 deletions src/test/java/net/imglib2/imagej/imageplus/ImgTestHelper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
package net.imglib2.imagej.imageplus;

import net.imglib2.Cursor;
import net.imglib2.RandomAccess;
import net.imglib2.img.Img;
import net.imglib2.img.ImgFactory;
import net.imglib2.outofbounds.OutOfBoundsPeriodicFactory;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Util;
import net.imglib2.view.ExtendedRandomAccessibleInterval;

import java.util.Random;

/**
* For of imglib2's {@code ImgTestHelper} for testing {@link Img} subclasses
*
* @author Stephan Preibisch
* @author Stephan Saalfeld
* @author Curtis Rueden
* @author Philipp Hanslovsky
* @author Gabriel Selzer
*/
public class ImgTestHelper
{
// which dimensions to test
private static final long[][] DIM =
new long[][] {
{ 127 },
{ 288 },
{ 135, 111 },
{ 172, 131 },
{ 15, 13, 33 },
{ 110, 38, 30 },
{ 109, 34, 111 },
{ 12, 43, 92, 10 },
{ 21, 34, 29, 13 },
{ 5, 12, 30, 4, 21 },
{ 14, 21, 13, 9, 12 }
};

public static long[][] dims()
{
return DIM.clone();
}

public static boolean testImg( final long[] size, final ImgFactory< FloatType > factory1, final ImgFactory< FloatType > factory2 )
{
// create the image
final Img< FloatType > img1 = factory1.create( size );
final Img< FloatType > img2 = factory2.create( size );

final int numDimensions = img1.numDimensions();

// get a reference to compare to
final float[] reference = createReference( img1 );

// copy into a second image using simple cursors
final Cursor< FloatType > cursor1 = img1.cursor();
final Cursor< FloatType > cursor2 = img2.cursor();

while ( cursor1.hasNext() )
{
cursor1.fwd();
cursor2.fwd();

cursor2.get().set( cursor1.get() );
}

cursor1.reset();
cursor2.reset();

// and copy right back
while ( cursor2.hasNext() )
{
cursor1.fwd();
cursor2.fwd();

cursor1.get().set( cursor2.get() );
}

// copy back into a second image using localizable and positionable
// cursors
final Cursor< FloatType > localizableCursor1 = img1.localizingCursor();
final RandomAccess< FloatType > positionable2 = img2.randomAccess();

int i = 0;

while ( localizableCursor1.hasNext() )
{
localizableCursor1.fwd();
++i;

if ( i % 2 == 0 )
positionable2.setPosition( localizableCursor1 );
else
positionable2.setPosition( localizableCursor1 );

final FloatType t2 = positionable2.get();
final FloatType t1 = localizableCursor1.get();
t2.set( t1 );
}

// copy again to the first image using a LocalizableByDimOutsideCursor
// and a LocalizableByDimCursor
final ExtendedRandomAccessibleInterval< FloatType, Img< FloatType > > extendedImg2 = new ExtendedRandomAccessibleInterval<>( img2, new OutOfBoundsPeriodicFactory<>() );
final RandomAccess< FloatType > outsideCursor2 = extendedImg2.randomAccess();
localizableCursor1.reset();

final int[] pos = new int[ numDimensions ];
i = 0;
int direction = 1;

try
{
while ( localizableCursor1.hasNext() )
{
localizableCursor1.fwd();
localizableCursor1.localize( pos );
++i;

// how many times far away from the original image do we grab
// the pixel
final int distance = i % 5;
direction *= -1;

pos[ i % numDimensions ] += (int) (img1.dimension( i % numDimensions ) * distance * direction);

if ( i % 7 == 0 )
outsideCursor2.setPosition( pos );
else
outsideCursor2.setPosition( pos );

final FloatType t1 = localizableCursor1.get();
final FloatType t2 = outsideCursor2.get();

t1.set( t2 );

}
}
catch ( final ArrayIndexOutOfBoundsException e )
{
System.err.println( ( i % 7 == 0 ? "setPosition() " : "moveTo() " ) + Util.printCoordinates( pos ) );
e.printStackTrace();
System.exit( 1 );
}

return test( img1, reference );
}

private static float[] createReference( final Img< FloatType > img )
{
// use a random number generator
final Random rnd = new Random( 1241234 );

// create reference array
final float[] reference = new float[ ( int ) img.size() ];

// iterate over image and reference array and fill with data
final Cursor< FloatType > cursor = img.cursor();
int i = 0;

while ( cursor.hasNext() )
{
cursor.fwd();

final float value = rnd.nextFloat();
reference[ i++ ] = value;
cursor.get().set( value );
}

return reference;
}

private static boolean test( final Img< FloatType > img, final float[] reference )
{
boolean allEqual = true;

final Cursor< FloatType > cursor = img.cursor();
int i = 0;

while ( cursor.hasNext() )
{
cursor.fwd();
allEqual &= cursor.get().get() == reference[ i++ ];
}

return allEqual;
}
}