A1g
A1g

Reputation: 93

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

Upvotes: 0

Views: 1236

Answers (1)

phyrox
phyrox

Reputation: 2449

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

Upvotes: 2

Related Questions