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

"TypeError: Axis must be specified when shapes of a and weights differ." in the LSQ method #59

Open
Siji-chl opened this issue Apr 22, 2022 · 0 comments

Comments

@Siji-chl
Copy link

Siji-chl commented Apr 22, 2022

🐛 Bug

My data are 3D brain MRI with large slicethickness (~5mm) and slicegap (~5mm) in .nii.gz format. First, I used HD-BET algorithm to get brain masks, then normalised the images using the LSQ method. But the code ran into the following error.

Code:

t1_image_paths = glob(root + r'/*_{}.nii.gz'.format(t1_modality))
t1_image_paths = sorted(t1_image_paths)
t1_images = [nib.load(t1_image_path) for t1_image_path in t1_image_paths]
t1_images_array = [t1_image.get_fdata() for t1_image in t1_images]
mask_paths = glob(mask_root + r'/*_{}_stripped_mask.nii.gz'.format(mask_modality))
mask_paths = sorted(mask_paths)
masks = [nib.load(mask_path) for mask_path in mask_paths]
masks_array = [mask.get_fdata() for mask in masks]
lsq_norm = LeastSquaresNormalize(norm_value=100)
lsq_norm.fit(t1_images, masks, modality='t1')
Traceback (most recent call last):
  File "/home/chenhaolin/Documents/normalized/normalize.py", line 286, in <module>
    lsq_norm.fit(t1_images, masks, modality='t1')
  File "/home/chenhaolin/Documents/py_environments/chl3.9/lib/python3.9/site-packages/intensity_normalization/normalize/base.py", line 389, in fit
    self._fit(images, masks, modality=modality, **kwargs)
  File "/home/chenhaolin/Documents/py_environments/chl3.9/lib/python3.9/site-packages/intensity_normalization/normalize/lsq.py", line 97, in _fit
    csf_mean = np.average(image, weights=tissue_membership[..., 0])
  File "<__array_function__ internals>", line 180, in average
  File "/home/chenhaolin/Documents/py_environments/chl3.9/lib/python3.9/site-packages/numpy/lib/function_base.py", line 508, in average
    raise TypeError(
TypeError: Axis must be specified when shapes of a and weights differ.

Environment

  • intensity-normalization version (2.2.3):
  • numpy version (1.22.3):
  • OS (Linux 18.04.6 LTS (GNU/Linux 5.4.0-107-generic x86_64)):
  • How you installed intensity-normalization (via pip):
  • Python version: 3.9.7
  • Any other relevant information: None
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

No branches or pull requests

1 participant