[英]How do I apply an affine transform to a 3d numpy array?
我使用以下代碼獲得了 [180,512,512] 形狀的 DICOM 圖像。 該圖像由 180 個切片組成,大小為 512x512。
dcm_list = glob.glob(os.path.join(PathDicom, "*.dcm"))
slices = [pydicom.read_file(dcm) for dcm in dcm_list]
slices.sort(key = lambda x: float(x.InstanceNumber))
if ('RescaleIntercept' in slices[0] and 'RescaleSlope' in slices[0]):
print("TRUE")
slope = slices[0].RescaleSlope
intercept = slices[0].RescaleIntercept
image = np.stack([s.pixel_array*slope+intercept for s in slices], axis=0)
else:
image = np.stack([s.pixel_array for s in slices], axis=0)
但是,我想將這些圖像傾斜成如下所示的 4x4 仿射矩陣,但我不知道該怎么做。
4x4 affine matrix :
[[ 2.1219860e-01 9.1372589e-03 -1.4462248e-02 -1.1527188e+02]
[-9.1041764e-03 2.1220960e-01 1.0911685e-02 -9.0879768e+01]
[ 3.1687310e-03 -2.1837775e-03 9.9983585e-01 -7.8977943e+01]
[ 0.0000000e+00 0.0000000e+00 0.0000000e+00 1.0000000e+00]]
對於 dicom 中的 3D 功能,尤其是如果您想做旋轉等,也許可以查看simpleITK而不是 pydicom。
它本身(並且非常快速地)處理 3D dicom 圖像的完整 3D 方面,並且會非常簡單輕松地完成您在這里尋找的事情。
Pydicom 在很多方面都很棒,但如果您正在尋找 3D 操作,您可能會更好地轉向 SITK。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.