korbinian90 / MriResearchTools.jl

Specialized tools for MRI
https://korbinian90.github.io/MriResearchTools.jl/dev
MIT License
25 stars 8 forks source link

Reading files with lower precision than Float64 #28

Open astewartau opened 2 months ago

astewartau commented 2 months ago

Hi Korbinian, do you know if it's possible to load and work with NIfTI images using MriResearchTools with anything smaller than Float64? This is sometimes an issue on machines with <16 GB memory, especially for multi-echo phase combination steps with a sufficiently large number of echoes and when the magnitude is also available and used.

For some NIfTI images, when I load them using nibabel in Python, nii.header.get_data_dtype().itemsize returns a value such as 8, depending on the image. However, loadmag and loadphase in MriResearchTools consistently return a Float64 Array. I'm not sure if this is an easy thing to update, but wondered if it could be possible. :)

korbinian90 commented 2 months ago

Hi Ashley,

I think that's because NIfTI.jl automatically scales the raw image by the scaling factor in the nifti Header. This scaling factor is float64, so the retrieved image is float64. You can instead access the raw image via: Ni = Loadmag(filename) Ni.raw

You can also check the types with typeof(Ni)

In Julia types are automatically converted when required. I didn't really take into account that users might want smaller data sizes. So a lot of my functions probably promote the input to float64. In principle it's not difficult to keep the data type consistent. So if you encounter other problems than reading the nifti, I can have a look.

I hope that helps. I'm already at the airport soon flying to OHBM, so this was written on my phone.

Cheers, Korbinian

Ashley Stewart @.***> schrieb am Fr., 21. Juni 2024, 08:48:

Hi Korbinian, do you know if it's possible to load and work with NIfTI images using MriResearchTools with anything smaller than Float64? This is sometimes an issue on machines with <16 GB memory, especially for multi-echo phase combination steps with a sufficiently large number of echoes and when the magnitude is also available and used.

For some NIfTI images, when I load them using nibabel in Python, nii.header.get_data_dtype().itemsize returns a value such as 8, depending on the image. However, loadmag and loadphase in MriResearchTools consistently return a Float64 Array.

— Reply to this email directly, view it on GitHub https://github.com/korbinian90/MriResearchTools.jl/issues/28, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJ7HAQSVT3URBMGHYQHKD3ZIPEETAVCNFSM6AAAAABJVJIT7WVHI2DSMVQWIX3LMV43ASLTON2WKOZSGM3DKOBUGQ4TEMQ . You are receiving this because you are subscribed to this thread.Message ID: @.***>

astewartau commented 2 months ago

Hi Korbinian, thanks for the advice! I'll try using what you suggested, and I'll see if I can test and make a pull request to use AbstractFloat without the datatype promotion.