removed some extra files
This commit is contained in:
parent
8dbce440e4
commit
269374ef84
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,8 +0,0 @@
|
|||||||
ImageView
|
|
||||||
=========
|
|
||||||
|
|
||||||
.. autoclass:: pyqtgraph.ImageView
|
|
||||||
:members:
|
|
||||||
|
|
||||||
.. automethod:: pyqtgraph.ImageView.__init__
|
|
||||||
|
|
@ -1,158 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
|
||||||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
|
||||||
|
|
||||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
|
||||||
<head>
|
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
||||||
|
|
||||||
<title>ImageView — pyqtgraph v1.8 documentation</title>
|
|
||||||
<link rel="stylesheet" href="../_static/default.css" type="text/css" />
|
|
||||||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
|
||||||
<script type="text/javascript">
|
|
||||||
var DOCUMENTATION_OPTIONS = {
|
|
||||||
URL_ROOT: '../',
|
|
||||||
VERSION: '1.8',
|
|
||||||
COLLAPSE_INDEX: false,
|
|
||||||
FILE_SUFFIX: '.html',
|
|
||||||
HAS_SOURCE: true
|
|
||||||
};
|
|
||||||
</script>
|
|
||||||
<script type="text/javascript" src="../_static/jquery.js"></script>
|
|
||||||
<script type="text/javascript" src="../_static/underscore.js"></script>
|
|
||||||
<script type="text/javascript" src="../_static/doctools.js"></script>
|
|
||||||
<link rel="top" title="pyqtgraph v1.8 documentation" href="../index.html" />
|
|
||||||
<link rel="up" title="Pyqtgraph’s Widgets" href="index.html" />
|
|
||||||
<link rel="next" title="DataTreeWidget" href="datatreewidget.html" />
|
|
||||||
<link rel="prev" title="PlotWidget" href="plotwidget.html" />
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div class="related">
|
|
||||||
<h3>Navigation</h3>
|
|
||||||
<ul>
|
|
||||||
<li class="right" style="margin-right: 10px">
|
|
||||||
<a href="../genindex.html" title="General Index"
|
|
||||||
accesskey="I">index</a></li>
|
|
||||||
<li class="right" >
|
|
||||||
<a href="../py-modindex.html" title="Python Module Index"
|
|
||||||
>modules</a> |</li>
|
|
||||||
<li class="right" >
|
|
||||||
<a href="datatreewidget.html" title="DataTreeWidget"
|
|
||||||
accesskey="N">next</a> |</li>
|
|
||||||
<li class="right" >
|
|
||||||
<a href="plotwidget.html" title="PlotWidget"
|
|
||||||
accesskey="P">previous</a> |</li>
|
|
||||||
<li><a href="../index.html">pyqtgraph v1.8 documentation</a> »</li>
|
|
||||||
<li><a href="../apireference.html" >API Reference</a> »</li>
|
|
||||||
<li><a href="index.html" accesskey="U">Pyqtgraph’s Widgets</a> »</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="document">
|
|
||||||
<div class="documentwrapper">
|
|
||||||
<div class="bodywrapper">
|
|
||||||
<div class="body">
|
|
||||||
|
|
||||||
<div class="section" id="imageview">
|
|
||||||
<h1>ImageView<a class="headerlink" href="#imageview" title="Permalink to this headline">¶</a></h1>
|
|
||||||
<dl class="class">
|
|
||||||
<dt id="pyqtgraph.ImageView">
|
|
||||||
<em class="property">class </em><tt class="descclassname">pyqtgraph.</tt><tt class="descname">ImageView</tt><big>(</big><em>parent=None</em>, <em>name='ImageView'</em>, <em>*args</em><big>)</big><a class="headerlink" href="#pyqtgraph.ImageView" title="Permalink to this definition">¶</a></dt>
|
|
||||||
<dd><dl class="method">
|
|
||||||
<dt id="pyqtgraph.ImageView.__init__">
|
|
||||||
<tt class="descname">__init__</tt><big>(</big><em>parent=None</em>, <em>name='ImageView'</em>, <em>*args</em><big>)</big><a class="headerlink" href="#pyqtgraph.ImageView.__init__" title="Permalink to this definition">¶</a></dt>
|
|
||||||
<dd></dd></dl>
|
|
||||||
|
|
||||||
<dl class="method">
|
|
||||||
<dt id="pyqtgraph.ImageView.jumpFrames">
|
|
||||||
<tt class="descname">jumpFrames</tt><big>(</big><em>n</em><big>)</big><a class="headerlink" href="#pyqtgraph.ImageView.jumpFrames" title="Permalink to this definition">¶</a></dt>
|
|
||||||
<dd><p>If this is a video, move ahead n frames</p>
|
|
||||||
</dd></dl>
|
|
||||||
|
|
||||||
<dl class="method">
|
|
||||||
<dt id="pyqtgraph.ImageView.setImage">
|
|
||||||
<tt class="descname">setImage</tt><big>(</big><em>img</em>, <em>autoRange=True</em>, <em>autoLevels=True</em>, <em>levels=None</em>, <em>axes=None</em>, <em>xvals=None</em>, <em>pos=None</em>, <em>scale=None</em><big>)</big><a class="headerlink" href="#pyqtgraph.ImageView.setImage" title="Permalink to this definition">¶</a></dt>
|
|
||||||
<dd><p>Set the image to be displayed in the widget.
|
|
||||||
Options are:</p>
|
|
||||||
<blockquote>
|
|
||||||
<p>img: ndarray; the image to be displayed.
|
|
||||||
autoRange: bool; whether to scale/pan the view to fit the image.
|
|
||||||
autoLevels: bool; whether to update the white/black levels to fit the image.
|
|
||||||
levels: (min, max); the white and black level values to use.
|
|
||||||
axes: {‘t’:0, ‘x’:1, ‘y’:2, ‘c’:3}; Dictionary indicating the interpretation for each axis.</p>
|
|
||||||
<blockquote>
|
|
||||||
This is only needed to override the default guess.</blockquote>
|
|
||||||
</blockquote>
|
|
||||||
</dd></dl>
|
|
||||||
|
|
||||||
<dl class="method">
|
|
||||||
<dt id="pyqtgraph.ImageView.timeIndex">
|
|
||||||
<tt class="descname">timeIndex</tt><big>(</big><em>slider</em><big>)</big><a class="headerlink" href="#pyqtgraph.ImageView.timeIndex" title="Permalink to this definition">¶</a></dt>
|
|
||||||
<dd><p>Return the time and frame index indicated by a slider</p>
|
|
||||||
</dd></dl>
|
|
||||||
|
|
||||||
</dd></dl>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="sphinxsidebar">
|
|
||||||
<div class="sphinxsidebarwrapper">
|
|
||||||
<h4>Previous topic</h4>
|
|
||||||
<p class="topless"><a href="plotwidget.html"
|
|
||||||
title="previous chapter">PlotWidget</a></p>
|
|
||||||
<h4>Next topic</h4>
|
|
||||||
<p class="topless"><a href="datatreewidget.html"
|
|
||||||
title="next chapter">DataTreeWidget</a></p>
|
|
||||||
<h3>This Page</h3>
|
|
||||||
<ul class="this-page-menu">
|
|
||||||
<li><a href="../_sources/widgets/imageview.txt"
|
|
||||||
rel="nofollow">Show Source</a></li>
|
|
||||||
</ul>
|
|
||||||
<div id="searchbox" style="display: none">
|
|
||||||
<h3>Quick search</h3>
|
|
||||||
<form class="search" action="../search.html" method="get">
|
|
||||||
<input type="text" name="q" size="18" />
|
|
||||||
<input type="submit" value="Go" />
|
|
||||||
<input type="hidden" name="check_keywords" value="yes" />
|
|
||||||
<input type="hidden" name="area" value="default" />
|
|
||||||
</form>
|
|
||||||
<p class="searchtip" style="font-size: 90%">
|
|
||||||
Enter search terms or a module, class or function name.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<script type="text/javascript">$('#searchbox').show(0);</script>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="clearer"></div>
|
|
||||||
</div>
|
|
||||||
<div class="related">
|
|
||||||
<h3>Navigation</h3>
|
|
||||||
<ul>
|
|
||||||
<li class="right" style="margin-right: 10px">
|
|
||||||
<a href="../genindex.html" title="General Index"
|
|
||||||
>index</a></li>
|
|
||||||
<li class="right" >
|
|
||||||
<a href="../py-modindex.html" title="Python Module Index"
|
|
||||||
>modules</a> |</li>
|
|
||||||
<li class="right" >
|
|
||||||
<a href="datatreewidget.html" title="DataTreeWidget"
|
|
||||||
>next</a> |</li>
|
|
||||||
<li class="right" >
|
|
||||||
<a href="plotwidget.html" title="PlotWidget"
|
|
||||||
>previous</a> |</li>
|
|
||||||
<li><a href="../index.html">pyqtgraph v1.8 documentation</a> »</li>
|
|
||||||
<li><a href="../apireference.html" >API Reference</a> »</li>
|
|
||||||
<li><a href="index.html" >Pyqtgraph’s Widgets</a> »</li>
|
|
||||||
</ul>
|
|
||||||
</div>
|
|
||||||
<div class="footer">
|
|
||||||
© Copyright 2011, Luke Campagnola.
|
|
||||||
Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.1.
|
|
||||||
</div>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
@ -1,398 +0,0 @@
|
|||||||
from pyqtgraph.Qt import QtGui, QtCore
|
|
||||||
import numpy as np
|
|
||||||
try:
|
|
||||||
import scipy.weave as weave
|
|
||||||
from scipy.weave import converters
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
import pyqtgraph.functions as fn
|
|
||||||
import pyqtgraph.debug as debug
|
|
||||||
from GraphicsObject import GraphicsObject
|
|
||||||
|
|
||||||
__all__ = ['ImageItem']
|
|
||||||
class ImageItem(GraphicsObject):
|
|
||||||
"""
|
|
||||||
GraphicsObject displaying an image. Optimized for rapid update (ie video display)
|
|
||||||
|
|
||||||
"""
|
|
||||||
|
|
||||||
|
|
||||||
sigImageChanged = QtCore.Signal()
|
|
||||||
|
|
||||||
## performance gains from this are marginal, and it's rather unreliable.
|
|
||||||
useWeave = False
|
|
||||||
|
|
||||||
def __init__(self, image=None, copy=True, parent=None, border=None, mode=None, *args):
|
|
||||||
#QObjectWorkaround.__init__(self)
|
|
||||||
GraphicsObject.__init__(self)
|
|
||||||
#self.pixmapItem = QtGui.QGraphicsPixmapItem(self)
|
|
||||||
self.qimage = QtGui.QImage()
|
|
||||||
self.pixmap = None
|
|
||||||
self.paintMode = mode
|
|
||||||
#self.useWeave = True
|
|
||||||
self.blackLevel = None
|
|
||||||
self.whiteLevel = None
|
|
||||||
self.alpha = 1.0
|
|
||||||
self.image = None
|
|
||||||
self.clipLevel = None
|
|
||||||
self.drawKernel = None
|
|
||||||
if border is not None:
|
|
||||||
border = fn.mkPen(border)
|
|
||||||
self.border = border
|
|
||||||
|
|
||||||
#QtGui.QGraphicsPixmapItem.__init__(self, parent, *args)
|
|
||||||
#self.pixmapItem = QtGui.QGraphicsPixmapItem(self)
|
|
||||||
if image is not None:
|
|
||||||
self.updateImage(image, copy, autoRange=True)
|
|
||||||
#self.setCacheMode(QtGui.QGraphicsItem.DeviceCoordinateCache)
|
|
||||||
|
|
||||||
#self.item = QtGui.QGraphicsPixmapItem(parent=self)
|
|
||||||
|
|
||||||
def setCompositionMode(self, mode):
|
|
||||||
self.paintMode = mode
|
|
||||||
self.update()
|
|
||||||
|
|
||||||
def setAlpha(self, alpha):
|
|
||||||
self.alpha = alpha
|
|
||||||
self.updateImage()
|
|
||||||
|
|
||||||
#def boundingRect(self):
|
|
||||||
#return self.pixmapItem.boundingRect()
|
|
||||||
#return QtCore.QRectF(0, 0, self.qimage.width(), self.qimage.height())
|
|
||||||
|
|
||||||
def width(self):
|
|
||||||
if self.pixmap is None:
|
|
||||||
return None
|
|
||||||
return self.pixmap.width()
|
|
||||||
|
|
||||||
def height(self):
|
|
||||||
if self.pixmap is None:
|
|
||||||
return None
|
|
||||||
return self.pixmap.height()
|
|
||||||
|
|
||||||
def boundingRect(self):
|
|
||||||
if self.pixmap is None:
|
|
||||||
return QtCore.QRectF(0., 0., 0., 0.)
|
|
||||||
return QtCore.QRectF(0., 0., float(self.width()), float(self.height()))
|
|
||||||
|
|
||||||
def setClipLevel(self, level=None):
|
|
||||||
self.clipLevel = level
|
|
||||||
|
|
||||||
#def paint(self, p, opt, widget):
|
|
||||||
#pass
|
|
||||||
#if self.pixmap is not None:
|
|
||||||
#p.drawPixmap(0, 0, self.pixmap)
|
|
||||||
#print "paint"
|
|
||||||
|
|
||||||
def setLevels(self, white=None, black=None):
|
|
||||||
if white is not None:
|
|
||||||
self.whiteLevel = white
|
|
||||||
if black is not None:
|
|
||||||
self.blackLevel = black
|
|
||||||
self.updateImage()
|
|
||||||
|
|
||||||
def getLevels(self):
|
|
||||||
return self.whiteLevel, self.blackLevel
|
|
||||||
|
|
||||||
def updateImage(self, *args, **kargs):
|
|
||||||
## can we make any assumptions here that speed things up?
|
|
||||||
## dtype, range, size are all the same?
|
|
||||||
defaults = {
|
|
||||||
'autoRange': False,
|
|
||||||
}
|
|
||||||
defaults.update(kargs)
|
|
||||||
return self.setImage(*args, **defaults)
|
|
||||||
|
|
||||||
def setImage(self, image=None, copy=True, autoRange=True, clipMask=None, white=None, black=None, axes=None):
|
|
||||||
prof = debug.Profiler('ImageItem.updateImage 0x%x' %id(self))
|
|
||||||
#debug.printTrace()
|
|
||||||
if axes is None:
|
|
||||||
axh = {'x': 0, 'y': 1, 'c': 2}
|
|
||||||
else:
|
|
||||||
axh = axes
|
|
||||||
#print "Update image", black, white
|
|
||||||
if white is not None:
|
|
||||||
self.whiteLevel = white
|
|
||||||
if black is not None:
|
|
||||||
self.blackLevel = black
|
|
||||||
|
|
||||||
gotNewData = False
|
|
||||||
if image is None:
|
|
||||||
if self.image is None:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
gotNewData = True
|
|
||||||
if self.image is None or image.shape != self.image.shape:
|
|
||||||
self.prepareGeometryChange()
|
|
||||||
if copy:
|
|
||||||
self.image = image.view(np.ndarray).copy()
|
|
||||||
else:
|
|
||||||
self.image = image.view(np.ndarray)
|
|
||||||
#print " image max:", self.image.max(), "min:", self.image.min()
|
|
||||||
prof.mark('1')
|
|
||||||
|
|
||||||
# Determine scale factors
|
|
||||||
if autoRange or self.blackLevel is None:
|
|
||||||
if self.image.dtype is np.ubyte:
|
|
||||||
self.blackLevel = 0
|
|
||||||
self.whiteLevel = 255
|
|
||||||
else:
|
|
||||||
self.blackLevel = self.image.min()
|
|
||||||
self.whiteLevel = self.image.max()
|
|
||||||
#print "Image item using", self.blackLevel, self.whiteLevel
|
|
||||||
|
|
||||||
if self.blackLevel != self.whiteLevel:
|
|
||||||
scale = 255. / (self.whiteLevel - self.blackLevel)
|
|
||||||
else:
|
|
||||||
scale = 0.
|
|
||||||
|
|
||||||
prof.mark('2')
|
|
||||||
|
|
||||||
## Recolor and convert to 8 bit per channel
|
|
||||||
# Try using weave, then fall back to python
|
|
||||||
shape = self.image.shape
|
|
||||||
black = float(self.blackLevel)
|
|
||||||
white = float(self.whiteLevel)
|
|
||||||
|
|
||||||
if black == 0 and white == 255 and self.image.dtype == np.ubyte:
|
|
||||||
im = self.image
|
|
||||||
elif self.image.dtype in [np.ubyte, np.uint16]:
|
|
||||||
# use lookup table instead
|
|
||||||
npts = 2**(self.image.itemsize * 8)
|
|
||||||
lut = self.getLookupTable(npts, black, white)
|
|
||||||
im = lut[self.image]
|
|
||||||
else:
|
|
||||||
im = self.applyColorScaling(self.image, black, scale)
|
|
||||||
|
|
||||||
prof.mark('3')
|
|
||||||
|
|
||||||
try:
|
|
||||||
im1 = np.empty((im.shape[axh['y']], im.shape[axh['x']], 4), dtype=np.ubyte)
|
|
||||||
except:
|
|
||||||
print im.shape, axh
|
|
||||||
raise
|
|
||||||
alpha = np.clip(int(255 * self.alpha), 0, 255)
|
|
||||||
prof.mark('4')
|
|
||||||
# Fill image
|
|
||||||
if im.ndim == 2:
|
|
||||||
im2 = im.transpose(axh['y'], axh['x'])
|
|
||||||
im1[..., 0] = im2
|
|
||||||
im1[..., 1] = im2
|
|
||||||
im1[..., 2] = im2
|
|
||||||
im1[..., 3] = alpha
|
|
||||||
elif im.ndim == 3: #color image
|
|
||||||
im2 = im.transpose(axh['y'], axh['x'], axh['c'])
|
|
||||||
if im2.shape[2] > 4:
|
|
||||||
raise Exception("ImageItem got image with more than 4 color channels (shape is %s; axes are %s)" % (str(im.shape), str(axh)))
|
|
||||||
## [B G R A] Reorder colors
|
|
||||||
order = [2,1,0,3] ## for some reason, the colors line up as BGR in the final image.
|
|
||||||
|
|
||||||
for i in range(0, im.shape[axh['c']]):
|
|
||||||
im1[..., order[i]] = im2[..., i]
|
|
||||||
|
|
||||||
## fill in unused channels with 0 or alpha
|
|
||||||
for i in range(im.shape[axh['c']], 3):
|
|
||||||
im1[..., i] = 0
|
|
||||||
if im.shape[axh['c']] < 4:
|
|
||||||
im1[..., 3] = alpha
|
|
||||||
|
|
||||||
else:
|
|
||||||
raise Exception("Image must be 2 or 3 dimensions")
|
|
||||||
#self.im1 = im1
|
|
||||||
# Display image
|
|
||||||
prof.mark('5')
|
|
||||||
if self.clipLevel is not None or clipMask is not None:
|
|
||||||
if clipMask is not None:
|
|
||||||
mask = clipMask.transpose()
|
|
||||||
else:
|
|
||||||
mask = (self.image < self.clipLevel).transpose()
|
|
||||||
im1[..., 0][mask] *= 0.5
|
|
||||||
im1[..., 1][mask] *= 0.5
|
|
||||||
im1[..., 2][mask] = 255
|
|
||||||
prof.mark('6')
|
|
||||||
#print "Final image:", im1.dtype, im1.min(), im1.max(), im1.shape
|
|
||||||
self.ims = im1.tostring() ## Must be held in memory here because qImage won't do it for us :(
|
|
||||||
prof.mark('7')
|
|
||||||
qimage = QtGui.QImage(buffer(self.ims), im1.shape[1], im1.shape[0], QtGui.QImage.Format_ARGB32)
|
|
||||||
prof.mark('8')
|
|
||||||
self.pixmap = QtGui.QPixmap.fromImage(qimage)
|
|
||||||
prof.mark('9')
|
|
||||||
##del self.ims
|
|
||||||
#self.item.setPixmap(self.pixmap)
|
|
||||||
|
|
||||||
self.update()
|
|
||||||
prof.mark('10')
|
|
||||||
|
|
||||||
if gotNewData:
|
|
||||||
#self.emit(QtCore.SIGNAL('imageChanged'))
|
|
||||||
self.sigImageChanged.emit()
|
|
||||||
|
|
||||||
prof.finish()
|
|
||||||
|
|
||||||
def getLookupTable(self, num, black, white):
|
|
||||||
num = int(num)
|
|
||||||
black = int(black)
|
|
||||||
white = int(white)
|
|
||||||
if white < black:
|
|
||||||
b = black
|
|
||||||
black = white
|
|
||||||
white = b
|
|
||||||
key = (num, black, white)
|
|
||||||
lut = np.empty(num, dtype=np.ubyte)
|
|
||||||
lut[:black] = 0
|
|
||||||
rng = lut[black:white]
|
|
||||||
try:
|
|
||||||
rng[:] = np.linspace(0, 255, white-black)[:len(rng)]
|
|
||||||
except:
|
|
||||||
print key, rng.shape
|
|
||||||
lut[white:] = 255
|
|
||||||
return lut
|
|
||||||
|
|
||||||
|
|
||||||
def applyColorScaling(self, img, offset, scale):
|
|
||||||
try:
|
|
||||||
if not ImageItem.useWeave:
|
|
||||||
raise Exception('Skipping weave compile')
|
|
||||||
#sim = np.ascontiguousarray(self.image) ## should not be needed
|
|
||||||
sim = img.reshape(img.size)
|
|
||||||
#sim.shape = sim.size
|
|
||||||
im = np.empty(sim.shape, dtype=np.ubyte)
|
|
||||||
n = im.size
|
|
||||||
|
|
||||||
code = """
|
|
||||||
for( int i=0; i<n; i++ ) {
|
|
||||||
float a = (sim(i)-offset) * (float)scale;
|
|
||||||
if( a > 255.0 )
|
|
||||||
a = 255.0;
|
|
||||||
else if( a < 0.0 )
|
|
||||||
a = 0.0;
|
|
||||||
im(i) = a;
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
|
|
||||||
weave.inline(code, ['sim', 'im', 'n', 'offset', 'scale'], type_converters=converters.blitz, compiler = 'gcc')
|
|
||||||
#sim.shape = shape
|
|
||||||
im.shape = img.shape
|
|
||||||
except:
|
|
||||||
if ImageItem.useWeave:
|
|
||||||
ImageItem.useWeave = False
|
|
||||||
#sys.excepthook(*sys.exc_info())
|
|
||||||
#print "=============================================================================="
|
|
||||||
#print "Weave compile failed, falling back to slower version."
|
|
||||||
#img.shape = shape
|
|
||||||
im = ((img - offset) * scale).clip(0.,255.).astype(np.ubyte)
|
|
||||||
return im
|
|
||||||
|
|
||||||
|
|
||||||
def getPixmap(self):
|
|
||||||
return self.pixmap.copy()
|
|
||||||
|
|
||||||
def getHistogram(self, bins=500, step=3):
|
|
||||||
"""returns x and y arrays containing the histogram values for the current image.
|
|
||||||
The step argument causes pixels to be skipped when computing the histogram to save time."""
|
|
||||||
if self.image is None:
|
|
||||||
return None,None
|
|
||||||
stepData = self.image[::step, ::step]
|
|
||||||
hist = np.histogram(stepData, bins=bins)
|
|
||||||
return hist[1][:-1], hist[0]
|
|
||||||
|
|
||||||
def setPxMode(self, b):
|
|
||||||
"""Set whether the item ignores transformations and draws directly to screen pixels."""
|
|
||||||
self.setFlag(self.ItemIgnoresTransformations, b)
|
|
||||||
|
|
||||||
def setScaledMode(self):
|
|
||||||
self.setPxMode(False)
|
|
||||||
|
|
||||||
def mousePressEvent(self, ev):
|
|
||||||
if self.drawKernel is not None and ev.button() == QtCore.Qt.LeftButton:
|
|
||||||
self.drawAt(ev.pos(), ev)
|
|
||||||
ev.accept()
|
|
||||||
else:
|
|
||||||
ev.ignore()
|
|
||||||
|
|
||||||
def mouseMoveEvent(self, ev):
|
|
||||||
#print "mouse move", ev.pos()
|
|
||||||
if self.drawKernel is not None:
|
|
||||||
self.drawAt(ev.pos(), ev)
|
|
||||||
|
|
||||||
def mouseReleaseEvent(self, ev):
|
|
||||||
pass
|
|
||||||
|
|
||||||
def tabletEvent(self, ev):
|
|
||||||
print ev.device()
|
|
||||||
print ev.pointerType()
|
|
||||||
print ev.pressure()
|
|
||||||
|
|
||||||
def drawAt(self, pos, ev=None):
|
|
||||||
pos = [int(pos.x()), int(pos.y())]
|
|
||||||
dk = self.drawKernel
|
|
||||||
kc = self.drawKernelCenter
|
|
||||||
sx = [0,dk.shape[0]]
|
|
||||||
sy = [0,dk.shape[1]]
|
|
||||||
tx = [pos[0] - kc[0], pos[0] - kc[0]+ dk.shape[0]]
|
|
||||||
ty = [pos[1] - kc[1], pos[1] - kc[1]+ dk.shape[1]]
|
|
||||||
|
|
||||||
for i in [0,1]:
|
|
||||||
dx1 = -min(0, tx[i])
|
|
||||||
dx2 = min(0, self.image.shape[0]-tx[i])
|
|
||||||
tx[i] += dx1+dx2
|
|
||||||
sx[i] += dx1+dx2
|
|
||||||
|
|
||||||
dy1 = -min(0, ty[i])
|
|
||||||
dy2 = min(0, self.image.shape[1]-ty[i])
|
|
||||||
ty[i] += dy1+dy2
|
|
||||||
sy[i] += dy1+dy2
|
|
||||||
|
|
||||||
#print sx
|
|
||||||
#print sy
|
|
||||||
#print tx
|
|
||||||
#print ty
|
|
||||||
#print self.image.shape
|
|
||||||
#print self.image[tx[0]:tx[1], ty[0]:ty[1]].shape
|
|
||||||
#print dk[sx[0]:sx[1], sy[0]:sy[1]].shape
|
|
||||||
ts = (slice(tx[0],tx[1]), slice(ty[0],ty[1]))
|
|
||||||
ss = (slice(sx[0],sx[1]), slice(sy[0],sy[1]))
|
|
||||||
#src = dk[sx[0]:sx[1], sy[0]:sy[1]]
|
|
||||||
#mask = self.drawMask[sx[0]:sx[1], sy[0]:sy[1]]
|
|
||||||
mask = self.drawMask
|
|
||||||
src = dk
|
|
||||||
#print self.image[ts].shape, src.shape
|
|
||||||
|
|
||||||
if callable(self.drawMode):
|
|
||||||
self.drawMode(dk, self.image, mask, ss, ts, ev)
|
|
||||||
else:
|
|
||||||
src = src[ss]
|
|
||||||
if self.drawMode == 'set':
|
|
||||||
if mask is not None:
|
|
||||||
mask = mask[ss]
|
|
||||||
self.image[ts] = self.image[ts] * (1-mask) + src * mask
|
|
||||||
else:
|
|
||||||
self.image[ts] = src
|
|
||||||
elif self.drawMode == 'add':
|
|
||||||
self.image[ts] += src
|
|
||||||
else:
|
|
||||||
raise Exception("Unknown draw mode '%s'" % self.drawMode)
|
|
||||||
self.updateImage()
|
|
||||||
|
|
||||||
def setDrawKernel(self, kernel=None, mask=None, center=(0,0), mode='set'):
|
|
||||||
self.drawKernel = kernel
|
|
||||||
self.drawKernelCenter = center
|
|
||||||
self.drawMode = mode
|
|
||||||
self.drawMask = mask
|
|
||||||
|
|
||||||
def paint(self, p, *args):
|
|
||||||
|
|
||||||
#QtGui.QGraphicsPixmapItem.paint(self, p, *args)
|
|
||||||
if self.pixmap is None:
|
|
||||||
return
|
|
||||||
if self.paintMode is not None:
|
|
||||||
p.setCompositionMode(self.paintMode)
|
|
||||||
p.drawPixmap(self.boundingRect(), self.pixmap, QtCore.QRectF(0, 0, self.pixmap.width(), self.pixmap.height()))
|
|
||||||
if self.border is not None:
|
|
||||||
p.setPen(self.border)
|
|
||||||
p.drawRect(self.boundingRect())
|
|
||||||
|
|
||||||
def pixelSize(self):
|
|
||||||
"""return size of a single pixel in the image"""
|
|
||||||
br = self.sceneBoundingRect()
|
|
||||||
return br.width()/self.pixmap.width(), br.height()/self.pixmap.height()
|
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user