Python matplotlib._image.resample() Examples
The following are 30
code examples of matplotlib._image.resample().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib._image
, or try the search function
.
Example #1
Source File: image.py From CogAlg with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, filternorm=True, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) self._mouseover = True if origin is None: origin = rcParams['image.origin'] self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) self.set_interpolation(interpolation) self.set_resample(resample) self.axes = ax self._imcache = None self.update(kwargs)
Example #2
Source File: image.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_resample(self): """Return the image resample boolean.""" return self._resample
Example #3
Source File: image.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, bbox, cmap=None, norm=None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample=False, interp_at_native=True, **kwargs ): """ cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 interp_at_native is a flag that determines whether or not interpolation should still be applied when the image is displayed at its native resolution. A common use case for this is when displaying an image for annotational purposes; it is treated similarly to Photoshop (interpolation is only used when displaying the image at non-native resolutions). kwargs are an optional list of Artist keyword args """ super().__init__( None, cmap=cmap, norm=norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample=resample, **kwargs ) self.bbox = bbox self.interp_at_native = interp_at_native self._transform = IdentityTransform()
Example #4
Source File: image.py From coffeegrindsize with MIT License | 5 votes |
def _rgb_to_rgba(A): """ Convert an RGB image to RGBA, as required by the image resample C++ extension. """ rgba = np.zeros((A.shape[0], A.shape[1], 4), dtype=A.dtype) rgba[:, :, :3] = A if rgba.dtype == np.uint8: rgba[:, :, 3] = 255 else: rgba[:, :, 3] = 1.0 return rgba
Example #5
Source File: image.py From coffeegrindsize with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, filternorm=True, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) self._mouseover = True if origin is None: origin = rcParams['image.origin'] self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) self.set_interpolation(interpolation) self.set_resample(resample) self.axes = ax self._imcache = None self.update(kwargs)
Example #6
Source File: image.py From coffeegrindsize with MIT License | 5 votes |
def set_resample(self, v): """ Set whether or not image resampling is used. Parameters ---------- v : bool """ if v is None: v = rcParams['image.resample'] self._resample = v self.stale = True
Example #7
Source File: image.py From coffeegrindsize with MIT License | 5 votes |
def get_resample(self): """Return the image resample boolean.""" return self._resample
Example #8
Source File: image.py From coffeegrindsize with MIT License | 5 votes |
def __init__(self, bbox, cmap=None, norm=None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample=False, interp_at_native=True, **kwargs ): """ cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 interp_at_native is a flag that determines whether or not interpolation should still be applied when the image is displayed at its native resolution. A common use case for this is when displaying an image for annotational purposes; it is treated similarly to Photoshop (interpolation is only used when displaying the image at non-native resolutions). kwargs are an optional list of Artist keyword args """ super().__init__( None, cmap=cmap, norm=norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample=resample, **kwargs ) self.bbox = bbox self.interp_at_native = interp_at_native self._transform = IdentityTransform()
Example #9
Source File: image.py From CogAlg with MIT License | 5 votes |
def _rgb_to_rgba(A): """ Convert an RGB image to RGBA, as required by the image resample C++ extension. """ rgba = np.zeros((A.shape[0], A.shape[1], 4), dtype=A.dtype) rgba[:, :, :3] = A if rgba.dtype == np.uint8: rgba[:, :, 3] = 255 else: rgba[:, :, 3] = 1.0 return rgba
Example #10
Source File: image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def _rgb_to_rgba(A): """ Convert an RGB image to RGBA, as required by the image resample C++ extension. """ rgba = np.zeros((A.shape[0], A.shape[1], 4), dtype=A.dtype) rgba[:, :, :3] = A if rgba.dtype == np.uint8: rgba[:, :, 3] = 255 else: rgba[:, :, 3] = 1.0 return rgba
Example #11
Source File: image.py From CogAlg with MIT License | 5 votes |
def set_resample(self, v): """ Set whether image resampling is used. Parameters ---------- v : bool or None If None, use :rc:`image.resample` = True. """ if v is None: v = rcParams['image.resample'] self._resample = v self.stale = True
Example #12
Source File: image.py From CogAlg with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, extent=None, filternorm=1, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ self._extent = extent super().__init__( ax, cmap=cmap, norm=norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample=resample, **kwargs )
Example #13
Source File: image.py From twitter-stock-recommendation with MIT License | 5 votes |
def _rgb_to_rgba(A): """ Convert an RGB image to RGBA, as required by the image resample C++ extension. """ rgba = np.zeros((A.shape[0], A.shape[1], 4), dtype=A.dtype) rgba[:, :, :3] = A if rgba.dtype == np.uint8: rgba[:, :, 3] = 255 else: rgba[:, :, 3] = 1.0 return rgba
Example #14
Source File: image.py From twitter-stock-recommendation with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) self._mouseover = True if origin is None: origin = rcParams['image.origin'] self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) self.set_interpolation(interpolation) self.set_resample(resample) self.axes = ax self._imcache = None self.update(kwargs)
Example #15
Source File: image.py From twitter-stock-recommendation with MIT License | 5 votes |
def set_resample(self, v): """ Set whether or not image resampling is used. ACCEPTS: True|False """ if v is None: v = rcParams['image.resample'] self._resample = v self.stale = True
Example #16
Source File: image.py From twitter-stock-recommendation with MIT License | 5 votes |
def get_resample(self): """Return the image resample boolean.""" return self._resample
Example #17
Source File: image.py From twitter-stock-recommendation with MIT License | 5 votes |
def __init__(self, bbox, cmap=None, norm=None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample=False, interp_at_native=True, **kwargs ): """ cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 interp_at_native is a flag that determines whether or not interpolation should still be applied when the image is displayed at its native resolution. A common use case for this is when displaying an image for annotational purposes; it is treated similarly to Photoshop (interpolation is only used when displaying the image at non-native resolutions). kwargs are an optional list of Artist keyword args """ super(BboxImage, self).__init__( None, cmap=cmap, norm=norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample=resample, **kwargs ) self.bbox = bbox self.interp_at_native = interp_at_native self._transform = IdentityTransform()
Example #18
Source File: image.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, filternorm=True, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) self._mouseover = True if origin is None: origin = rcParams['image.origin'] self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) self.set_interpolation(interpolation) self.set_resample(resample) self.axes = ax self._imcache = None self.update(kwargs)
Example #19
Source File: image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, filternorm=True, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) self._mouseover = True if origin is None: origin = rcParams['image.origin'] self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) self.set_interpolation(interpolation) self.set_resample(resample) self.axes = ax self._imcache = None self.update(kwargs)
Example #20
Source File: image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def set_resample(self, v): """ Set whether image resampling is used. Parameters ---------- v : bool or None If None, use :rc:`image.resample` = True. """ if v is None: v = rcParams['image.resample'] self._resample = v self.stale = True
Example #21
Source File: image.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, extent=None, filternorm=1, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ self._extent = extent super().__init__( ax, cmap=cmap, norm=norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample=resample, **kwargs )
Example #22
Source File: image.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _rgb_to_rgba(A): """ Convert an RGB image to RGBA, as required by the image resample C++ extension. """ rgba = np.zeros((A.shape[0], A.shape[1], 4), dtype=A.dtype) rgba[:, :, :3] = A if rgba.dtype == np.uint8: rgba[:, :, 3] = 255 else: rgba[:, :, 3] = 1.0 return rgba
Example #23
Source File: image.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def __init__(self, ax, cmap=None, norm=None, interpolation=None, origin=None, filternorm=True, filterrad=4.0, resample=False, **kwargs ): """ interpolation and cmap default to their rc settings cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 extent is data axes (left, right, bottom, top) for making image plots registered with data plots. Default is to label the pixel centers with the zero-based row and column indices. Additional kwargs are matplotlib.artist properties """ martist.Artist.__init__(self) cm.ScalarMappable.__init__(self, norm, cmap) self._mouseover = True if origin is None: origin = rcParams['image.origin'] self.origin = origin self.set_filternorm(filternorm) self.set_filterrad(filterrad) self.set_interpolation(interpolation) self.set_resample(resample) self.axes = ax self._imcache = None self.update(kwargs)
Example #24
Source File: image.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def set_resample(self, v): """ Set whether or not image resampling is used. Parameters ---------- v : bool """ if v is None: v = rcParams['image.resample'] self._resample = v self.stale = True
Example #25
Source File: image.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def get_resample(self): """Return the image resample boolean.""" return self._resample
Example #26
Source File: image.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def __init__(self, bbox, cmap=None, norm=None, interpolation=None, origin=None, filternorm=1, filterrad=4.0, resample=False, interp_at_native=True, **kwargs ): """ cmap is a colors.Colormap instance norm is a colors.Normalize instance to map luminance to 0-1 interp_at_native is a flag that determines whether or not interpolation should still be applied when the image is displayed at its native resolution. A common use case for this is when displaying an image for annotational purposes; it is treated similarly to Photoshop (interpolation is only used when displaying the image at non-native resolutions). kwargs are an optional list of Artist keyword args """ super().__init__( None, cmap=cmap, norm=norm, interpolation=interpolation, origin=origin, filternorm=filternorm, filterrad=filterrad, resample=resample, **kwargs ) self.bbox = bbox self.interp_at_native = interp_at_native self._transform = IdentityTransform()
Example #27
Source File: image.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _rgb_to_rgba(A): """ Convert an RGB image to RGBA, as required by the image resample C++ extension. """ rgba = np.zeros((A.shape[0], A.shape[1], 4), dtype=A.dtype) rgba[:, :, :3] = A if rgba.dtype == np.uint8: rgba[:, :, 3] = 255 else: rgba[:, :, 3] = 1.0 return rgba
Example #28
Source File: image.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def set_resample(self, v): """ Set whether or not image resampling is used. Parameters ---------- v : bool """ if v is None: v = rcParams['image.resample'] self._resample = v self.stale = True
Example #29
Source File: image.py From coffeegrindsize with MIT License | 4 votes |
def thumbnail(infile, thumbfile, scale=0.1, interpolation='bilinear', preview=False): """ Make a thumbnail of image in *infile* with output filename *thumbfile*. See :doc:`/gallery/misc/image_thumbnail_sgskip`. Parameters ---------- infile : str or file-like The image file -- must be PNG, Pillow-readable if you have `Pillow <http://python-pillow.org/>`_ installed. thumbfile : str or file-like The thumbnail filename. scale : float, optional The scale factor for the thumbnail. interpolation : str, optional The interpolation scheme used in the resampling. See the *interpolation* parameter of `~.Axes.imshow` for possible values. preview : bool, optional If True, the default backend (presumably a user interface backend) will be used which will cause a figure to be raised if `~matplotlib.pyplot.show` is called. If it is False, the figure is created using `FigureCanvasBase` and the drawing backend is selected as `~matplotlib.figure.savefig` would normally do. Returns ------- figure : `~.figure.Figure` The figure instance containing the thumbnail. """ im = imread(infile) rows, cols, depth = im.shape # This doesn't really matter (it cancels in the end) but the API needs it. dpi = 100 height = rows / dpi * scale width = cols / dpi * scale if preview: # Let the UI backend do everything. import matplotlib.pyplot as plt fig = plt.figure(figsize=(width, height), dpi=dpi) else: from matplotlib.figure import Figure fig = Figure(figsize=(width, height), dpi=dpi) FigureCanvasBase(fig) ax = fig.add_axes([0, 0, 1, 1], aspect='auto', frameon=False, xticks=[], yticks=[]) ax.imshow(im, aspect='auto', resample=True, interpolation=interpolation) fig.savefig(thumbfile, dpi=dpi) return fig
Example #30
Source File: image.py From CogAlg with MIT License | 4 votes |
def composite_images(images, renderer, magnification=1.0): """ Composite a number of RGBA images into one. The images are composited in the order in which they appear in the `images` list. Parameters ---------- images : list of Images Each must have a `make_image` method. For each image, `can_composite` should return `True`, though this is not enforced by this function. Each image must have a purely affine transformation with no shear. renderer : RendererBase instance magnification : float The additional magnification to apply for the renderer in use. Returns ------- tuple : image, offset_x, offset_y Returns the tuple: - image: A numpy array of the same type as the input images. - offset_x, offset_y: The offset of the image (left, bottom) in the output figure. """ if len(images) == 0: return np.empty((0, 0, 4), dtype=np.uint8), 0, 0 parts = [] bboxes = [] for image in images: data, x, y, trans = image.make_image(renderer, magnification) if data is not None: x *= magnification y *= magnification parts.append((data, x, y, image.get_alpha() or 1.0)) bboxes.append( Bbox([[x, y], [x + data.shape[1], y + data.shape[0]]])) if len(parts) == 0: return np.empty((0, 0, 4), dtype=np.uint8), 0, 0 bbox = Bbox.union(bboxes) output = np.zeros( (int(bbox.height), int(bbox.width), 4), dtype=np.uint8) for data, x, y, alpha in parts: trans = Affine2D().translate(x - bbox.x0, y - bbox.y0) _image.resample(data, output, trans, _image.NEAREST, resample=False, alpha=alpha) return output, bbox.x0 / magnification, bbox.y0 / magnification