Hadi GhahremanNezhad
Hadi GhahremanNezhad

Reputation: 2455

How to normalize images using mean and std?

I am trying to use numpy to normalize a set of MRI images, but it seems to be not working. The simplified code is:

img = nib.load(img_path).get_data() #img is a numpy array
print("pre\n============================")
plt.imshow(img[:,:,100])
plt.ioff()
plt.show()

img = (img - 47.08389527329749)/125.64995558389833

print("post\n============================")
plt.imshow(img[:,:,100])
plt.ioff()
plt.show()

To calculate the mean and std values with numpy:

mean = np.mean(image_list) # 47.08389527329749
std = np.std(image_list) # 125.64995558389833

But the result images are similar:

pre:

enter image description here

post:

enter image description here

Which part am I doing wrong here?

Upvotes: 1

Views: 3225

Answers (1)

Alexis Pister
Alexis Pister

Reputation: 499

You should print the numerical values of your matrix and not plot the images. I think the process went fine. Normalization has the purpose to center the values in a given interval, here the values of a standard normal distribution, and set the same range if you use several attributes. It is not supposed to remove the relative differences between values of a given attribute, here the pixels intensities.

Upvotes: 1

Related Questions