Exemplo n.º 1
0
    def setImageLUT(self, image: np.ndarray) -> None:
        if image.dtype != self.current_dtype:
            return self.setImageFirstTime(image)

        if self.max_value is None:
            self.getMaxValue(image)

        if self.conversion is None:
            self.setPixmap(QtGui.QPixmap(array2qimage(image.astype(np.uint8))))
        else:
            self.setPixmap(
                QtGui.QPixmap(array2qimage(self.conversion[image[:, :, :3]])))
Exemplo n.º 2
0
    def setImageContrastSpread(self, image: np.ndarray) -> None:
        if self.max_value is None:
            self.getMaxValue(image)

        self.min, self.max = np.percentile(image, self.percentile).astype(int)
        self.conversion = generateLUT(self.min, self.max, self.gamma,
                                      self.max_value)
        if len(image.shape) > 2:
            self.setPixmap(
                QtGui.QPixmap(array2qimage(self.conversion[image[:, :, :3]])))
        else:
            self.setPixmap(
                QtGui.QPixmap(array2qimage(self.conversion[image[:, :,
                                                                 None]])))
Exemplo n.º 3
0
    def updateSlideView(self) -> None:
        if self.image is not None and not isinstance(self.image,
                                                     np.ndarray):  # is slide
            preview_rect = np.array(
                self.window.view.GetExtend(True)).astype("int") + np.array(
                    [0, 0, 1, 1])
            for i in [0, 1]:
                if preview_rect[i] < 0:
                    preview_rect[i] = 0
                if preview_rect[
                        i + 2] - preview_rect[i] > self.image.dimensions[i]:
                    preview_rect[
                        i + 2] = self.image.dimensions[i] + preview_rect[i]

            level = self.image.get_best_level_for_downsample(
                1 / self.window.view.getOriginScale())
            self.last_level = level
            downsample = self.image.level_downsamples[level]

            dimensions_downsampled = (np.array(preview_rect[2:4]) -
                                      np.array(preview_rect[:2])) / downsample
            # if the slide allows, we can also try to decode a slightly larger patch
            if getattr(self.image, "read_region_uncropped", None) is not None:
                data, loc = self.image.read_region_uncropped(
                    preview_rect[0:2], level,
                    dimensions_downsampled.astype("int"))
                preview_rect = [
                    loc[1] * downsample, loc[0] * downsample,
                    data.shape[1] * downsample, data.shape[0] * downsample
                ]
            else:
                data = np.asarray(
                    self.image.read_region(
                        preview_rect[0:2], level,
                        dimensions_downsampled.astype("int")))
            self.slice_zoom_image = data
            self.hist = np.histogram(self.slice_zoom_image.flatten(),
                                     bins=np.linspace(
                                         0, self.image_pixMapItem.max_value,
                                         256),
                                     density=True)
            if self.config.auto_contrast:
                self.image_pixMapItem.min, self.image_pixMapItem.max = np.percentile(
                    self.slice_zoom_image,
                    self.image_pixMapItem.percentile).astype(int)
                self.image_pixMapItem.conversion = generateLUT(
                    self.image_pixMapItem.min, self.image_pixMapItem.max,
                    self.image_pixMapItem.gamma,
                    self.image_pixMapItem.max_value)
            if self.image_pixMapItem.conversion is not None:
                self.slice_zoom_image = self.image_pixMapItem.conversion[
                    self.slice_zoom_image[:, :, :3]]
            self.slice_zoom_pixmap.setPixmap(
                QtGui.QPixmap(array2qimage(self.slice_zoom_image)))
            self.slice_zoom_pixmap.setOffset(*(np.array(preview_rect[0:2]) /
                                               downsample))
            self.slice_zoom_pixmap.setScale(downsample)
            self.slice_zoom_pixmap.show()
Exemplo n.º 4
0
    def setCursor(self) -> None:
        icon = self.getIcon(color=QtGui.QColor(255, 255, 255))
        # convert icon to numpy array
        buffer = icon.pixmap(16, 16).toImage().constBits()
        cursor2 = np.ndarray(shape=(16, 16, 4), buffer=buffer.asarray(size=16 * 16 * 4), dtype=np.uint8)
        # load the cursor image
        cursor = imageio.imread(os.path.join(os.environ["CLICKPOINTS_ICON"], "Cursor.png"))
        # compose them
        cursor3 = np.zeros([cursor.shape[0] + cursor2.shape[0], cursor.shape[1] + cursor2.shape[1], 4], cursor.dtype)
        cursor3[:cursor.shape[0], :cursor.shape[1], :] = cursor
        y, x = (cursor.shape[0] - 6, cursor.shape[1] - 4)
        cursor3[y:y + cursor2.shape[0], x:x + cursor2.shape[1], :] = cursor2
        # create a cursor
        cursor = QtGui.QCursor(QtGui.QPixmap(array2qimage(cursor3)), 0, 0)

        # and the the cursor as the active one
        self.parent.ImageDisplay.setCursor(cursor)
Exemplo n.º 5
0
 def UpdatePixmapCount(self) -> None:
     # Create new subimages if needed
     for i in range(len(self.pixMapItems), self.number_of_imagesX * self.number_of_imagesY):
         self.images.append(None)
         self.DrawImages.append(None)
         self.qimages.append(None)
         if i == 0:
             new_pixmap = QtWidgets.QGraphicsPixmapItem(self.origin)
         else:
             new_pixmap = QtWidgets.QGraphicsPixmapItem(self.origin)
         new_pixmap.setZValue(20)
         self.pixMapItems.append(new_pixmap)
         new_pixmap.setOpacity(self.opacity)
     # Hide images which are not needed
     for i in range(self.number_of_imagesX * self.number_of_imagesY, len(self.pixMapItems)):
         im = np.zeros((1, 1, 1))
         self.pixMapItems[i].setPixmap(QtGui.QPixmap(array2qimage(im)))
         self.pixMapItems[i].setOffset(0, 0)
Exemplo n.º 6
0
 def setImageDirect(self, image: np.ndarray) -> None:
     if image.dtype != self.current_dtype:
         return self.setImageFirstTime(image)
     self.setPixmap(QtGui.QPixmap(array2qimage(image.astype(np.uint8))))