|
From: Christoph G. <cg...@uc...> - 2011-02-10 01:17:32
|
On 2/9/2011 4:29 PM, Benjamin Root wrote:
> On Wed, Feb 9, 2011 at 1:50 AM, Eric Firing <ef...@ha...
> <mailto:ef...@ha...>> wrote:
>
> On 02/08/2011 02:39 PM, Christoph Gohlke wrote:
> >
>
> >
> > Please consider the attached patch for the _image.frombyte
> function. It
> > avoids temporary copies in case of non-contiguous input arrays.
> Copying
> > a 1024x1024 slice out of a contiguous 4096x4096 RGBA or RGB array is
> > about 7x faster (a common case for zooming/panning). Copying
> contiguous
> > RGB input arrays is ~2x faster. Tested on win32-py2.7.
> >
> > Christoph
> >
>
> Thank you!
>
> Looks good, speeds up zooming and panning on large images as advertised.
> An 8000x8000 image is actually manageable now.
> interpolation='nearest' is still very slow until the image is
> substantially zoomed, but everything is quite quick with other
> interpolation styles. The slowness of 'nearest' looks like a basic
> characteristic of the implementation.
>
> I committed the patch in 8966.
>
> Before that I found and committed a big speed-up in Normalize.
>
> Eric
>
>
> Bug Report:
>
> At some point between the recent revision and r8934, setting the alpha
> value to anythhing but None will cause the image to not show. I suspect
> it has something to do with some of the recent revisions. Maybe the
> alpha values were being converted into an integer, causing them to be
> zero? Then again, even setting alpha to 1 will cause the image to
> disappear.
>
> Ideas? Thoughts? I included an example script below.
>
> Ben Root
>
>
> Example script:
>
>
> import numpy as np
> import matplotlib.pyplot as plt
>
> z = np.random.random((40, 50))
>
> fig = plt.figure()
> ax = fig.add_subplot(1, 2, 1)
> ax.imshow(z, alpha=1.0)
> ax.set_title('Blank!')
>
> ax = fig.add_subplot(1, 2, 2)
> ax.imshow(z, alpha=None)
> ax.set_title("Not Blank")
>
>
>
> plt.show()
>
>
>
This should fix it:
Index: lib/matplotlib/colors.py
===================================================================
--- lib/matplotlib/colors.py (revision 8967)
+++ lib/matplotlib/colors.py (working copy)
@@ -49,6 +49,7 @@
'chartreuse' are supported.
"""
import re
+import math
import numpy as np
from numpy import ma
import matplotlib.cbook as cbook
@@ -547,6 +548,8 @@
if alpha is not None:
alpha = min(alpha, 1.0) # alpha must be between 0 and 1
alpha = max(alpha, 0.0)
+ if bytes:
+ alpha = int(math.floor(alpha*255.9999999))
if (lut[-1] == 0).all():
lut[:-1, -1] = alpha
# All zeros is taken as a flag for the default bad
Christoph
|