I have these medical raw data images which have .rawb instead of .jpg. I need to open and read this data which is 3D. My question is after opening this file into python I have to compare the pixel intensity (av. mean) of two different regions within this image.
Asked
Active
Viewed 383 times
1 Answers
0
For the second part (i.e. for once you have read the image into a numpy array), you could go about it as follows:
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}')

Michael Hodel
- 2,845
- 1
- 5
- 10