def updateImage(self, dummy=None): if self._images is None: raise RuntimeError("No images set!") images = list() contours = dict() ccolor = AtConfig().contours_complementary_color for i, n in self.checkedChannels().iteritems(): # converting the gray image to the color defined in the button color = self.widgetAt(i, 1).currentColor() image = self._images[i] lut = self.enhancer.lut_from_color(i, color, 256) image.setColorTable(lut) images.append(image) if self._contours is not None: if ccolor: color = AtPainter.complementaryColor(color) contours[color] = self._contours[n] pixmap = AtPainter.blend(images) # sometimes qt segfaults when drawing polygons if AtConfig().draw_contours_in_pixmap: pixmap = AtPainter.drawContours(pixmap, contours) self.newContourImage.emit(pixmap, None) else: self.newContourImage.emit(pixmap, contours)
def __init__(self, item, *args, **kw): super(CellGraphicsItem, self).__init__(*args, **kw) self.setAcceptHoverEvents(True) self._pixmap = None self._mask = None self.class_ = UnClassified self.shape = item.image.shape self.setPixmap(item.pixmap) self.features = item.features self.frame = item.frame self.objid = item.objid self.index = item.index self.hash = item.hash self.path = item.path self.treatment = item.treatment self.qimages = list(item.iterQImages()) self._is_training_sample = False ccolor = AtConfig().contours_complementary_color if item.contour is not None: for contour, color in item.iterContours(): if ccolor: color = AtPainter.complementaryColor(color) self.setContour(contour, color) self._addDescription() self.setFlag(self.ItemIsSelectable) self.sortkey = None
def enhancePixmap(self, index, lut): self.qimages[index].setColorTable(lut) qimages = [img for img, flag in zip(self.qimages, self._image_flags) if flag] if not qimages: self._pixmap = QtGui.QPixmap(self.shape[0], self.shape[1]) self._pixmap.fill(Colors.black) else: self._pixmap = AtPainter.blend(qimages) self._pixmapItem.setPixmap(self._pixmap)
def updateView(self, dummy=None): if self._images is None: raise RuntimeError("No images set!") images = list() contours = dict() ccolor = AtConfig().contours_complementary_color for i, n in self.checkedChannels().iteritems(): # converting the gray image to the color defined in the button image = self._images[i] lut = self.lut_from_channel(i, 256) image.setColorTable(lut) images.append(image) if self._contours is not None: color = QtGui.QColor(self.colors[n]) if ccolor: color = AtPainter.complementaryColor(color) contours[color] = self._contours[n] pixmap = AtPainter.blend(images) self.newContourImage.emit(pixmap, contours)
def iterQImages(self): """Iterator over qimages (indexed_8) with colortable set.""" iinfo = np.iinfo(self.image.dtype) ncolors = abs(iinfo.max - iinfo.min) + 1 luts = [AtPainter.lut_from_color(QColor(c), ncolors) for c in self.colors] for i, color in enumerate(self.colors): if self.image.ndim == 2: image = gray2qimage(self.image, normalize=False) else: image = gray2qimage(self.image[:, :, i], normalize=False) image.setColorTable(luts[i]) yield image
def iterQImages(self): """Iterator over qimages (indexed_8) with colortable set.""" iinfo = np.iinfo(self.image.dtype) ncolors = abs(iinfo.max - iinfo.min) + 1 luts = [ AtPainter.lut_from_color(QColor(c), ncolors) for c in self.colors ] for i, color in enumerate(self.colors): if self.image.ndim == 2: image = gray2qimage(self.image, normalize=False) else: image = gray2qimage(self.image[:, :, i], normalize=False) image.setColorTable(luts[i]) yield image
def pixmap(self): # XXX be aware of thread safety images = list(self.iterQImages()) return AtPainter.blend(images)
def enhancePixmap(self, index, lut): self.qimages[index].setColorTable(lut) self._pixmap = AtPainter.blend(self.qimages) self._pixmapItem.setPixmap(self._pixmap)