From: Daniel H. <dh...@gm...> - 2011-10-13 11:36:12
|
I was playing around with images.BboxImage, and found that if I displayed, say a 100x100 image at its native resolution (exactly 100x100 pixels on the plotting window), it was blurred. This is because of the interpolation jumping in and interpolating when it is not needed. This might not be the best way to fix, but it does work....in matplotlib 1.0.0, it is image.py around line 1102 (this is BboxImage.make_image). Just after numrows and numcols is set in that routine, do if (r-l) == numcols and (t-b) == numrows: im.set_interpolation(0) As you can see, all this does is just flip the interpolation off if the size of the image is the same size that it is about to be rendered as...and the regular interpolation is used otherwise. I do apologize for the lack of a proper patch, but for little things like this I think a word description works as well or better; I need to sit down and both learn git and set of a development environment for matplotlib, but after reading through the docs on the web site about it, decided that would take me more time than I had at the moment. In context: def make_image(self, renderer, magnification=1.0): if self._A is None: raise RuntimeError('You must first set the image array or the image attribute') if self._imcache is None: if self._A.dtype == np.uint8 and len(self._A.shape) == 3: im = _image.frombyte(self._A, 0) im.is_grayscale = False else: if self._rgbacache is None: x = self.to_rgba(self._A, self._alpha) self._rgbacache = x else: x = self._rgbacache im = _image.fromarray(x, 0) if len(self._A.shape) == 2: im.is_grayscale = self.cmap.is_gray() else: im.is_grayscale = False self._imcache = im if self.origin=='upper': im.flipud_in() else: im = self._imcache # image input dimensions im.reset_matrix() im.set_interpolation(self._interpd[self._interpolation]) im.set_resample(self._resample) l, b, r, t = self.get_window_extent(renderer).extents #bbox.extents widthDisplay = (round(r) + 0.5) - (round(l) - 0.5) heightDisplay = (round(t) + 0.5) - (round(b) - 0.5) widthDisplay *= magnification heightDisplay *= magnification numrows, numcols = self._A.shape[:2] if (r-l) == numcols and (t-b) == numrows: # <----------------- add this im.set_interpolation(0) #<-------------- and this # resize viewport to display rx = widthDisplay / numcols ry = heightDisplay / numrows #im.apply_scaling(rx*sx, ry*sy) im.apply_scaling(rx, ry) #im.resize(int(widthDisplay+0.5), int(heightDisplay+0.5), # norm=self._filternorm, radius=self._filterrad) im.resize(int(widthDisplay), int(heightDisplay), norm=self._filternorm, radius=self._filterrad) return im -- Daniel Hyams dh...@gm... |