From: Eric F. <ef...@ha...> - 2006-02-22 08:31:14
|
Ray, You tripped over a bug in cm.py: when I added masked array support, I put the "x = ma.asarray(x)" too early in the to_rgba() method of ScalarMappable. It is fixed now in CVS. Thanks for finding the problem. If you want to try the fix in your version, in place of your workaround, here is the revised method: def to_rgba(self, x, alpha=1.0): # assume normalized rgb, rgba if len(x.shape)>2: return x x = ma.asarray(x) x = self.norm(x) x = self.cmap(x, alpha) return x Eric Thouis (Ray) Jones wrote: > Greetings, > > I searched the mail archive for information on this question, and > didn't find anything. Hopefully this hasn't been addressed elsewhere. > > I just spent a few hours tracking down a huge performance hit in > imshow(). I'm loading some image data via numarray's fromfile(), > stacking three imgaes to make an RGB, and showing it with imshow. > > My image loading code looks like this: > > def read_dib(filename): > f = open(filename, "rb") > fromfile(f, "UInt8", shape=(52, 1)) > im = fromfile(f, "UInt16", shape=(512, 512)) > if sys.byteorder == "big": > im.byteswap() > return im.astype('Float') / (2**12 - 1) > > I load three images, and put them into a NxMx3 float numarray, and > pass that to imshow. > > The performance drop is at this line in image.py: > im = _image.fromarray(x, 0) > > in AxesImage.make_image() > > I eventually tracked it down to x's type being <class > 'numarray.ma.MA.MaskedArray'>, which gets passed off to numarray's > NA_InputArray function, which chokes and calls setArrayFromSequence > (i.e., it's not using the fact that the input data is a numarray, and > is instead iterating over each element). This is taking around 30 > seconds to convert a 512x512x3 image on a new Intel iMac. > > I sped it up significantly by using this line instead: > > im = _image.fromarray(numerix.ma.filled(x,0), 0) > > Not that that's a good idea (but it works for me for now). > > There is no invalid data in my image. I'm not sure why it's ever > being turned into a masked array. > > I'm using matplotlib 0.86.2 and numarray-1.5.1, on OS X 10.3.5 on an Intel iMac. > > Any advice would be appreciated. > > Thanks, > Ray Jones > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://sel.as-us.falkag.net/sel?cmd=k&kid3432&bid#0486&dat1642 > _______________________________________________ > Matplotlib-users mailing list > Mat...@li... > https://lists.sourceforge.net/lists/listinfo/matplotlib-users |