我想问一下,如何使用Python计算两幅三维图像的互信息值和标准化互信息值?任何帮助都将不胜感激。 我曾尝试使用sklearn中的函数来计算互信息值a,但我发现在旋转或平移图像后再次计算互信息时,会获得值B。a和B之间的差异非常小,所以我个人认为这种方法不适用于图像。我说的对吗?这是我在sklearn软件包中使用的代码
def NMI(img1,img2):
img1_ = sitk.GetArrayFromImage(img1)
img2_ = sitk.GetArrayFromImage(img2)
img2_ = np.reshape(img2_, -1)
img1_ = np.reshape(img1_, -1)
normalized_mutual_infor = mr.normalized_mutual_info_score(img1_, img2_)
nmi = normalized_mutual_infor
print(nmi)
fixed_image = sitk.ReadImage(r"D:\Lung CT\RIDER Lung CT\001_1.mha", sitk.sitkFloat32)
moving_image = sitk.ReadImage(r"D:\Lung CT\RIDER Lung CT\001_2.mha", sitk.sitkFloat32)
tfm1 = sitk.ReadTransform(r'D:\6freedom\1_text2.tfm')
x = tfm1.GetParameters()[3]
y = tfm1.GetParameters()[4]
z = tfm1.GetParameters()[5]
transform1 = sitk.Euler3DTransform(tfm1)
transform1.SetParameters((0, 0, 0, x, y, z))
resample = sitk.Resample(moving_image, fixed_image, transform1, sitk.sitkLinear, 0.0, moving_image.GetPixelID())
NMI(fixed_image, resample)
#When the parameter is (0,0,0, x, y, z), the result is 0.524628297588729
#When the parameter is (1,0,0, x, y, z), the result is 0.4657578384754303
#The unit of rotation is radians, so the image has been rotated a lot,
#but the difference between the two results is very small.
从这个漂亮的notebook,似乎可以使用输入图像的联合直方图,例如
相关问题 更多 >
编程相关推荐