调整3D图像的大小(并重新采样) [英] Resizing a 3D image (and resampling)
问题描述
我有一个大脑的3D图像(我们称它为闪光灯),当前为263 x 256 x 185. 256 x 256 x 176,并且(希望)使用lanczos插值进行重新采样(Image.ANTIALIAS).我的(失败的)尝试:
I have 3D image of a brain (let's call it flash) and it's currently 263 x 256 x 185. I want to resize it to be the size of another image(call it whole_brain_bravo); 256 x 256 x 176, and (hopefully) use a lanczos interpolation to resample (Image.ANTIALIAS). My (failed) attempt:
from scipy import ndimage as nd
import nibabel as nib
import numpy as np
a = nib.load('flash.hdr') # nib is what I use to load the images
b = nib.load('whole_brain_bravo.hdr')
flash = a.get_data() # Access data as array (in this case memmap)
whole = b.get_data()
downed = nd.interpolation.zoom(flash, zoom=b.shape) # This obviously doesn't work
你们曾经在3D图像上做过这种事情吗?
Have you guys ever done this sort of thing on a 3D image?
推荐答案
来自scipy.ndimage.interpolate.zoom
的文档字符串:
"""
zoom : float or sequence, optional
The zoom factor along the axes. If a float, `zoom` is the same for each
axis. If a sequence, `zoom` should contain one value for each axis.
"""
两个图像之间的比例因子是多少?它在所有轴上都恒定吗(即,您是否按等距缩放)?在这种情况下,zoom
应该是单个浮点值.否则,它应该是一系列浮点数,每个轴一个.
What is the scale factor between the two images? Is it constant across all axes (i.e. are you scaling isometrically)? In that case zoom
should be a single float value. Otherwise it should be a sequence of floats, one per axis.
例如,如果可以假设whole
和flash
的物理尺寸相等,则可以执行以下操作:
For example, if the physical dimensions of whole
and flash
can be assumed to be equal, then you could do something like this:
dsfactor = [w/float(f) for w,f in zip(whole.shape, flash.shape)]
downed = nd.interpolation.zoom(flash, zoom=dsfactor)
这篇关于调整3D图像的大小(并重新采样)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!