paul23
paul23

Reputation: 9435

Matplotlib (Python) normalizing data

Well I'm trying to normalize some (infrared) thermography data, to display it later.

However I'm stuck at normalizing, I could of course do it by hand, but I wonder why the matplotlib code is not working, the python code is shown below:

import numpy as N
import matplotlib.colors as colors

test2 = N.array([100, 10, 95])
norm = colors.Normalize(0,100)
for pix in N.nditer(test2, op_flags=['readwrite']):
    val = (norm.process_value(pix)[0])
    print (val)

img = norm.process_value(test2)[0]
print(img)

Now I expect vals OR img to show the correct processed data. Depending on what matplotlib.colors.Normalize.process_value actually should get as argument.

But in any case: both functions do not normalize and just return the original function.. Not on the [0, 1] interval at all.

Upvotes: 1

Views: 10371

Answers (1)

hitzg
hitzg

Reputation: 12701

The documentation of Normalize might be a bit deceiving here: process_value is a function which is only used for preprocessing (and static). The actual usage is described with this sentence:

A class which, when called, can normalize data into the [0.0, 1.0] interval.

Thus the normalization happens when you call the class:

import numpy as N
import matplotlib.colors as colors

test2 = N.array([100, 10, 95])
norm = colors.Normalize(0,100)
for pix in N.nditer(test2, op_flags=['readwrite']):
    val = (norm(pix))
    print (val)

img = norm(test2)
print(img)

Output:

1.0
0.1
0.95
[ 1.    0.1   0.95]

Upvotes: 1

Related Questions