Help with extracting one plane in a NDPI z-stack

Hi,

I am successfully using the bio-formats batch commands to manipulate large NDPI files within a python script to split each NDPI file into a collection of 512x512 tiles.

I now have a NDPI z-stack file of which I need to extract each z-plane as such a tile collection. However, the batch command using the “-z” parameter always outputs the same plane.

I checked the NDPI file in the Hamamatsu NDPview2 viewer and the file indeed has 5 planes of focus, as intended. The ndpi header (extracted using the bio-formats batch command) also says that each section contains 5 images in a z-stack.

The batch command:
./bfconvert -z 0 -crop 0,0,512,512 B15_Golgi.ndpi B15_Golgi-plane0.tiff
works perfectly and generates the intended image. But I am unable to get any other z plane… -z 1, or -z 2 don’t generate a file, while negative numbers (-z -1, for example) generate the same file as -z 0.

What mistake am I doing? What value should I use in the -z parameter in order to access the other planes?

This is the relevant header info for the first section of the ndpi file:

Reading core metadata
filename = C:\histolab\Step 0 - NDPI Files\B15_Golgi.ndpi
Series count = 8
Series #0 :
Image count = 5
RGB = true (3)
Interleaved = true
Indexed = false (true color)
Width = 25088
Height = 26880
SizeZ = 5
SizeT = 1
SizeC = 3 (effectively 1)
Thumbnail size = 119 x 128
Endianness = intel (little)
Dimension order = XYCZT (uncertain)
Pixel type = uint8
Valid bits per pixel = 8
Metadata complete = true
Thumbnail series = false
-----
Plane #0 <=> Z 0, C 0, T 0
Plane #2 <=> Z 2, C 0, T 0
Plane #4 <=> Z 4, C 0, T 0

This is the powershell output when running the batch command:

./bfconvert -series 5 -z 2 B15_Golgi.ndpi B15_Golgi-serie05-02.tiff
*** A new stable version is available. ***
*** Install the new version using: ***
*** ‘upgradechecker -install’ ***
B15_Golgi.ndpi
NDPIReader initializing B15_Golgi.ndpi
Reading IFDs
Populating metadata
Populating OME metadata
[Hamamatsu NDPI] -> B15_Golgi-serie05-02.tiff [Tagged Image File Format]
Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at ome.xml.model.Pixels.getChannel(Pixels.java:628)
at ome.xml.meta.OMEXMLMetadataImpl.getChannelName(OMEXMLMetadataImpl.java:1211)
at loci.formats.FormatTools.getFilename(FormatTools.java:1138)
at loci.formats.FormatTools.getFilename(FormatTools.java:1101)
at loci.formats.tools.ImageConverter.testConvert(ImageConverter.java:537)
at loci.formats.tools.ImageConverter.main(ImageConverter.java:880)

Thanks for getting in touch @vagporto,

Is the error you showed in your last post only happening for the 6th series or also e.g. for earlier series like -series 0 or -series 1? Also could you give the dimensions of each series e.g. as shown by the output of:

showing -nopix B15_Golgi.ndpi

Sebastien

Hi,

It occurs for all series. What happens is that series 0-4 are so large that give memory errors unless I output only a cropped portion. So, the following works well:

./bfconvert -z 0 -series 0 -crop 0,0,4000,4000 B15_Golgi.ndpi B15_Golgi-plane0.tiff

while for example the similar one but at another z plane does not work:

./bfconvert -z 0 -series 2 -crop 0,0,4000,4000 B15_Golgi.ndpi B15_Golgi-plane2.tiff

It generates the exception:
Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 2, Size: 1

Using the “showinf.bat” command the sizes of each series is (and that is the reason I use series 5 for testing - no need for additional cropping commands):

Series #0 :
Image count = 5
Width = 25088
Height = 26880
SizeZ = 5

Series #1 :
Image count = 5
Width = 12544
Height = 13440
SizeZ = 5

Series #2 :
Image count = 5
Width = 6272
Height = 6720
SizeZ = 5

Series #3 :
Image count = 5
Width = 3136
Height = 3360
SizeZ = 5

Series #4 :
Image count = 5
Width = 1568
Height = 1680
SizeZ = 5

Series #5 :
Image count = 5
Width = 784
Height = 840
SizeZ = 5

Series #6 :
Image count = 1
Width = 1036
Height = 352
SizeZ = 1

Series #7 :
Image count = 1
Width = 518
Height = 176
SizeZ = 1

Hi Vasco

here you are selecting the second series not the second z plane

while for example the similar one but at another z plane does not work:

./bfconvert -z 0 -series 2 -crop 0,0,4000,4000 B15_Golgi.ndpi B15_Golgi-plane2.tiff

I don’t think is a matter of memory size, since you are cropping in the conversion.

Cheers
Mafalda

Hi,

Thanks for the suggestion, but that was a simple typing mistake. What I tried was in fact what you mention:

./bfconvert -z 2 -series 0 -crop 0,0,4000,4000 B15_Golgi.ndpi B15_Golgi-plane2.tiff

(cropping series 0 and not series 2). This is the entire bfconvert exception output:

B15_Golgi.ndpi
NDPIReader initializing B15_Golgi.ndpi
Reading IFDs
Populating metadata
Populating OME metadata
[Hamamatsu NDPI] -> B15_Golgi-plane2.tiff [Tagged Image File Format]
Exception in thread “main” java.lang.IndexOutOfBoundsException: Index: 2, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at ome.xml.model.Pixels.getChannel(Pixels.java:628)
at ome.xml.meta.OMEXMLMetadataImpl.getChannelName(OMEXMLMetadataImpl.java:1211)
at loci.formats.FormatTools.getFilename(FormatTools.java:1138)
at loci.formats.FormatTools.getFilename(FormatTools.java:1101)
at loci.formats.tools.ImageConverter.testConvert(ImageConverter.java:537)
at loci.formats.tools.ImageConverter.main(ImageConverter.java:880)

It gets even weirder… I now tried to output to JPG instead of TIFF.

./bfconvert -z 0 -series 0 -crop 0,0,4000,4000 B15_Golgi.ndpi B15_Golgi-plane0.jpg

gives the following error exception BUT GENERATES THE CORRECT JPG FILE:
Exception in thread “main” java.lang.ArithmeticException: / by zero
at loci.formats.tools.ImageConverter.testConvert(ImageConverter.java:572)
at loci.formats.tools.ImageConverter.main(ImageConverter.java:880)

while:
./bfconvert -z 4 -series 0 -crop 0,0,4000,4000 B15_Golgi.ndpi B15_Golgi-plane4.jpg

gives no exception error, outputs that conversion was OK, but generates no JPG file!!!
[Hamamatsu NDPI] -> B15_Golgi-plane4.jpg [JPEG]
[done]
1.453s elapsed (NaN+NaNms per plane, 1437ms overhead)

BTW, I tried to use bio-formats v5 and the errors persist.

Hi @vagporto,

Thanks for the extra information about the dimensions and the failing commands. I am trying to reproduce your issue but it is possible we might need the file you used.

One separate question: which version of Bio-Formats command line tools are you using?

Best,
Sebastien

Hi Sébastien,

I am using the latest version, but also tried using 2 instances of v5 with the same results.

However, meanwhile I copied several other .jar files into the bftools folder (like loci.tools.jar, formats-api.jar, etc) and now I am able to crop and extract the separate planes, although it still reports the same exception errors:

I will later report any update on this issue…

Hi @vagporto, that most recent exception (Invalid tile size), looks as though it has converted the first series fine but failed at the lower resolution series due to the x + y being out of range. If instead you convert just ./bfconvert -z 3 -series 0 -crop 3000,18000,4000,4000 B15_Golgi.ndpi B15_Golgi-plane3.tiffthen that should work as expected.