我有这些医学原始数据图像,它们有.rawb而不是.jpg。我需要打开并读取这些3D数据。我的问题是,在将该文件打开到python中后,我必须比较该图像中两个不同区域的像素强度(平均值(。
对于第二部分(即,一旦您将图像读取到numpy数组中(,您可以按如下方式进行:
import numpy as np
# simulate an image
n, m, o = 100, 100, 100
img = np.random.random((n, m, o)) ** 8
# define the two regions by the indices of two corners each
idx1 = ((20, 30, 25), (40, 35, 50))
idx2 = ((60, 55, 75), (65, 80, 85))
# get the pixel values in the specified regions
region1 = img[idx1[0][0]:idx1[1][0], idx1[0][1]:idx1[1][1], idx1[0][2]:idx1[1][2]]
region2 = img[idx2[0][0]:idx2[1][0], idx2[0][1]:idx2[1][1], idx2[0][2]:idx2[1][2]]
# calculate the averages
avg1 = np.mean(region1)
avg2 = np.mean(region2)
avg1, avg2
# calculate differences
abs_diff = avg2 - avg1
rel_diff = 1 - avg1 / avg2
print(f'abs. diff.: {abs_diff:.4f}')
print(f'rel. diff.: {rel_diff:.4f}')