Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug in 'int16' data reading. #83

Merged
merged 1 commit into from
Feb 5, 2025
Merged

Conversation

aldoclemente
Copy link
Contributor

Hi,
I encountered a bug when trying to use brain2mesh to build a mesh from the ICBM 2009c Nonlinear Asymmetric Atlas (available here). This issue occurs when reading NIfTI files containing int16 data.

To reproduce the error you can use the following Docker image: aldoclemente/iso2mesh-bug.

Steps to reproduce the issue

Pull the Docker image and run the container:

docker run --rm -ti aldoclemente/iso2mesh-bug /bin/bash

Inside the container, you will find four directories:

  • ~/octave/: contains the required packages to run brain2mesh.

  • ~/mni_icbm152_nlin_asym_09c/: contains the nifti data.

  • ~/jnii_uint16/: contains the .jnii data obtained using the older version of nii2jnii(created with ~/mni_icbm152_nlin_asym_09c_jnii_uint16.m).

  • ~/jnii/: : contains the .jnii data obtained using the newer version of nii2jnii(created with ~/mni_icbm152_nlin_asym_09c_jnii.m).

You can run the script that reproduces the error:

cd && octave script_broken.m

To test the corrected version of nii2jnii, run:

cd && octave script.m 

You can inspect the output matrices (nodes, elements, and faces) with:

head nodes.txt 
head elements.txt
head faces.txt

Additional note

While running Octave in Docker, I encountered another minor issue at line 239 of nii2jnii.m.
To ensure proper execution, I had to modify this line in both versions of iso2mesh:

original:

nii.img = typecast(gzdata(nii.hdr.vox_offset + 1:nii.hdr.vox_offset + imgbytenum), nii.datatype);

modified:

nii.img = typecast(gzdata(double(nii.hdr.vox_offset + 1):double(nii.hdr.vox_offset + imgbytenum)), nii.datatype);

I also observed this behaviour when using the gnuoctave/octave Docker image.
However, I did not observe this issue when running Octave on my local machine, so I did not include it in the pull request.

Let me know if you need any further details!

Kind regards,
Aldo

@fangq fangq merged commit 1e7a9b4 into fangq:master Feb 5, 2025
11 checks passed
@fangq
Copy link
Owner

fangq commented Feb 5, 2025

thanks for fixing this typo. I also added your double() casting just to be safe on older versions of octave. will also port this to jsonlab and jnifty, which are the source packages providing nii2jnii.m.

fangq added a commit to NeuroJSON/jsonlab that referenced this pull request Feb 5, 2025
fangq added a commit to NeuroJSON/jnifty that referenced this pull request Feb 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants