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

[PET] Improve how to 4D images with 1 volume are handled #871

Closed
alexandreroutier opened this issue Jan 22, 2023 · 4 comments · Fixed by #872
Closed

[PET] Improve how to 4D images with 1 volume are handled #871

alexandreroutier opened this issue Jan 22, 2023 · 4 comments · Fixed by #872

Comments

@alexandreroutier
Copy link
Contributor

Hi!

Following Discussion #870, it turns out that 4D images with 1 volume are not taken into account in PET pipelines:

A solution would be:

    if len(img.shape) == 4:
        if img.shape[3] > 1:
            error_msg = (
                f"Clinica does not handle 4D volumes for {image_id.replace('_', ' | ')}"
            )

(I have a doubt but a oneliner if len(img.shape) == 4 and img.shape[3] > 1: could also work)

Best,
Alex

@NicolasGensollen
Copy link
Member

Thanks for looking into this @alexandreroutier !
I'm wondering whether we should also explicitly squeeze the image in this case (might be done automatically by tools downstream, but doesn't hurt I think...). Maybe something like this:

def _check_img_3d(img):
    """Load a 3D nifti image, raise if not 3D...""" 
    img = nib.load(img)
    dim = len(img.shape) 
    if dim != 3:
        if dim == 4 and img.shape[3] == 1:
            data = img.get_fdata()
            klass = img.__class__
            header = copy.deepcopy(img.header)
            return klass(data[:, :, :, 0], img.affine, header=header)
        error_msg = ( 
             f"Clinica does not handle {dim}D volumes for {image_id.replace('_', ' | ')}" 
         ) 
        cprint(error_msg, lvl="error")
        raise NotImplementedError(error_msg)
    return img

@ghisvail
Copy link
Collaborator

I'm wondering whether we should also explicitly squeeze the image in this case

In that case, I'd suggest to rename this function to something more explicit. check implies a boolean or exception raising function. Here we are actually loading and returnung the data.

(might be done automatically by tools downstream, but doesn't hurt I think...).

From the old nipype code base perpsective, I think you are right.

For the pydra pipelines, since they rely on checksumming the input files to handle caching, the 4D to 3D squeezing should probably happen in a separate node which will keep track of the old and new (squeezed) volume files.

On a side note, since the PET volumes likely came from preprocessed ADNI files, maybe it's also the job of our converters to ensure volumes are squeezed and (re)written to 3D. There was also a similar point raised in #622 about normalizing the data type used for writing.

@NicolasGensollen
Copy link
Member

In that case, I'd suggest to rename this function to something more explicit. check implies a boolean or exception raising function. Here we are actually loading and returnung the data.

Yes, I agree the name is misleading, I'll change that in #872

@alexandreroutier
Copy link
Contributor Author

I didn't think about it yesterday but you are raising the fact that we don't known how third party apps are handling this particular case 🤔 Generating an 'adequate' 3D image would be the simplest solution.

(For info, this NotImplementedError was added in order to solve #70)

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 a pull request may close this issue.

3 participants