本文整理汇总了Python中matplotlib._image.resample方法的典型用法代码示例。如果您正苦于以下问题:Python _image.resample方法的具体用法?Python _image.resample怎么用?Python _image.resample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib._image
的用法示例。
在下文中一共展示了_image.resample方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _rgb_to_rgba
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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
示例2: __init__
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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)
示例3: set_resample
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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
示例4: set_resample
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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
示例5: get_resample
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
def get_resample(self):
"""Return the image resample boolean."""
return self._resample
示例6: __init__
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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)
示例7: set_resample
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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
示例8: composite_images
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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
示例9: thumbnail
# 需要导入模块: from matplotlib import _image [as 别名]
# 或者: from matplotlib._image import resample [as 别名]
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, or Pillow-readable if you have Pillow_
installed.
.. _Pillow: http://python-pillow.org/
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