CellImg incorrect dimension exception

Dear all,

I write this here because I guess I’m doing s.th. wrong - so I don’t put it into github issues…

Whenever I read a cell-type image (CellImg) with imglib2 (e.g. NDPI images, but also small jpg images, with config ImgMode.CELL explicitly set), it results in an incorrect dimensions exception:

    // NDPI file from http://downloads.openmicroscopy.org/images/Hamamatsu-NDPI/manuel/test3-DAPI%202%20(387)%20.ndpi
    String testPath = "test3-DAPI 2 (387) .ndpi";
    SCIFIOConfig config = new SCIFIOConfig();
    config.imgOpenerSetImgModes( SCIFIOConfig.ImgMode.CELL );
    final List<SCIFIOImgPlus<FloatType>> img = new ImgOpener().openImgs(new FileLocation(testPath), new FloatType(), config );
    img.get(0).firstElement();   // fails

it results in a exception “Expected bounds of dimensionality 3 but was 2”.
The image is an RGB image.

Stacktrace:

Summary
 Exception in thread "main" java.lang.RuntimeException: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Expected bounds of dimensionality 3 but was 2
	at net.imglib2.cache.util.CacheAsUncheckedCacheAdapter.get(CacheAsUncheckedCacheAdapter.java:32)
	at net.imglib2.img.cell.LazyCellImg$LazyCells.get(LazyCellImg.java:104)
	at net.imglib2.img.list.AbstractLongListImg$LongListCursor.get(AbstractLongListImg.java:98)
	at net.imglib2.img.cell.CellCursor.getCell(CellCursor.java:94)
	at net.imglib2.img.cell.CellCursor.moveToNextCell(CellCursor.java:182)
	at net.imglib2.img.cell.CellCursor.reset(CellCursor.java:152)
	at net.imglib2.img.cell.CellCursor.<init>(CellCursor.java:88)
	at net.imglib2.img.cell.AbstractCellImg.cursor(AbstractCellImg.java:92)
	at net.imglib2.img.cell.AbstractCellImg.cursor(AbstractCellImg.java:51)
	at net.imglib2.img.AbstractImg.firstElement(AbstractImg.java:81)
	at net.imagej.ImgPlus.firstElement(ImgPlus.java:276)
	at TileReader2.main(TileReader2.java:53)
Caused by: java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Expected bounds of dimensionality 3 but was 2
	at net.imglib2.cache.ref.SoftRefLoaderRemoverCache.get(SoftRefLoaderRemoverCache.java:168)
	at net.imglib2.cache.util.LoaderRemoverCacheAsLoaderCacheAdapter.get(LoaderRemoverCacheAsLoaderCacheAdapter.java:37)
	at net.imglib2.cache.util.LoaderCacheAsCacheAdapter.get(LoaderCacheAsCacheAdapter.java:30)
	at net.imglib2.cache.util.CacheAsUncheckedCacheAdapter.get(CacheAsUncheckedCacheAdapter.java:28)
	... 11 more
Caused by: java.lang.IllegalArgumentException: Expected bounds of dimensionality 3 but was 2
	at io.scif.img.cell.loaders.AbstractArrayLoader.validateBounds(AbstractArrayLoader.java:306)
	at io.scif.img.cell.loaders.AbstractArrayLoader.read(AbstractArrayLoader.java:279)
	at io.scif.img.cell.loaders.AbstractArrayLoader.read(AbstractArrayLoader.java:270)
	at io.scif.img.cell.loaders.AbstractArrayLoader.read(AbstractArrayLoader.java:252)
	at io.scif.img.cell.loaders.AbstractArrayLoader.loadArray(AbstractArrayLoader.java:232)
	at io.scif.img.cell.SCIFIOCellImgFactory$SCIFIOCellLoader.load(SCIFIOCellImgFactory.java:200)
	at net.imglib2.cache.img.LoadedCellCacheLoader.get(LoadedCellCacheLoader.java:91)
	at net.imglib2.cache.img.LoadedCellCacheLoader.get(LoadedCellCacheLoader.java:51)
	at net.imglib2.cache.img.DiskCellCache.get(DiskCellCache.java:104)
	at net.imglib2.cache.img.DiskCellCache.get(DiskCellCache.java:43)
	at net.imglib2.cache.IoSync.get(IoSync.java:174)
	at net.imglib2.cache.ref.SoftRefLoaderRemoverCache.get(SoftRefLoaderRemoverCache.java:158)
	... 14 more

Gradle dependencies:

Summary

compile ‘net.imglib2:imglib2:5.8.0’
compile ‘net.imglib2:imglib2-algorithm:0.11.1’
compile ‘net.imglib2:imglib2-algorithm-fft:0.2.0’
compile ‘net.imglib2:imglib2-algorithm-gpl:0.2.3’
compile ‘net.imglib2:imglib2-ij:2.0.0-beta6’
compile ‘net.imglib2:imglib2-realtransform:2.2.1’
compile ‘net.imglib2:imglib2-ui:2.0.0’
compile ‘net.imagej:imagej:2.0.0-rc-69’
compile group: ‘io.scif’, name: ‘scifio-bf-compat’, version: ‘4.0.0’
compile (group: ‘ome’, name:‘formats-gpl’, version:‘6.1.1’) {
exclude (module: ‘blitz’)
}

Am I doing s.th. wrong?

Some debugging shows me the error comes from

 CellCursor->private void moveToNextCell()
	{
		cursorOnCells.fwd();
		isNotLastCell = cursorOnCells.hasNext();
		lastIndexInCell = ( int ) ( getCell().size() - 1 );
		index = -1;
		type.updateContainer( this );
	}

-> getCell()

Any ideas?

Cheers,
Manuel

1 Like

Hi Manuel, do you see any exceptions with the image if you open directly with the Bio-Formats Importer?

Hi @dgault,
no, that works without any problems.

so if instead of

final List<SCIFIOImgPlus<FloatType>> img = new ImgOpener().openImgs(new FileLocation(testPath), new FloatType(), config );

the CellImgFactory is used

final List<SCIFIOImgPlus<FloatType>> img = new ImgOpener().openImgs(location, new CellImgFactory<>( new FloatType(), 512,512,3 ) );

it works, but only for small images because it reads everything into memory.

For the lazy cell loading factory

DiskCachedCellImgOptions options = new DiskCachedCellImgOptions();
options.cellDimensions(512,512,3);
final List<SCIFIOImgPlus<FloatType>> img = new ImgOpener().openImgs(location, new SCIFIOCellImgFactory<>( new FloatType(), options ) );

it’s exactly the same problem (wrong dimensionality exception) as initially.

What’s the correct way of reading big images with lazy cell loading? Or is it a bug?

Cheers,
Manuel

There is now a GitHub issue, imglib/imglib2#267, describing this same issue.