首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >计算三维图像的互信息量

计算三维图像的互信息量
EN

Stack Overflow用户
提问于 2020-08-12 16:53:57
回答 1查看 433关注 0票数 0

请问,如何使用Python计算两张三维图像的互信息值和标准化互信息值?任何帮助都将不胜感激。我曾尝试使用sklearn中的函数来计算互信息值a,但我发现在旋转或平移图像后再次计算互信息值时,得到的是值B。A和b之间的差异非常小,所以我个人认为这种方法不适用于图像。我说的对吗?这是我在sklearn包中使用的代码。

代码语言:javascript
复制
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.
EN

回答 1

Stack Overflow用户

发布于 2020-08-26 05:25:10

从这个很好的notebook中,似乎可以使用输入图像的联合直方图,例如

代码语言:javascript
复制
import numpy as np
def mutual_information(hgram):
     # Mutual information for joint histogram
     # Convert bins counts to probability values
     pxy = hgram / float(np.sum(hgram))
     px = np.sum(pxy, axis=1) # marginal for x over y
     py = np.sum(pxy, axis=0) # marginal for y over x
     px_py = px[:, None] * py[None, :] # Broadcast to multiply marginals
     # Now we can do the calculation using the pxy, px_py 2D arrays
     nzs = pxy > 0 # Only non-zero pxy values contribute to the sum
     return np.sum(pxy[nzs] * np.log(pxy[nzs] / px_py[nzs]))
hist_2d, x_edges, y_edges = np.histogram2d(img1.ravel(),img2.ravel(),bins=20)
mi = mutual_information(hist_2d)
print(mi)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63373115

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档