Closed
Description
I'm sure this should be already known, but I couldn't find any issue related to this.
As far as I can tell, imsave and imshow expect arrays of floats to be from 0 to 1, and arrays of uint8 to be from 0 to 255. In both cases, the vmin and vmax arguments are completely ignored.
The following code shows the issue with imsave, and I'm attaching the resulting images. It was tested with matplotlib 1.5.0 and numpy 1.8.2.
import matplotlib
print matplotlib.__version__ ## 1.5.0
import matplotlib.image as im
a = im.imread('lena.jpg')
print 'a: ', a.min(), a.max(), a.dtype ## a: 0 255 uint8
# This works fine
im.imsave('test0.png', a)
# vmin and vmax are ignored. Expected a saturated image
im.imsave('test1.png', a, vmin=0, vmax=128)
a_expected = a.astype('float')/128
im.imsave('test1_expected.png', a_expected)
b = a.astype('float')
print 'b: ', b.min(), b.max(), b.dtype ## b: 0.0 255.0 float64
# imsave should use b.min() and b.max() as limits.
im.imsave('test2.png', b)
im.imsave('test2_expected.png', b/255)
# vmin and vmax are ignored. Expected an image equal to the original
im.imsave('test3.png', b, vmin=0, vmax=255)
im.imsave('test3_expected.png', b/255)
c = b / b.max()
print 'c: ', c.min(), c.max(), c.dtype ##c: 0.0 1.0 float64
# This works fine
im.imsave('test4.png', c)
# vmin and vmax are ignored. Expected a saturated image
im.imsave('test5.png', c, vmin=0, vmax=0.5)
im.imsave('test5_expected.png', c*2)
original
test0
test1
test1_expected
test2
test2_expected
test3
test3_expected
test4
test5
test5_expected
Metadata
Metadata
Assignees
Labels
No labels