简体   繁体   中英

Get the ROI of two binary images and find difference of the mean image intesities between 2 ROI in python

I have 2 binary images (uint16, [512,512]) there ROI is at the exact center, how can I get ROI of both those binary images(image1.dat and image2.dat) and calculate the difference in mean intensities between those 2 ROI and save it as a PDF in python. Please help me out.

Thanks

You should use [numpy][1] .Loading and saving the images can be done with different modules. Here I am using numpy, but there are 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM