如果我想将 3D 体积平面与 2D 切片相乘,numpy
我可以使用广播:
import numpy as np
vol = np.random.rand(10, 20, 30)
slc = np.random.rand(10, 30)
new_vol = vol * slc[:, None]
如果我尝试类似的东西,SimpleITK
我会得到一个错误
import SimpleITK as sitk
vol_img = sitk.GetImageFromArray(vol)
slc_img = sitk.GetImageFromArray(slc[:, None])
new_vol_img = vol_img * slc_img
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-1-7d2c0160b591> in <module>
9 vol_img = sitk.GetImageFromArray(vol)
10 slc_img = sitk.GetImageFromArray(slc[:, None])
---> 11 new_vol_img = vol_img * slc_img
~\AppData\Local\Continuum\anaconda3\lib\site-packages\SimpleITK\SimpleITK.py in __mul__(self, other)
4273 def __mul__( self, other ):
4274 if isinstance( other, Image ):
-> 4275 return Multiply( self, other )
4276 try:
4277 return Multiply( self, float(other) )
~\AppData\Local\Continuum\anaconda3\lib\site-packages\SimpleITK\SimpleITK.py in Multiply(*args)
50874
50875 """
> 50876 return _SimpleITK.Multiply(*args)
50877 class N4BiasFieldCorrectionImageFilter(ImageFilter_0):
50878 """
RuntimeError: Exception thrown in SimpleITK Multiply: C:\b\3.6-64\ITK\Modules\Core\Common\src\itkDataObject.cxx:393:
Requested region is (at least partially) outside the largest possible region.