简体   繁体   中英

MemoryError: Unable to allocate 115. MiB for an array with shape (344, 344, 127) and data type float64 in DIPY image registration

I'm trying to do image registration using DIPY (Affine registration in 3d) I tried to run the following code (Actually I tried to reproduce the example code with a different nifti file)

from os.path import join as pjoin
import numpy as np
from dipy.viz import regtools
from dipy.data import fetch_mni_template, read_mni_template
from dipy.data.fetcher import fetch_syn_data, read_syn_data
from dipy.io.image import load_nifti
from dipy.align.imaffine import (transform_centers_of_mass,
                                 AffineMap,
                                 MutualInformationMetric,
                                 AffineRegistration)
from dipy.align.transforms import (TranslationTransform3D,
                                   RigidTransform3D,
                                   AffineTransform3D)

files, folder = fetch_mni_template()
static_data, static_affine = load_nifti(pjoin(folder, 'mni_icbm152_t1_tal_nlin_asym_09a.nii'))
static = np.squeeze(static_data)
static_grid2world = static_affine

files, folder = fetch_syn_data()
moving_data, moving_affine = load_nifti(pjoin(folder, '2018.nii'))
moving = moving_data
moving_grid2world = moving_affine

identity = np.eye(4)
affine_map = AffineMap(identity,
                       static.shape, static_grid2world,
                       moving.shape, moving_grid2world)
print(static.shape)


resampled = affine_map.transform(moving)


regtools.overlay_slices(static, resampled, None, 0,
                        "Static", "Moving", "resampled_0.png")
regtools.overlay_slices(static, resampled, None, 1,
                        "Static", "Moving", "resampled_1.png")
regtools.overlay_slices(static, resampled, None, 2,
                        "Static", "Moving", "resampled_2.png")

c_of_mass = transform_centers_of_mass(static, static_grid2world,
                                      moving, moving_grid2world)

transformed = c_of_mass.transform(moving)
regtools.overlay_slices(static, transformed, None, 0,
                        "Static", "Transformed", "transformed_com_0.png")
regtools.overlay_slices(static, transformed, None, 1,
                        "Static", "Transformed", "transformed_com_1.png")
regtools.overlay_slices(static, transformed, None, 2,
                        "Static", "Transformed", "transformed_com_2.png")

nbins = 32
sampling_prop = None
metric = MutualInformationMetric(nbins, sampling_prop)

level_iters = [10000, 1000, 100]

sigmas = [3.0, 1.0, 0.0]

factors = [4, 2, 1]

affreg = AffineRegistration(metric=metric,
                            level_iters=level_iters,
                            sigmas=sigmas,
                            factors=factors)

transform = TranslationTransform3D()
params0 = None
starting_affine = c_of_mass.affine

translation = affreg.optimize(static, moving, transform, params0,
                              static_grid2world, moving_grid2world,
                              starting_affine=starting_affine)

but im getting the following error

MemoryError: Unable to allocate 115. MiB for an array with shape (344, 344, 127) and data type float64

I couldn't find a solution for this.

I solved this issue by moving from 32 bit version of python to 64 bit version

Thanks, Mani

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM