Skip to content

Commit

Permalink
Update to imglib2 5.1.0
Browse files Browse the repository at this point in the history
Eliminate deprecated ImgFactory usages. Clean up the code.
  • Loading branch information
ctrueden committed Apr 30, 2018
1 parent 58aa4d8 commit 4627adc
Show file tree
Hide file tree
Showing 43 changed files with 281 additions and 286 deletions.
5 changes: 1 addition & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>net.imglib2</groupId>
<artifactId>pom-imglib2</artifactId>
<version>9.0.0</version>
<version>11.0.0</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -88,20 +88,17 @@ Jean-Yves Tinevez and Michael Zinsmaier.</license.copyrightOwners>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2</artifactId>
<version>4.4.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-algorithm</artifactId>
<version>0.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
<artifactId>imglib2-algorithm-gpl</artifactId>
<scope>test</scope>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>net.imglib2</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
package net.imglib2.algorithm;

import ij.ImageJ;

import io.scif.img.IO;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;

import java.io.File;

Expand All @@ -39,8 +40,6 @@
import net.imglib2.RandomAccess;
import net.imglib2.exception.IncompatibleTypeException;
import net.imglib2.img.Img;
import net.imglib2.img.ImgFactory;
import net.imglib2.img.array.ArrayImgFactory;
import net.imglib2.img.display.imagej.ImageJFunctions;
import net.imglib2.outofbounds.OutOfBounds;
import net.imglib2.type.NativeType;
Expand Down Expand Up @@ -73,7 +72,7 @@ public static enum IterationMethod {
public TestRelativeIterationPerformance(final Img<T> input) {
this.input = input;
try {
output = input.factory().imgFactory(new FloatType()).create( input, new FloatType() );
output = input.factory().imgFactory( new FloatType() ).create( input );
} catch (final IncompatibleTypeException e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -454,7 +453,7 @@ public long getProcessingTime() {
public static <T extends RealType<T> & NativeType< T >> void benchmark( final IterationMethod method, final String msg, final int niter, final Img< T > image )
{
// Init algo
final TestRelativeIterationPerformance<T> algo = new TestRelativeIterationPerformance<T>(image);
final TestRelativeIterationPerformance<T> algo = new TestRelativeIterationPerformance<>(image);

algo.method = method;

Expand Down Expand Up @@ -483,8 +482,7 @@ public static <T extends RealType<T> & NativeType< T >> void main(final String[
final int niter = 1000;

// Open file in imglib2
final ImgFactory< ? > imgFactory = new ArrayImgFactory< T >();
final Img< T > image = (Img< T >) new ImgOpener().openImg( file.getAbsolutePath(), imgFactory );
final Img< T > image = ( Img< T > ) IO.openImgs( file.getAbsolutePath() ).get( 0 );

// Display it via ImgLib using ImageJ
new ImageJ();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ public static void print( PixelListComponentTree< IntType > tree )

public static void main( String[] args )
{
ImgFactory< IntType > imgFactory = new ArrayImgFactory< IntType >();
Img< IntType > input = imgFactory.create( dimensions, new IntType() );
ImgFactory< IntType > imgFactory = new ArrayImgFactory<>( new IntType() );
Img< IntType > input = imgFactory.create( dimensions );

// fill input image with test data
int[] pos = new int[ 2 ];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
import ij.ImagePlus;
import ij.gui.Line;
import ij.gui.Overlay;

import io.scif.img.IO;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;

import java.awt.Color;
import java.util.ArrayList;
Expand All @@ -50,10 +51,10 @@ final static public void main( final String[] args ) throws ImgIOException
{
new ImageJ();

final ImgFactory< FloatType > imgFactory = new ArrayImgFactory< FloatType >();
final ImgFactory< FloatType > imgFactory = new ArrayImgFactory<>( new FloatType() );

// load image
final Img< FloatType > img = new ImgOpener().openImg( "/home/tobias/workspace/HisYFP/blob.tif", imgFactory, new FloatType() );
final Img< FloatType > img = IO.openImgs( "/home/tobias/workspace/HisYFP/blob.tif", imgFactory ).get( 0 );

// detect edgels
final ArrayList< Edgel > edgels = SubpixelEdgelDetection.getEdgels( img, imgFactory, 2 );
Expand Down
77 changes: 37 additions & 40 deletions src/test/java/net/imglib2/algorithm/gauss3/Gauss3Benchmark.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,20 @@ public static void main( final String[] args ) throws ImgIOException

public static < T > void convolve(
final double[] sigmas, final RandomAccessible< T > source, final RandomAccessibleInterval< T > target,
final ConvolverFactory< T, T > convf, final ImgFactory< T > imgf, final T type )
final ConvolverFactory< T, T > convf, final ImgFactory< T > imgf )
{
final double[][] halfkernels = Gauss3.halfkernels( sigmas );
final int numthreads = Runtime.getRuntime().availableProcessors();
final ExecutorService service = Executors.newFixedThreadPool( numthreads );
SeparableSymmetricConvolution.convolve( halfkernels, source, target, convf, convf,convf, convf, imgf, type, service );
SeparableSymmetricConvolution.convolve( halfkernels, source, target, convf, convf,convf, convf, imgf, service );
service.shutdown();
}

public static void benchmarkFloat( final long[] dimensions, final double sigma, final boolean printIndividualTimes, final int numRuns) throws ImgIOException
{
final FloatType type = new FloatType();
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory< FloatType >();
final Img< FloatType > img = factory.create( dimensions, type );
final Img< FloatType > convolved = factory.create( dimensions, type );
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory<>( new FloatType() );
final Img< FloatType > img = factory.create( dimensions );
final Img< FloatType > convolved = factory.create( dimensions );
fillRandom( img );

final int n = img.numDimensions();
Expand Down Expand Up @@ -140,7 +139,7 @@ public void run()
@Override
public void run()
{
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, FloatConvolverRealTypeBuffered.< FloatType, FloatType >factory(), factory, type );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, FloatConvolverRealTypeBuffered.< FloatType, FloatType >factory(), factory );
}
} );

Expand All @@ -149,17 +148,17 @@ public void run()
@Override
public void run()
{
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, FloatConvolverRealType.< FloatType, FloatType >factory(), factory, type );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, FloatConvolverRealType.< FloatType, FloatType >factory(), factory );
}
} );
}

public static void benchmarkNative( final long[] dimensions, final double sigma, final boolean printIndividualTimes, final int numRuns) throws ImgIOException
{
final FloatType type = new FloatType();
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory< FloatType >();
final Img< FloatType > img = factory.create( dimensions, type );
final Img< FloatType > convolved = factory.create( dimensions, type );
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory<>( type );
final Img< FloatType > img = factory.create( dimensions );
final Img< FloatType > convolved = factory.create( dimensions );
fillRandom( img );

final int n = img.numDimensions();
Expand All @@ -183,7 +182,7 @@ public void run()
@Override
public void run()
{
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, ConvolverNativeTypeBuffered.factory( type ), factory, type );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, ConvolverNativeTypeBuffered.factory( type ), factory );
}
} );

Expand All @@ -192,17 +191,17 @@ public void run()
@Override
public void run()
{
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, ConvolverNativeType.factory( type ), factory, type );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, ConvolverNativeType.factory( type ), factory );
}
} );
}

public static void benchmarkGeneric( final long[] dimensions, final double sigma, final boolean printIndividualTimes, final int numRuns) throws ImgIOException
{
final FloatType type = new FloatType();
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory< FloatType >();
final Img< FloatType > img = factory.create( dimensions, type );
final Img< FloatType > convolved = factory.create( dimensions, type );
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory<>( type );
final Img< FloatType > img = factory.create( dimensions );
final Img< FloatType > convolved = factory.create( dimensions );
fillRandom( img );

final int n = img.numDimensions();
Expand All @@ -226,7 +225,7 @@ public void run()
@Override
public void run()
{
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, ConvolverNumericType.factory( type ), factory, type );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved, ConvolverNumericType.factory( type ), factory );
}
} );
}
Expand All @@ -241,8 +240,8 @@ static void fillRandom( final Img< FloatType > img )
public static void visualise( final long[] dimensions, final double sigma ) throws ImgIOException
{
final FloatType type = new FloatType();
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory< FloatType >();
final Img< FloatType > img = factory.create( dimensions, type );
final ArrayImgFactory< FloatType > factory = new ArrayImgFactory<>( type );
final Img< FloatType > img = factory.create( dimensions );
fillRandom( img );
ImageJFunctions.show( img, "source image" );

Expand All @@ -260,28 +259,28 @@ public static void visualise( final long[] dimensions, final double sigma ) thro

final Point min = new Point( n );
img.min( min );
final Img< FloatType > convolved2 = factory.create( img, new FloatType() );
final Img< FloatType > convolved2 = factory.create( img );
new GaussFloat( sigmas, Views.extendMirrorSingle( img ), img, convolved2, min, factory ).call();
ImageJFunctions.show( convolved2, "GaussFloat" );

final Img< FloatType > convolved5 = factory.create( img, new FloatType() );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved5, ConvolverNumericType.factory( type ), factory, type );
final Img< FloatType > convolved5 = factory.create( img );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved5, ConvolverNumericType.factory( type ), factory );
ImageJFunctions.show( convolved5, "SeparableSymmetricConvolution with ConvolverNumericType" );

final Img< FloatType > convolved4 = factory.create( img, new FloatType() );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved4, ConvolverNativeType.factory( type ), factory, type );
final Img< FloatType > convolved4 = factory.create( img );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved4, ConvolverNativeType.factory( type ), factory );
ImageJFunctions.show( convolved4, "SeparableSymmetricConvolution with ConvolverNativeType" );

final Img< FloatType > convolved6 = factory.create( img, new FloatType() );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved6, ConvolverNativeTypeBuffered.factory( type ), factory, type );
final Img< FloatType > convolved6 = factory.create( img );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved6, ConvolverNativeTypeBuffered.factory( type ), factory );
ImageJFunctions.show( convolved6, "SeparableSymmetricConvolution with ConvolverNativeTypeBuffered" );

final Img< FloatType > convolved7 = factory.create( img, new FloatType() );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved7, FloatConvolverRealType.< FloatType, FloatType >factory(), factory, type );
final Img< FloatType > convolved7 = factory.create( img );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved7, FloatConvolverRealType.< FloatType, FloatType >factory(), factory );
ImageJFunctions.show( convolved7, "SeparableSymmetricConvolution with" );

final Img< FloatType > convolved3 = factory.create( img, new FloatType() );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved3, FloatConvolverRealTypeBuffered.< FloatType, FloatType >factory(), factory, type );
final Img< FloatType > convolved3 = factory.create( img );
convolve( sigmas, Views.extendMirrorSingle( img ), convolved3, FloatConvolverRealTypeBuffered.< FloatType, FloatType >factory(), factory );
ImageJFunctions.show( convolved3, "SeparableSymmetricConvolution with FloatConvolverRealTypeBuffered" );
}

Expand All @@ -294,32 +293,30 @@ static void fillRandomUnsignedByte( final Img< UnsignedByteType > img )

public static void benchmarkInFloat( final long[] dimensions, final double sigma, final boolean printIndividualTimes, final int numRuns) throws ImgIOException
{
final UnsignedByteType unsignedByteType = new UnsignedByteType();
final ArrayImgFactory< UnsignedByteType > factory = new ArrayImgFactory< UnsignedByteType >();
final Img< UnsignedByteType > img = factory.create( dimensions, unsignedByteType );
final Img< UnsignedByteType > convolved = factory.create( dimensions, unsignedByteType );
final ArrayImgFactory< UnsignedByteType > factory = new ArrayImgFactory<>( new UnsignedByteType() );
final Img< UnsignedByteType > img = factory.create( dimensions );
final Img< UnsignedByteType > convolved = factory.create( dimensions );
fillRandomUnsignedByte( img );

final int n = img.numDimensions();
final double[] sigmas = new double[ n ];
for ( int d = 0; d < n; ++d )
sigmas[ d ] = sigma;

final FloatType floatType = new FloatType();
final ArrayImgFactory< FloatType > floatFactory = new ArrayImgFactory< FloatType >();
final ArrayImgFactory< FloatType > floatFactory = new ArrayImgFactory<>( new FloatType() );

System.out.println( "convolve UnsignedByteType using Converters on source and target" );
BenchmarkHelper.benchmarkAndPrint( numRuns, printIndividualTimes, new Runnable() {
@Override
public void run()
{
final ConvolverFactory< FloatType, FloatType > cff = FloatConvolverRealTypeBuffered.< FloatType, FloatType >factory();
final RandomAccessibleInterval< FloatType > rIn = new WriteConvertedRandomAccessibleInterval< UnsignedByteType, FloatType >( img, new RealFloatSamplerConverter< UnsignedByteType >() );
final RandomAccessibleInterval< FloatType > rOut = new WriteConvertedRandomAccessibleInterval< UnsignedByteType, FloatType >( convolved, new RealFloatSamplerConverter< UnsignedByteType >() );
final RandomAccessibleInterval< FloatType > rIn = new WriteConvertedRandomAccessibleInterval<>( img, new RealFloatSamplerConverter< UnsignedByteType >() );
final RandomAccessibleInterval< FloatType > rOut = new WriteConvertedRandomAccessibleInterval<>( convolved, new RealFloatSamplerConverter< UnsignedByteType >() );
final double[][] halfkernels = Gauss3.halfkernels( sigmas );
final int numthreads = Runtime.getRuntime().availableProcessors();
final ExecutorService service = Executors.newFixedThreadPool( numthreads );
SeparableSymmetricConvolution.convolve( halfkernels, Views.extendMirrorSingle( rIn ), rOut, cff, cff, cff, cff, floatFactory, floatType, service );
SeparableSymmetricConvolution.convolve( halfkernels, Views.extendMirrorSingle( rIn ), rOut, cff, cff, cff, cff, floatFactory, service );
service.shutdown();
}
} );
Expand All @@ -336,7 +333,7 @@ public void run()
final double[][] halfkernels = Gauss3.halfkernels( sigmas );
final int numthreads = Runtime.getRuntime().availableProcessors();
final ExecutorService service = Executors.newFixedThreadPool( numthreads );
SeparableSymmetricConvolution.convolve( halfkernels, Views.extendMirrorSingle( img ), convolved, cif, cff, cfi, cii, floatFactory, floatType, service );
SeparableSymmetricConvolution.convolve( halfkernels, Views.extendMirrorSingle( img ), convolved, cif, cff, cfi, cii, floatFactory, service );
service.shutdown();
}
} );
Expand Down
5 changes: 3 additions & 2 deletions src/test/java/net/imglib2/algorithm/gauss3/Gauss3Example.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

package net.imglib2.algorithm.gauss3;

import io.scif.img.IO;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;

import net.imglib2.exception.IncompatibleTypeException;
import net.imglib2.img.Img;
import net.imglib2.img.array.ArrayImgFactory;
Expand All @@ -47,7 +48,7 @@ public class Gauss3Example
public static void main( final String[] args ) throws ImgIOException
{
final String fn = "/home/tobias/workspace/data/DrosophilaWing.tif";
final Img< FloatType > img = new ImgOpener().openImg( fn, new ArrayImgFactory< FloatType >(), new FloatType() );
final Img< FloatType > img = IO.openImgs( fn, new ArrayImgFactory<>( new FloatType() ) ).get( 0 );

final long[] dims = new long[ img.numDimensions() ];
img.dimensions( dims );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@

package net.imglib2.algorithm.gradient;

import io.scif.img.IO;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;

import net.imagej.ImgPlus;
import net.imglib2.Interval;
import net.imglib2.img.Img;
Expand All @@ -44,15 +45,15 @@ public class GradientExample
{
public static < T extends RealType< T > & NativeType< T > > void doit( final T type ) throws ImgIOException
{
final ImgPlus< T > input = new ImgOpener().openImg( "/home/tobias/workspace/data/img1.tif", new ArrayImgFactory< T >(), type );
final ImgPlus< T > input = IO.openImgs( "/home/tobias/workspace/data/img1.tif", new ArrayImgFactory<>( type ) ).get( 0 );
ImageJFunctions.show( input );

final int n = input.numDimensions();
final long[] dim = new long[ n + 1 ];
for ( int d = 0; d < n; ++d )
dim[ d ] = input.dimension( d );
dim[ n ] = n;
final Img< T > gradients = new ArrayImgFactory< T >().create( dim, type );
final Img< T > gradients = new ArrayImgFactory<>( type ).create( dim );

// bounding box for computation of gradients
// we require a border of 1 pixel wrt. to the input image
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static void main( final String[] args )
ImageJ.main( args );

final String fn = "/Users/pietzsch/Desktop/data/cca2.tif";
final RandomAccessibleInterval< UnsignedByteType > img = IO.openImgs( fn, new ArrayImgFactory< UnsignedByteType >(), new UnsignedByteType() ).get( 0 ).getImg();
final RandomAccessibleInterval< UnsignedByteType > img = IO.openImgs( fn, new ArrayImgFactory<>( new UnsignedByteType() ) ).get( 0 ).getImg();

final long[] dims = new long[ img.numDimensions() ];
img.dimensions( dims );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
package net.imglib2.algorithm.morphology;

import ij.ImageJ;

import io.scif.img.IO;
import io.scif.img.ImgIOException;
import io.scif.img.ImgOpener;
import io.scif.img.SCIFIOImgPlus;

import java.io.File;
Expand All @@ -50,7 +51,7 @@ public static void main( final String[] args ) throws ImgIOException
{
ImageJ.main( args );
final File file = new File( "DrosophilaWing.tif" );
final SCIFIOImgPlus img = new ImgOpener().openImgs( file.getAbsolutePath() ).get( 0 );
final SCIFIOImgPlus img = IO.openImgs( file.getAbsolutePath() ).get( 0 );
final Img< UnsignedByteType > imgInv = img.copy();
final Cursor< UnsignedByteType > cursor = img.cursor();
final Cursor< UnsignedByteType > cursor2 = imgInv.cursor();
Expand Down Expand Up @@ -86,7 +87,7 @@ public static void main( final String[] args ) throws ImgIOException
* To target
*/

final Img img2 = img.factory().create( interval, new UnsignedByteType() );
final Img img2 = img.factory().create( interval );
final long[] translation = new long[ interval.numDimensions() ];
interval.min( translation );
final IntervalView translate = Views.translate( img2, translation );
Expand Down
Loading

0 comments on commit 4627adc

Please sign in to comment.