Odd result for numDimensions() on a DefaultDataset

Hello, I am getting strange results trying to find the number of spatial dimensions of an image.
For the FluorescentCells.tif image found in File -> Open Samples in the Fiji dialog, calling the following gives an unexpected result:

Load the input image as a DefaultDataset

input_image = ij.io().open(f)

Get dimensions of image

dimensions = input_image.numDimensions()

returns dimensions == 3 even though it is a 2D image (but with 3 color channels).
Are the multiple color channels the 3rd dimension?

Calling the same functions on Blobs.gif (2D, single channel) returns dimensions == 2

How can i distinguish between an image with 3 spatial dimensions (xyz) and a 2D image with multiple color channels?

Thank you,

Hi Cameron (@arshadic),

Welcome to the forum!

You can ask a Dataset ds how many channels it has with: ds.getChannels()

// how many dimensions? (not only spatial)
println( ds.numDimensions())
// how many Channels are there
// if this returns 
println( ds.getChannels() )

// which dimension holds the channels?
// this returns an optional, if its non-empty then there exists a channel dimension
// if it returns Optional.empty, then there is no channel dimension
println( ds.axis( Axes.CHANNEL )) 

Check here for lots of details, and more options.

Please post back if you have more questions,

1 Like