Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.9k
Closed
Milestone
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.
importmatplotlibprintmatplotlib.__version__## 1.5.0importmatplotlib.imageasima=im.imread('lena.jpg')print'a: ',a.min(),a.max(),a.dtype## a: 0 255 uint8# This works fineim.imsave('test0.png',a)# vmin and vmax are ignored. Expected a saturated imageim.imsave('test1.png',a,vmin=0,vmax=128)a_expected=a.astype('float')/128im.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 originalim.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 fineim.imsave('test4.png',c)# vmin and vmax are ignored. Expected a saturated imageim.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