本文整理汇总了Python中matplotlib.figure.Figure.figimage方法的典型用法代码示例。如果您正苦于以下问题:Python Figure.figimage方法的具体用法?Python Figure.figimage怎么用?Python Figure.figimage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib.figure.Figure
的用法示例。
在下文中一共展示了Figure.figimage方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: processImage
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def processImage(self, fileBuffer):
# tmp_name = uuid.uuid4().__str__() + ".png"
try:
image = Image.open(fileBuffer)
image.thumbnail(self.size)
converted = image.convert("L")
# converted = ImageEnhance.Contrast(converted).enhance(1.1)
# converted = ImageEnhance.Brightness(converted).enhance(1.1)
converted = ImageEnhance.Sharpness(converted).enhance(1.4)
# image = np.array(converted)
image = matplotlib.image.pil_to_array(converted)
binary_adaptive = threshold_adaptive(image, 40, offset=10)
figsize = [x / float(self._dpi) for x in (binary_adaptive.shape[1], binary_adaptive.shape[0])]
fig = Figure(figsize=figsize, dpi=self._dpi, frameon=False)
canvas = FigureCanvasAgg(fig)
fig.figimage(binary_adaptive)
output = StringIO()
fig.savefig(output, format='png')
output.seek(0)
self.outfiles.append(output)
except IOError:
self.invalidFiles.append(fileBuffer)
示例2: imsave
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, origin=None):
"""
Saves a 2D :class:`numpy.array` as an image with one pixel per element.
The output formats available depend on the backend being used.
Arguments:
*fname*:
A string containing a path to a filename, or a Python file-like object.
If *format* is *None* and *fname* is a string, the output
format is deduced from the extension of the filename.
*arr*:
A 2D array.
Keyword arguments:
*vmin*/*vmax*: [ None | scalar ]
*vmin* and *vmax* set the color scaling for the image by fixing the
values that map to the colormap color limits. If either *vmin* or *vmax*
is None, that limit is determined from the *arr* min/max value.
*cmap*:
cmap is a colors.Colormap instance, eg cm.jet.
If None, default to the rc image.cmap value.
*format*:
One of the file extensions supported by the active
backend. Most backends support png, pdf, ps, eps and svg.
*origin*
[ 'upper' | 'lower' ] Indicates where the [0,0] index of
the array is in the upper left or lower left corner of
the axes. Defaults to the rc image.origin value.
"""
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
fig = Figure(figsize=arr.shape[::-1], dpi=1, frameon=False)
canvas = FigureCanvas(fig)
fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin)
fig.savefig(fname, dpi=1, format=format)
示例3: save_as_plt
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def save_as_plt(self, fname, pixel_array=None, vmin=None, vmax=None,
cmap=None, format=None, origin=None):
""" This method saves the image from a numpy array using matplotlib
:param fname: Location and name of the image file to be saved.
:param pixel_array: Numpy pixel array, i.e. ``numpy()`` return value
:param vmin: matplotlib vmin
:param vmax: matplotlib vmax
:param cmap: matplotlib color map
:param format: matplotlib format
:param origin: matplotlib origin
This method will return True if successful
"""
from matplotlib.backends.backend_agg \
import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from pylab import cm
if pixel_array is None:
pixel_array = self.numpy()
if cmap is None:
cmap = cm.bone
fig = Figure(figsize=pixel_array.shape[::-1], dpi=1, frameon=False)
canvas = FigureCanvas(fig)
fig.figimage(pixel_array, cmap=cmap, vmin=vmin,
vmax=vmax, origin=origin)
fig.savefig(fname, dpi=1, format=format)
return True
示例4: GraphFrame
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
class GraphFrame(wx.Frame):
def __init__(self, maze_width=70, maze_height=70, magnification=8):
wx.Frame.__init__(self, None, -1, 'Maze Generator')
self.Bind(wx.EVT_CLOSE, self.OnClose, self)
self.running = False
self.maze_width = maze_width
self.maze_height = maze_height
self.magnification = magnification
sizer = wx.BoxSizer(wx.VERTICAL)
hSizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(hSizer)
btnStart = wx.Button(self, -1, "Start")
self.Bind(wx.EVT_BUTTON, self.OnStart, btnStart)
hSizer.Add(btnStart)
btnStop = wx.Button(self, -1, "Stop")
self.Bind(wx.EVT_BUTTON, self.OnStop, btnStop)
hSizer.Add(btnStop)
self.fig = Figure()
self.canvas = FigureCanvasWxAgg(self, -1, self.fig)
sizer.Add(self.canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
self.SetSizer(sizer)
self.SetSize((800, 500))
def OnClose(self, evt):
self.running = False
self.plot_thread.join()
evt.Skip()
def OnStart(self, evt):
self.Plot()
def OnStop(self, evt):
self.running = False
def Plot(self):
if self.running:
return
def thread():
self.running = True
for m in maze(self.maze_width, self.maze_height):
if not self.running:
break
wx.CallAfter(self.plot_data, magnify(m, magnification=self.magnification))
time.sleep(0.05)
self.plot_thread = threading.Thread(target=thread)
self.plot_thread.start()
def plot_data(self, snapshot):
self.fig.clear()
self.fig.figimage(snapshot, 0, 0, cmap=plt.cm.binary)
self.canvas.draw()
示例5: imsave
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None, origin=None):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
fig = Figure(figsize=arr.shape[::-1], dpi=1, frameon=False)
canvas = FigureCanvas(fig)
fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin)
fig.savefig(fname, dpi=1, format=format)
示例6: save_array_as_image
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def save_array_as_image(filename, array, colourmap=None, format=None, dpi=1, vmin=None, vmax=None, origin=None):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib import cm
figure = Figure(figsize=array.shape[::-1], dpi=1, frameon=False)
# canvas = FigureCanvas(figure) # essential even though it isn't used
FigureCanvas(figure) # essential even though it isn't used
figure.figimage(array, cmap=cm.get_cmap(colourmap), vmin=vmin, vmax=vmax, origin=origin)
figure.savefig(filename, dpi=dpi, format=format)
示例7: imsave
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
origin=None, dpi=100):
"""
Save an array as in image file.
The output formats available depend on the backend being used.
Arguments:
*fname*:
A string containing a path to a filename, or a Python file-like object.
If *format* is *None* and *fname* is a string, the output
format is deduced from the extension of the filename.
*arr*:
An MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA) array.
Keyword arguments:
*vmin*/*vmax*: [ None | scalar ]
*vmin* and *vmax* set the color scaling for the image by fixing the
values that map to the colormap color limits. If either *vmin*
or *vmax* is None, that limit is determined from the *arr*
min/max value.
*cmap*:
cmap is a colors.Colormap instance, e.g., cm.jet.
If None, default to the rc image.cmap value.
*format*:
One of the file extensions supported by the active
backend. Most backends support png, pdf, ps, eps and svg.
*origin*
[ 'upper' | 'lower' ] Indicates where the [0,0] index of
the array is in the upper left or lower left corner of
the axes. Defaults to the rc image.origin value.
*dpi*
The DPI to store in the metadata of the file. This does not affect the
resolution of the output image.
"""
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
# Fast path for saving to PNG
if (format == 'png' or format is None or
isinstance(fname, six.string_types) and
fname.lower().endswith('.png')):
image = AxesImage(None, cmap=cmap, origin=origin)
image.set_data(arr)
image.set_clim(vmin, vmax)
image.write_png(fname)
else:
fig = Figure(dpi=dpi, frameon=False)
FigureCanvas(fig)
fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin,
resize=True)
fig.savefig(fname, dpi=dpi, format=format, transparent=True)
示例8: _build_image
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def _build_image(data, cmap='gray'):
"""Build an image encoded in base64.
"""
import matplotlib.pyplot as plt
from matplotlib.figure import Figure
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
figsize = data.shape[::-1]
if figsize[0] == 1:
figsize = tuple(figsize[1:])
data = data[:, :, 0]
fig = Figure(figsize=figsize, dpi=1.0, frameon=False)
FigureCanvas(fig)
cmap = getattr(plt.cm, cmap, plt.cm.gray)
fig.figimage(data, cmap=cmap)
output = BytesIO()
fig.savefig(output, dpi=1.0, format='png')
return output.getvalue().encode('base64')
示例9: imsave
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def imsave(fname, arr, **kwargs):
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
from matplotlib.colors import ColorConverter as CC
C = CC()
import pylab
if pylab.isinteractive():
i_was_on = True
pylab.ioff()
else:
i_was_on = False
fig = Figure(figsize=arr.shape[::-1], dpi=1, frameon=False)
canvas = FigureCanvas(fig)
if 'background' in kwargs.keys():
if kwargs['background'] != 'transparent':
[r,g,b] = C.to_rgb(kwargs['background'])
BG = numpy.ones(shape=(arr.shape[0],arr.shape[1],3))
BG[:,:,0] = r
BG[:,:,1] = g
BG[:,:,2] = b
fig.figimage(BG)
fig.figimage(arr,
xo = kwargs.get('xo',0),
yo = kwargs.get('yo',0),
alpha = kwargs.get('alpha',None),
norm = kwargs.get('norm',None),
cmap = kwargs.get('cmap',None),
vmin = kwargs.get('vmin',None),
vmax = kwargs.get('vmax',None),
origin = kwargs.get('origin',None))
fig.savefig(fname,
dpi=1,
format = kwargs.get('format',None))
if i_was_on:
pylab.ion()
示例10: save
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def save(filename, np_array, png=False):
""" saves numpy array as bitmap and/or png image. A list of details
may be included to save relevant info about the images in a CSV file
of the same name. By default only a bitmap is produced.
Parameters
----------
filename : string
Filename (without extension).
np_array : numpy.array
2D numpy array (dtype=uint8) representing grayscale image to save.
png : bool
By default, a bmp file is produced. If png=True, a png file will be
retained along with the bitmap.
"""
value_min = 0
value_max = 255
color_map = 'gray'
fig = Figure(figsize=np_array.shape[::-1], dpi=1, frameon=False)
fig.canvas = FigureCanvas(fig)
fig.figimage(np_array, cmap=color_map, vmin=value_min,
vmax=value_max, origin=None)
fig.savefig(filename, dpi=1, format=None)
# save bitmap (convert from PNG)
img = PIL.Image.open(filename + '.png')
if len(img.split()) == 4: # prevent IOError: cannot write mode RGBA as BMP
r, g, b, a = img.split()
img = PIL.Image.merge("RGB", (r, g, b))
greyscale = img.convert("L") # L indicates PIL's greyscale mode
greyscale.save(filename + '.bmp')
# delete PNG
if not png:
os.remove(filename + '.png')
示例11: imsave
# 需要导入模块: from matplotlib.figure import Figure [as 别名]
# 或者: from matplotlib.figure.Figure import figimage [as 别名]
def imsave(fname, arr, vmin=None, vmax=None, cmap=None, format=None,
origin=None, dpi=100):
"""
Save an array as in image file.
The output formats available depend on the backend being used.
Arguments:
*fname*:
A string containing a path to a filename, or a Python file-like object.
If *format* is *None* and *fname* is a string, the output
format is deduced from the extension of the filename.
*arr*:
An MxN (luminance), MxNx3 (RGB) or MxNx4 (RGBA) array.
Keyword arguments:
*vmin*/*vmax*: [ None | scalar ]
*vmin* and *vmax* set the color scaling for the image by fixing the
values that map to the colormap color limits. If either *vmin* or *vmax*
is None, that limit is determined from the *arr* min/max value.
*cmap*:
cmap is a colors.Colormap instance, eg cm.jet.
If None, default to the rc image.cmap value.
*format*:
One of the file extensions supported by the active
backend. Most backends support png, pdf, ps, eps and svg.
*origin*
[ 'upper' | 'lower' ] Indicates where the [0,0] index of
the array is in the upper left or lower left corner of
the axes. Defaults to the rc image.origin value.
*dpi*
The DPI to store in the metadata of the file. This does not affect the
resolution of the output image.
"""
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure
figsize = [x / float(dpi) for x in (arr.shape[1], arr.shape[0])]
fig = Figure(figsize=figsize, dpi=dpi, frameon=False)
canvas = FigureCanvas(fig)
im = fig.figimage(arr, cmap=cmap, vmin=vmin, vmax=vmax, origin=origin)
fig.savefig(fname, dpi=dpi, format=format)