Пример #1
0
 def setColorMaskOpacity(self, value):
     """
     Set mask alpha channel to value * 255 / 100
     @param value:
     @type value: int in range 0..100
     """
     buf = QImageBuffer(self.mask)
     buf[:, :, 3] = np.uint8(value * 255 / 100)
Пример #2
0
 def setColorMaskOpacity(self, value):
     """
     Set mask alpha channel to value
     @param value:
     @type value: int in range 0..255
     """
     self.colorMaskOpacity = value
     buf = QImageBuffer(self.mask)
     buf[:, :, 3] = np.uint8(value)
Пример #3
0
 def updatePixmap(self, maskOnly=False):
     """
     Synchronize qPixmap and rPixmap with the image layer and mask.
     If maskOnly is True, cmImage is not updated.
     if maskIsEnabled is False, the mask is not shown.
     If maskIsEnabled is True, then
         - if maskIsSelected is True, the mask is drawn over
           the layer as a color mask.
         - if maskIsSelected is False, the mask is drawn as an
           opacity mask, setting image opacity to that of mask
           (mode DestinationIn). Mask color is no used.
     @param maskOnly: default False
     @type maskOnly: boolean
     """
     currentImage = self.getCurrentImage()
     # apply color management to presentation layer
     if icc.COLOR_MANAGE and self.parentImage is not None and getattr(
             self, 'role', None) == 'presentation':
         # CAUTION : reset alpha channel
         img = convertQImage(currentImage,
                             transformation=self.parentImage.
                             colorTransformation)  # time 0.66 s for 15 Mpx.
         # restore alpha channel
         # img = img.convertToFormat(currentImage.format()) # TODO 15/10/18 dome by convertQImage()
         buf0 = QImageBuffer(img)
         buf1 = QImageBuffer(currentImage)
         buf0[:, :, 3] = buf1[:, :, 3]
     else:
         img = currentImage
     qImg = img
     rImg = currentImage
     if self.maskIsEnabled:
         #qImg = vImage.visualizeMask(qImg, self.mask, color=self.maskIsSelected, clipping=self.isClipping)
         rImg = vImage.visualizeMask(rImg,
                                     self.mask,
                                     color=self.maskIsSelected,
                                     clipping=self.isClipping)
     self.qPixmap = QPixmap.fromImage(qImg)
     self.rPixmap = QPixmap.fromImage(rImg)
     self.setModified(True)
Пример #4
0
def PilImageToQImage(pilimg):
    """
    Converts a PIL image (mode RGB) to a QImage (format RGB32)
    @param pilimg: The PIL image, mode RGB
    @type pilimg: PIL image
    @return: the converted image
    @rtype: QImage
    """
    ############################################
    # CAUTION: PIL ImageQt causes a memory leak!!!
    # return ImageQt(pilimg)
    ############################################
    im_data = PilImgToRaw(pilimg)
    Qimg = QImage(im_data['im'].size[0], im_data['im'].size[1],
                  im_data['format'])
    buf = QImageBuffer(Qimg).ravel()
    buf[:] = np.frombuffer(im_data['data'], dtype=np.uint8)
    return Qimg
Пример #5
0
def QImageToPilImage(qimg):
    """
    Converts a QImage (format ARGB32or RGB32) to a PIL image
    @param qimg: The Qimage to convert
    @type qimg: Qimage
    @return: PIL image  object, mode RGB
    @rtype: PIL Image
    """
    a = QImageBuffer(qimg)
    if (qimg.format() == QImage.Format_ARGB32) or (qimg.format()
                                                   == QImage.Format_RGB32):
        # convert pixels from BGRA or BGRX to RGB
        a = np.ascontiguousarray(
            a[:, :, :3][:, :, ::-1]
        )  #ascontiguousarray is mandatory to speed up Image.fromArray (x3)
    else:
        raise ValueError("QImageToPilImage : unrecognized format : %s" %
                         qimg.Format())
    return Image.fromarray(a)