NIfTI.jl
NIfTI.jl copied to clipboard
bug with Integer valued niftis
When creating a Integer valued nifti:
ni = NIVolume(Int16.(round.(rand(2,2,2))))
its type is
NIVolume{Float32,3,Array{Int16,3}}
I am not sure why, but it may have to do with the return type of getindex being Float32
Then when writing the nifti it becomes corrupted, as the header always says Float32 datatype
ok, the reason are the lines like
NIVolume{typeof(one(T)*1f0+1f0),N,typeof(raw)}(header, extensions, raw)
which then leads to niupdate corrupting the header
@vsaase I found essentially the same bug. My solution is different though. I wonder why you solved it the way you did? What would be the advantage relative to my proposal? (Just wondering if I should chuck mine, in case yours is superior.)
I'm tempted to drop the whole distinction between "raw" and actual data type. That would make fixing this straightforward. Thoughts?
I am not clear on whether this distinction reflects something in the description of the format or not. If it doesn't, it would certainly make things more straightforward if the implementation did not distinguish.
Technically there are two values for adding and multiplying the raw data. These serve to minimize the file size if you don't have enough unique values to need a Float64. I'm pretty sure this was developed with Matlab in mind where it can be painful to manage that manually.
Hi and thank you for a nice package.
I stumbled into this type of problem and found that @PetrKryslUCSD 's solution in #46 solved it for me. If it does not break anything, it would be fantastic if his suggestion could be added to the package.
I'm going to be making a fairly breaking change here soon that will fix this. I'm mostly getting dependencies registered and working.
I am having the same problem with integer valued niftis. #57 #46 seems to be related to the same issue. Is there any chance that this will be fixed soon? This issue might be a critical deal-breaker.
By the way, for a workaround, I have used FSL fslmaths
utility (here) to cast my int16
nifti to float32
:
fslmaths /path/to/my_nifti.nii.gz -mul 1.0 /path/to/my_nifti_float32.nii.gz
After doing this, niread
niwrite
works. Might be helpful if someone is looking for a quick workaround where it is not important to preserve the integer nature of the input niftis.
Sorry I haven't had time to fix this. I'm not sure if I'll have time to figure it out for a couple weeks but if someone makes a PR I could take a look