[Scipy-tickets] [SciPy] #1748: scipy.misc.pilutil.bytescale problem

SciPy Trac scipy-tickets@scipy....
Fri Oct 19 14:44:48 CDT 2012


#1748: scipy.misc.pilutil.bytescale problem
------------------------------------------+---------------------------------
 Reporter:  kingson                       |       Owner:  somebody   
     Type:  defect                        |      Status:  new        
 Priority:  normal                        |   Milestone:  Unscheduled
Component:  Other                         |     Version:  0.11.0     
 Keywords:  scipy.misc.pilutil.bytescale  |  
------------------------------------------+---------------------------------
 {{{
 In [1]: from scipy.misc import bytescale
 In [2]: import numpy as np
 In [3]: a=np.array([40,60,120,200,300,500])
 In [4]: bytescale(a,cmin=60,cmax=300)
 Out[4]: array([236,   0,  64, 149, 255, 211], dtype=uint8)
 }}}
 The expected result is
 {{{
 array([0,   0,  64, 149, 255, 255], dtype=uint8)
 }}}

 The following patch does what I want.
 {{{
 --- /Library/Python/2.7/site-
 packages/scipy-0.11.0-py2.7-macosx-10.8-intel.egg/scipy//misc/pilutil.py
 2012-10-02 22:59:06.000000000 +0200
 +++ pilutil.py  2012-10-19 20:00:21.000000000 +0200
 @@ -73,8 +73,10 @@
      if cmin is None: cmin = data.min()
      if cmax is None: cmax = data.max()
      scale = high *1.0 / (cmax-cmin or 1)
 -    bytedata = ((data*1.0-cmin)*scale + 0.4999).astype(uint8)
 -    return bytedata + cast[uint8](low)
 +    bytedata = (data*1.0-cmin)*scale + 0.4999
 +    bytedata[bytedata > high] = high
 +    bytedata[bytedata < 0] = 0
 +    return cast[uint8](bytedata) + cast[uint8](low)
 }}}

-- 
Ticket URL: <http://projects.scipy.org/scipy/ticket/1748>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.


More information about the Scipy-tickets mailing list