[英]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)我正在尝试使用 DIPY(3d 中的仿射注册)进行图像注册我尝试运行以下代码(实际上我尝试使用不同的 nifti 文件重现示例代码)
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
内存错误:无法为形状为 (344, 344, 127) 且数据类型为 float64 的数组分配 115. MiB
I couldn't find a solution for this.我找不到解决方案。
I solved this issue by moving from 32 bit version of python to 64 bit version我通过从 32 位版本的 python 移动到 64 位版本解决了这个问题
Thanks, Mani谢谢,玛尼
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.