Render image from hsv color
-
I've looking into a way to render an image on screen from a saturation map.
I'm currently using a regular widget (because I couldn't get transparency to work with the openGL one).
My paint even look something likepainter = QPainter() painter.begin(self) color = QColor() for x, y in np.transpose(np.nonzero(self.im)): color.setHsv(168, self.im[x, y], 180) painter.setPen(color) painter.drawPoint(QPoint(x, y)) painter.end()
where I iterate over the whole (nonzero) saturation map "self.im", change the QColor to that, update the painter with that color and paint that point.
But this is terribly inefficient and slow, how can I make this work?
Is there a way to make a hsv/hsl Image and render that?
I can layer the (constant) hue and value/saturation to a make a full hw3 numpy array if that helps. -
I have found a solution that kind of does the job, although takes three times as much memory.
Every update I calculate the difference between the new and the old saturation matrix, this eliminates 60% of the nonzero values, which means it gets drawn that much faster.As a second layer of optimization I call repaint with a rectangle describing the most important zone, and call update every 60ms.
-
@Adam-V In the same way you're drawing it now. See http://doc.qt.io/qt-5/qimage.html#setPixel-1
-
@jsulm While this does draw faster but still 90ms paintEvent (improved from 180).
Implementation:image = QImage(self.width(), self.height(), QImage.Format_ARGB32) painter = QPainter() painter.begin(self) color = QColor() for x, y in np.transpose(np.nonzero(self.im)): color.setHsv(168, self.im[x, y], 180) image.setPixelColor(x, y, color) painter.drawImage(self.rect(), image) painter.end()
-
I have found a solution that kind of does the job, although takes three times as much memory.
Every update I calculate the difference between the new and the old saturation matrix, this eliminates 60% of the nonzero values, which means it gets drawn that much faster.As a second layer of optimization I call repaint with a rectangle describing the most important zone, and call update every 60ms.