I have a array which is created as below:
im = plt.array(Image.open('Mean.png').convert('L'))
I have to convert all its values for an specified range. To do this, I have this function:
def translate(value, inputMin, inputMax, outputMin, outputMax):
# Figure out how 'wide' each range is
leftSpan = inputMax - inputMin
rightSpan = outputMax - outputMin
# Convert the left range into a 0-1 range (float)
valueScaled = float(value - inputMin) / float(leftSpan)
# Convert the 0-1 range into a value in the right range.
return outputMin + (valueScaled * rightSpan)
In my specific problem I have to show this image contour:
plt.figure()
CS = plt.contour(im, origin='image', extent=[-1, 1, -1, 1])
plt.colorbar(CS, shrink=0.5, aspect=10)
plt.clabel(CS, inline=1, fontsize=10)
plt.savefig("ContourLevel2D.png")
But each grayscale value must be translate to the -1..1 range. I know that I can do something like this:
CS = plt.contour(im/100, origin='image', extent=[-1, 1, -1, 1])
Which divide each element of im by 100. But is there a similar/easy way to translate this values using the function I mentioned above?
Thanks in advance.