【问题标题】:Get the ROI of two binary images and find difference of the mean image intesities between 2 ROI in python获取两个二值图像的 ROI 并在 python 中找到 2 个 ROI 之间的平均图像强度的差异
【发布时间】:2014-02-24 12:13:58
【问题描述】:

我有 2 个二进制图像(uint16,[512,512]),ROI 位于确切的中心,我怎样才能获得这两个二进制图像(image1.dat 和 image2.dat)的 ROI 并计算平均强度之间的差异这 2 个 ROI 并将其保存为 Python 中的 PDF。请帮帮我。

谢谢

【问题讨论】:

  • 您对“投资回报率”的定义是什么?
  • 我拥有的图像的 ROI 是中心的一个方块。[100:400, 150:350]
  • 为什么要将图像存储为 PDF?存储为图像会更好...

标签: python image image-processing binary


【解决方案1】:

您应该使用[numpy][1]。加载和保存图像可以使用不同的模块完成。这里我用的是numpy,但是有other possibilities

import numpy as np

#Load the image using numpy
shape = (512, 512)
im1 = np.fromfile('image1.dat', 'uint16').reshape(shape)
im2 = np.fromfile('image2.dat', 'uint16').reshape(shape)

#extract the ROI
im1_roi = im1[100:400,150:350] 
im2_roi = im2[100:400,150:350] 

#Get the difference and save to BMP
im_difference = im1_roi-im2_roi

result = Image.fromarray(im_difference)
result.save('out.bmp')

#Get the MEAN of the intensities and compute the difference
im_mean_difference = np.mean(im1_roi)-np.mean(im2_roi)
print im_mean_difference

【讨论】:

  • 您好,谢谢,但是我有二进制图像数据,是否必须将它们转换为图像数组?以及如何计算 python 中的强度和方差?
  • 检查新版本的答案。我添加了一个加载二进制图像的示例(这取决于图像的格式),以及平均强度的计算。
猜你喜欢
  • 2019-04-30
  • 1970-01-01
  • 1970-01-01
  • 2021-07-04
  • 1970-01-01
  • 2021-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多