We're Hiring!

Adding support for complex NIfTI files

Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats
Please note:
Historical discussions about the Bio-Formats library. Please look for and ask new questions at https://forum.image.sc/tags/bio-formats

If you are having trouble with image files, there is information about reporting bugs in the Bio-Formats documentation. Please send us the data and let us know what version of Bio-Formats you are using. For issues with your code, please provide a link to a public repository, ideally GitHub.

Adding support for complex NIfTI files

Postby ericbarnhill » Fri Mar 02, 2018 12:09 pm

I would like to add support for complex files to the NiftiReader class so that if I open a Nifti in ImageJ and it is complex, there is a default behavior.

I think it would be fine for the initial default behavior to simply read the real component of the image, and if there was interest it could be further developed to opening a 4D image or opening two stacks.

Unlike my last pull request (https://github.com/openmicroscopy/bioformats/pull/2493) I am having trouble figuring out where to get started. Obviously the populatePixelType() method requires an additional switch block

Code: Select all
case 16:
    m.pixelType = FormatTools.FLOAT;
    break;
// just add a condition for 32
// case 32:
//    m.pixelType = FormatTools.DOUBLE;
case 64:
    m.pixelType = FormatTools.DOUBLE;
    break;


however I do not see where to add the functionality of reading every other value out of the NIfTI. So I have these starting questions:
1) What method reads the bytes of the body of the image in NiftiReader?
2) Should this method incorporate the isInterleaved() functionality, because technically the complex NIfTI is stored in an interleaved manner?

Eric
ericbarnhill
 
Posts: 2
Joined: Fri Mar 02, 2018 9:10 am

Re: Adding support for complex NIfTI files

Postby dgault » Mon Mar 05, 2018 12:19 pm

Hi Eric,

The 2 main methods in each reader are initFile which is first called to initiate the file and read the metadata values and openBytes which is then used to retrieve the pixel values for each plane.

When a file is first opened by the reader the initFile method (https://github.com/openmicroscopy/biofo ... .java#L206) is first called and it is here that the metadata is read and set for the file. For the interleaved property in particular it is currently set at https://github.com/openmicroscopy/biofo ... .java#L273 based on if the file is RGB or not. This condition could be updated if you have an additional use case for it.

The pixel values for each plane are then handled in the openBytes method (https://github.com/openmicroscopy/biofo ... .java#L146). In the case of the NiftiReader this function simply seeks to the correct part of the file and uses the base FormatReader to read the pixel values in the plane (https://github.com/openmicroscopy/biofo ... .java#L517). If the only change you are making is adding support for 32 bit pixels then the FormatReader should be able to handle this by setting the pixelType. If you require other custom handling of the pixels just let me know and I can point you towards examples in other readers.

David Gault
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm

Re: Adding support for complex NIfTI files

Postby ericbarnhill » Tue Mar 06, 2018 9:19 am

Hi David,

Complex NIfTI images are indeed single precision (i.e. 32-bit) but also interleaved. So a method to handle complex NIfTIs would have to read every other pixel to create an image of the real component for example.

As you suggest, there may be relevant code examples already -- is there an example of readBytes applied to interleaved images, perhaps in an RGB reader? If so, then I think I stand a good chance of being able to adapt this to Complex NIfTI.

Thanks,
Eric
ericbarnhill
 
Posts: 2
Joined: Fri Mar 02, 2018 9:10 am

Re: Adding support for complex NIfTI files

Postby dgault » Wed Mar 07, 2018 2:00 pm

Hi Eric,

The good news is that the existing openBytes with readPlane should be able to handle both the 32bit and interleaved data. As long as the values are correctly set on the coreMetadata in the initFile then that sounds like it may be all that is required. The pixelType can be updated as you had suggested with an extra case on the switch statement and the interleaved can be updated in its existing location (https://github.com/openmicroscopy/biofo ... .java#L273) .

Some examples of other readers that use readPlane in this way would be the BMP Reader or the JPEG2000Reader.
User avatar
dgault
Team Member
 
Posts: 208
Joined: Fri Aug 14, 2015 2:56 pm


Return to User Discussion [Legacy]

Who is online

Users browsing this forum: No registered users and 0 guests