Skip to content

Nifti image conflicted names - #9

Merged
hjmjohnson merged 3 commits into
masterfrom
nifti_image_conflicted_names
Jan 25, 2025
Merged

Nifti image conflicted names#9
hjmjohnson merged 3 commits into
masterfrom
nifti_image_conflicted_names

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Jan 23, 2025

Copy link
Copy Markdown
Member

If there are conflicted names, prefer to give a un-ambigous error stating the problem rather than guessing what to do.

Related to: InsightSoftwareConsortium/ITK#2243

Inspired by: NIFTI-Imaging#138 @neurolabusc

emulate FSL when multiple ambiguous filenames exist (.nii/.nii.gz),

Configure 'run "FSL=1 make"' and 'cmake -DFSLSTYLE=ON .'

Make names consistent
nifti_strdup() is too small to include an extension
emulate AFNI pigz support

Fixed conversion error when PIGZ is defined.

Configure 'run "FSL=1 make"' and 'cmake -DFSLSTYLE=ON .'
Reject complex data like FSL does

Configure 'run "FSL=1 make"' and 'cmake -DFSLSTYLE=ON .'
@hjmjohnson
hjmjohnson force-pushed the nifti_image_conflicted_names branch from bc14651 to 8047aee Compare January 23, 2025 20:04
@hjmjohnson

Copy link
Copy Markdown
Member Author

@neurolabusc Could you please review this update to your suggestions posed several years ago to NIFTI-Imaging/nifti_clib? These changes may provide a fix for an issue reported to ITK.

Thanks,
Hans

@hjmjohnson hjmjohnson self-assigned this Jan 23, 2025
@hjmjohnson hjmjohnson added the enhancement New feature or request label Jan 23, 2025
@hjmjohnson

Copy link
Copy Markdown
Member Author

@gdevenyi @lassoan Would you mind commenting on this upstream change as a solution to InsightSoftwareConsortium/ITK#2243? We could have ITK build with the nifti libraries with FSLSTYLE_NAME_CONFLICTS:BOOL=ON.

@gdevenyi

Copy link
Copy Markdown

Well, its 3 commits, which is what I suggested in the original PR :)

Erroring out on some of the more...interesting choices of how the reader works seems the most sensible thing to do, mirroring how FSL does it already (and re-using the environment variables) is good too.

I'm agnostic on pigz, its a band-aid to improve things on a file format lacking good internal compression.

@hjmjohnson
hjmjohnson merged commit 9a0b246 into master Jan 25, 2025
@hjmjohnson
hjmjohnson deleted the nifti_image_conflicted_names branch January 25, 2025 18:08

@seanm seanm left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO this was merged prematurely...

Comment thread nifti2/nifti2_io.c
#ifdef REJECT_COMPLEX
if ((nim->datatype == DT_COMPLEX64) || (nim->datatype == DT_COMPLEX128) || (nim->datatype == DT_COMPLEX256)) {
fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX64): use fslcomplex to manipulate: %s\n", hname);
exit(13);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 13?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a few years ago, perhaps that was the output of fsl tools at the time. Feel free to change this to 134 as that is what I get with the current version of fslmaths (the FSL error is odd, the tools work fine with float 32, so the error really refers to the enumeration for DT_COMPLEX64 which is 32.

$ fslmaths complex.nii.gz -add 0 sfsf
Image Exception : #8 :: Fslread: DT 32 not supported
libc++abi: terminating due to uncaught exception of type std::runtime_error: Fslread: DT 32 not supported
/Users/chris/fsl/share/fsl/bin/fslmaths: line 2: 19588 Abort trap: 6 /Users/chris/fsl/bin/fslmaths "$@"
$ echo $?
134

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And you actually need that exact error code? As I said in another comment, it's not ideal IMHO to call exit() in a library...

Comment thread niftilib/nifti1_io.c
#ifdef REJECT_COMPLEX
if ((nim->datatype == DT_COMPLEX64) || (nim->datatype == DT_COMPLEX128) || (nim->datatype == DT_COMPLEX256)) {
fprintf(stderr,"Image Exception Unsupported datatype (COMPLEX64): use fslcomplex to manipulate: %s\n", hname);
exit(13);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 13?

Comment thread niftilib/nifti1_io.c
Comment thread nifti2/nifti2_io.c
Comment thread CMakeLists.txt
Comment thread nifti2/nifti2_io.c

#ifdef PIGZ
#ifdef HAVE_ZLIB
int doPigz2(nifti_image *nim, struct nifti_2_header nhdr, const nifti_brick_list * NBL) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct nifti_2_header is a pretty big struct, might be better to pass by reference, not value, no?

Comment thread nifti2/nifti2_io.c
Comment thread nifti2/Makefile
CFLAGS = -Wall -std=gnu99 -pedantic $(USEZLIB) $(IFLAGS)


#run "FSLSTYLE=1 make" for JPEGLS build

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see the JPEGLS connection...

Comment thread nifti2/nifti2_io.c
Comment on lines +3747 to +3748
strcpy(gzname, hdrname);
strcat(gzname,extzip);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strcpy and strcat should not be used in new code

Comment thread nifti2/nifti2_io.c
if (nifti_fileexists(gzname)) {
fprintf(stderr,"Image Exception : Multiple possible filenames detected for basename (*.nii, *.nii.gz): %s\n", basename);
free(gzname);
exit(134);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why 134?

Also, it doesn't seem appropriate for library code to call exit(), nowhere else in this file calls exit(). This should probably return NULL.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compile directive FSLSTYLE emulates the beahavior of fsl tools, these terminate with these exit codes for these failures:

$fslmaths a add -0 b
Image Exception : #61 :: Multiple possible filenames detected for basename: a
libc++abi: terminating due to uncaught exception of type std::runtime_error: Multiple possible filenames detected for basename: a
/Users/chris/fsl/share/fsl/bin/fslmaths: line 2: 20227 Abort trap: 6           /Users/chris/fsl/bin/fslmaths "$@"
$ echo $?
134

@seanm seanm Feb 4, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So that's a SIGABRT. If we really need to emulate that, better to call abort().

But what would happen if we just return NULL? Could you try this: #11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants