Exemple #1
0
    def rgbFromWaveLength(self, wave):
        r = 0.0
        g = 0.0
        b = 0.0

        if wave >= 380.0 and wave <= 440.0:
            r = -1.0 * (wave - 440.0) / (440.0 - 380.0)
            b = 1.0
        elif wave >= 440.0 and wave <= 490.0:
            g = (wave - 440.0) / (490.0 - 440.0)
            b = 1.0
        elif wave >= 490.0 and wave <= 510.0:
            g = 1.0
            b = -1.0 * (wave - 510.0) / (510.0 - 490.0)
        elif wave >= 510.0 and wave <= 580.0:
            r = (wave - 510.0) / (580.0 - 510.0)
            g = 1.0
        elif wave >= 580.0 and wave <= 645.0:
            r = 1.0
            g = -1.0 * (wave - 645.0) / (645.0 - 580.0)
        elif wave >= 645.0 and wave <= 780.0:
            r = 1.0

        s = 1.0
        if wave > 700.0:
            s = 0.3 + 0.7 * (780.0 - wave) / (780.0 - 700.0)
        elif wave < 420.0:
            s = 0.3 + 0.7 * (wave - 380.0) / (420.0 - 380.0)

        r = pow(r * s, 0.8)
        g = pow(g * s, 0.8)
        b = pow(b * s, 0.8)

        return qRgb(r*255, g*255, b*255)
Exemple #2
0
    def rgbFromWaveLength(self, wave):
        r = 0.0
        g = 0.0
        b = 0.0

        if wave >= 380.0 and wave <= 440.0:
            r = -1.0 * (wave - 440.0) / (440.0 - 380.0)
            b = 1.0
        elif wave >= 440.0 and wave <= 490.0:
            g = (wave - 440.0) / (490.0 - 440.0)
            b = 1.0
        elif wave >= 490.0 and wave <= 510.0:
            g = 1.0
            b = -1.0 * (wave - 510.0) / (510.0 - 490.0)
        elif wave >= 510.0 and wave <= 580.0:
            r = (wave - 510.0) / (580.0 - 510.0)
            g = 1.0
        elif wave >= 580.0 and wave <= 645.0:
            r = 1.0
            g = -1.0 * (wave - 645.0) / (645.0 - 580.0)
        elif wave >= 645.0 and wave <= 780.0:
            r = 1.0

        s = 1.0
        if wave > 700.0:
            s = 0.3 + 0.7 * (780.0 - wave) / (780.0 - 700.0)
        elif wave < 420.0:
            s = 0.3 + 0.7 * (wave - 380.0) / (420.0 - 380.0)

        r = pow(r * s, 0.8)
        g = pow(g * s, 0.8)
        b = pow(b * s, 0.8)

        return qRgb(r * 255, g * 255, b * 255)
    def resizeImage(self, image, newSize):
        if self.image.size() == newSize:
            return

        newImage = QImage(newSize, QImage.Format_RGB32)
        newImage.fill(qRgb(255, 255, 255))
        painter = QPainter(newImage)
        painter.drawImage(QPoint(0, 0), self.image)
        self.image = newImage
Exemple #4
0
    def __init__(self):
        QWidget.__init__(self)

        self.pressed = False
        self.selectedIndex = -1
        self.lineColor = qRgb(34, 163, 169)
        self.lineWidth = 2
        self.selectColor = qRgb(0, 120, 200)
        self.polygonColor = qRgb(0, 255, 255)
        self.dotRadius = 4
        self.dotColor = qRgb(34, 163, 169)
        self.setMouseTracking(True)
        self.tempPoints = []
        self.tempPolygons = []
        self.selectedEllipseIndex = -1
        self.selectDotVisible = True
        self.pressedPolygon = {}

        self.button = QPushButton("&Delete All", self)
        # Connecting the signal
        self.button.clicked.connect(self.magic)
Exemple #5
0
    def update_widgets(self, cam_id, camera_widget, camera_label):
        camera_data = self.images_received[cam_id]

        if cam_id in self.is_sensor_active.keys(
        ) and self.is_sensor_active[cam_id]:
            array = np.frombuffer(camera_data.image, dtype=np.dtype("uint8"))
            array = np.reshape(array,
                               (camera_data.height, camera_data.width, 4))
            qImg = QImage(array, array.shape[1], array.shape[0],
                          array.strides[0], QImage.Format_ARGB32)
        else:
            qImg = QImage(camera_data.width, camera_data.height,
                          QImage.Format_ARGB32)
            qImg.fill(qRgb(0, 0, 0))
        pixmap = QPixmap(qImg)
        pixmap = pixmap.scaled(camera_widget.size(), Qt.KeepAspectRatio,
                               Qt.SmoothTransformation)

        camera_widget.setPixmap(pixmap)
        camera_label.setText(self.pose_cameras_dict[cam_id]['name'])
def toQImage(im, copy=False):
    gray_color_table = [qRgb(i, i, i) for i in range(256)]
    if im is None:
        return QImage()
    if im.dtype == np.uint8:
        if len(im.shape) == 2:
            qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0],
                         QImage.Format_Indexed8)
            qim.setColorTable(gray_color_table)
            return qim.copy() if copy else qim

        elif len(im.shape) == 3:
            if im.shape[2] == 3:
                qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0],
                             QImage.Format_RGB888)
                return qim.copy() if copy else qim
            elif im.shape[2] == 4:
                qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0],
                             QImage.Format_ARGB32)
                return qim.copy() if copy else qim
Exemple #7
0
    def set_title(self):
        """Setup label"""
        self._window.title.setText('This is PySide2 Tutorial')

        # set color
        a_color = QColor('#55aa55')
        b_color = QColor(qRgb(125, 22, 100))
        c_color = QColor('red')

        print(a_color.name())
        print(b_color.name())
        print(c_color.name())

        a_cmyk = a_color.toCmyk()
        print(a_cmyk)

        # set font
        font = QFont("Arial", 20, QFont.Bold)
        self._window.title.setFont(font)
        # set widget size (x, y, width, height)
        self._window.title.setGeometry(0, 0, 600, 30)
        # set alignment
        self._window.title.setAlignment(Qt.AlignBottom | Qt.AlignCenter)
 def setUp(self):
     #Acquire resources
     super(SetPixelFloat, self).setUp()
     self.color = qRgb(255, 0, 0)
     self.image = QImage(200, 200, QImage.Format_RGB32)
Exemple #9
0
from PySide2.QtCore import Qt, QObject, SIGNAL, Signal
from PySide2.QtWidgets import QWidget, QGraphicsView, QGraphicsScene, QGraphicsPixmapItem, QVBoxLayout, QButtonGroup, QHBoxLayout, QPushButton
from PySide2.QtGui import QImage, QPixmap, qRgb

SPRITE_SIZE = 8

COLORS = {
    0: qRgb(255, 255, 255),
    1: qRgb(170, 170, 180),
    2: qRgb(85, 85, 85),
    3: qRgb(0, 0, 0)
}


class SpriteFormatException(Exception):
    pass


class SpriteGraphicsItem(QGraphicsPixmapItem):
    def __init__(self, sprite_view):
        super().__init__()
        self._sprite_view = sprite_view

    def _paint_event(self, event):
        x = int(event.pos().x())
        y = int(event.pos().y())
        if x < 0 or x >= SPRITE_SIZE or y < 0 or y >= SPRITE_SIZE:
            return
        self._sprite_view.paint_pixel(x, y)

    def mousePressEvent(self, event):
 def setUp(self):
     #Acquire resources
     super(SetPixelFloat, self).setUp()
     self.color = qRgb(255, 0, 0)
     self.image = QImage(200, 200, QImage.Format_RGB32)
 def clearImage(self):
     self.image.fill(qRgb(255, 255, 255))
     self.modified = True
     self.update()
Exemple #12
0
def _to_rgb(colormap):
    colormap = numpy.array(colormap)
    cm = []
    for color in colormap:
        cm.append(qRgb(color[0], color[1], color[2]))
    return cm
Exemple #13
0
def _generate_colormap(minvalue, maxvalue, colormap=_seismic_data256):
    return _to_rgb(colormap[minvalue:maxvalue + 1])


def _generate_colormap_interp(minvalue, maxvalue, color_map=_seismic_data256):
    points = numpy.array(color_map)
    interp = numpy.empty((maxvalue + 1 - minvalue, 3))
    x = numpy.linspace(minvalue, maxvalue, interp.shape[0])
    for c in range(points.shape[1]):
        interp[:, c] = numpy.interp(
            x, numpy.linspace(0, points.shape[0], points.shape[0]), points[:,
                                                                           c])
    return _to_rgb(interp)


grey = [qRgb(i, i, i) for i in range(256)]
seismic = _generate_colormap_interp(0, 255)

colormap_dict = {
    'None': None,
    'Grey': grey,
    'Seismic': seismic,
}


def _my_dir(oo):
    return [o for o in dir(oo) if not o.startswith('__')]


def _my_getmembers(oo):
    return [o for o in getmembers(oo) if not o[0].startswith('__')]
Exemple #14
0
    def run(self):
        while True:
            self.mutex.lock()
            resultSize = self.resultSize
            scaleFactor = self.scaleFactor
            centerX = self.centerX
            centerY = self.centerY
            self.mutex.unlock()

            halfWidth = resultSize.width() // 2
            halfHeight = resultSize.height() // 2
            image = QImage(resultSize, QImage.Format_RGB32)

            NumPasses = 8
            curpass = 0

            while curpass < NumPasses:
                MaxIterations = (1 << (2 * curpass + 6)) + 32
                Limit = 4
                allBlack = True

                for y in range(-halfHeight, halfHeight):
                    if self.restart:
                        break
                    if self.abort:
                        return

                    ay = 1j * (centerY + (y * scaleFactor))

                    for x in range(-halfWidth, halfWidth):
                        c0 = centerX + (x * scaleFactor) + ay
                        c = c0
                        numIterations = 0

                        while numIterations < MaxIterations:
                            numIterations += 1
                            c = c * c + c0
                            if abs(c) >= Limit:
                                break
                            numIterations += 1
                            c = c * c + c0
                            if abs(c) >= Limit:
                                break
                            numIterations += 1
                            c = c * c + c0
                            if abs(c) >= Limit:
                                break
                            numIterations += 1
                            c = c * c + c0
                            if abs(c) >= Limit:
                                break

                        if numIterations < MaxIterations:
                            image.setPixel(
                                x + halfWidth, y + halfHeight,
                                self.colormap[numIterations %
                                              RenderThread.ColormapSize])
                            allBlack = False
                        else:
                            image.setPixel(x + halfWidth, y + halfHeight,
                                           qRgb(0, 0, 0))

                if allBlack and curpass == 0:
                    curpass = 4
                else:
                    if not self.restart:
                        self.renderedImage.emit(image, scaleFactor)
                    curpass += 1

            self.mutex.lock()
            if not self.restart:
                self.condition.wait(self.mutex)
            self.restart = False
            self.mutex.unlock()
import numpy as np
from PySide2.QtGui import QImage, qRgb

# https://gist.github.com/smex/5287589

gray_color_table = [qRgb(i, i, i) for i in range(256)]


def to_QImage(im, copy=False):
    if im is None:
        return QImage()

    if im.dtype == np.uint8:
        if len(im.shape) == 2:
            qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_Indexed8)
            qim.setColorTable(gray_color_table)
            return qim.copy() if copy else qim

        elif len(im.shape) == 3:
            if im.shape[2] == 3:
                qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_RGB888);
                return qim.copy() if copy else qim
            elif im.shape[2] == 4:
                qim = QImage(im.data, im.shape[1], im.shape[0], im.strides[0], QImage.Format_ARGB32);
                return qim.copy() if copy else qim

    raise NotImplementedException
Exemple #16
0
    def run(self):
        while True:
            self.mutex.lock()
            resultSize = self.resultSize
            scaleFactor = self.scaleFactor
            centerX = self.centerX
            centerY = self.centerY
            self.mutex.unlock()

            halfWidth = resultSize.width() // 2
            halfHeight = resultSize.height() // 2
            image = QImage(resultSize, QImage.Format_RGB32)

            NumPasses = 8
            curpass = 0

            while curpass < NumPasses:
                MaxIterations = (1 << (2 * curpass + 6)) + 32
                Limit = 4
                allBlack = True

                for y in range(-halfHeight, halfHeight):
                    if self.restart:
                        break
                    if self.abort:
                        return

                    ay = 1j * (centerY + (y * scaleFactor))

                    for x in range(-halfWidth, halfWidth):
                        c0 = centerX + (x * scaleFactor) + ay
                        c = c0
                        numIterations = 0

                        while numIterations < MaxIterations:
                            numIterations += 1
                            c = c*c + c0
                            if abs(c) >= Limit:
                                break
                            numIterations += 1
                            c = c*c + c0
                            if abs(c) >= Limit:
                                break
                            numIterations += 1
                            c = c*c + c0
                            if abs(c) >= Limit:
                                break
                            numIterations += 1
                            c = c*c + c0
                            if abs(c) >= Limit:
                                break

                        if numIterations < MaxIterations:
                            image.setPixel(x + halfWidth, y + halfHeight,
                                           self.colormap[numIterations % RenderThread.ColormapSize])
                            allBlack = False
                        else:
                            image.setPixel(x + halfWidth, y + halfHeight, qRgb(0, 0, 0))

                if allBlack and curpass == 0:
                    curpass = 4
                else:
                    if not self.restart:
                        self.renderedImage.emit(image, scaleFactor)
                    curpass += 1

            self.mutex.lock()
            if not self.restart:
                self.condition.wait(self.mutex)
            self.restart = False
            self.mutex.unlock()