Ejemplo n.º 1
0
    def setGroovePixmapFromProfile(self, profile, colormap=None):
        """Set the pixmap displayed in the slider groove from histogram values.

        :param Union[numpy.ndarray,None] profile:
            1D array of values to display
        :param Union[~silx.gui.colors.Colormap,str] colormap:
            The colormap name or object to convert profile values to colors
        """
        if profile is None:
            self.setSliderPixmap(None)
            return

        profile = numpy.array(profile, copy=False)

        if profile.size == 0:
            self.setSliderPixmap(None)
            return

        if colormap is None:
            colormap = colors.Colormap()
        elif isinstance(colormap, str):
            colormap = colors.Colormap(name=colormap)
        assert isinstance(colormap, colors.Colormap)

        rgbImage = colormap.applyToData(profile.reshape(1, -1))[:, :, :3]
        qimage = convertArrayToQImage(rgbImage)
        qpixmap = qt.QPixmap.fromImage(qimage)
        self.setGroovePixmap(qpixmap)
Ejemplo n.º 2
0
    def setGroovePixmapFromProfile(self, profile, colormap=None):
        """Set the pixmap displayed in the slider groove from histogram values.

        :param Union[numpy.ndarray,None] profile:
            1D array of values to display
        :param Union[Colormap,str] colormap:
            The colormap name or object to convert profile values to colors
        """
        if profile is None:
            self.setSliderPixmap(None)
            return

        profile = numpy.array(profile, copy=False)

        if profile.size == 0:
            self.setSliderPixmap(None)
            return

        if colormap is None:
            colormap = colors.Colormap()
        elif isinstance(colormap, str):
            colormap = colors.Colormap(name=colormap)
        assert isinstance(colormap, colors.Colormap)

        rgbImage = colormap.applyToData(profile.reshape(1, -1))[:, :, :3]
        qimage = convertArrayToQImage(rgbImage)
        qpixmap = qt.QPixmap.fromImage(qimage)
        self.setGroovePixmap(qpixmap)
Ejemplo n.º 3
0
    def testConvertArrayToQImage(self):
        """Test conversion of numpy array to QImage"""
        for format_, channels in [('Format_RGB888', 3), ('Format_ARGB32', 4)]:
            with self.subTest(format_):
                image = numpy.arange(3 * 3 * channels,
                                     dtype=numpy.uint8).reshape(
                                         3, 3, channels)
                qimage = convertArrayToQImage(image)

                self.assertEqual(qimage.height(), image.shape[0])
                self.assertEqual(qimage.width(), image.shape[1])
                self.assertEqual(qimage.format(), getattr(qt.QImage, format_))

                for row in range(3):
                    for col in range(3):
                        # Qrgb has no alpha channel, not compared
                        # Qt uses x,y while array is row,col...
                        self.assertEqual(qt.QColor(qimage.pixel(col, row)),
                                         qt.QColor(*image[row, col, :3]))
Ejemplo n.º 4
0
    def testConvertArrayToQImage(self):
        """Test conversion of numpy array to QImage"""
        for format_, channels in [('Format_RGB888', 3),
                                  ('Format_ARGB32', 4)]:
            with self.subTest(format_):
                image = numpy.arange(
                    3*3*channels, dtype=numpy.uint8).reshape(3, 3, channels)
                qimage = convertArrayToQImage(image)

                self.assertEqual(qimage.height(), image.shape[0])
                self.assertEqual(qimage.width(), image.shape[1])
                self.assertEqual(qimage.format(), getattr(qt.QImage, format_))

                for row in range(3):
                    for col in range(3):
                        # Qrgb has no alpha channel, not compared
                        # Qt uses x,y while array is row,col...
                        self.assertEqual(qt.QColor(qimage.pixel(col, row)),
                                         qt.QColor(*image[row, col, :3]))