1

I know that this question should be a duplicate question from post but since none of the solution there works for me, I decided to create another post for it. So I tried all of the solution there but I keep getting the same noise image as can be soon below (the left picture is the result when I show using matplotlib while the right picture is the result that I keep getting). Here is the code that I used, Normal is the variable for a numpy array that I want to show.

    height, width, channel = normal.shape
    bytesPerLine = 3 * width
    qImg = QtGui.QImage(normal.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
    self.normalImage = QtGui.QPixmap(qImg)
    self.ui.normalDisplay.setPixmap(self.normalImage)

enter image description here

Wanttobepro
  • 77
  • 13
  • Make sure the image data in the numpy array is with right bit depth and the data range is normalized. – heLomaN May 20 '20 at 10:30

1 Answers1

0

Okay,I have found the answer. It turns out that you need to make sure the numpy arrays to be between [0,255] and must be uint8 type to works. This is the piece of code that works

            normal *= 255
            normal = normal.astype(np.uint8)
            height, width, channel = normal.shape
            bytesPerLine = 3 * width
            qImg = QtGui.QImage(normal.data, width, height, bytesPerLine, QtGui.QImage.Format_RGB888)
            pixmap01 = QtGui.QPixmap.fromImage(qImg)
            self.normalImage = QtGui.QPixmap(pixmap01)
            self.ui.normalDisplay.setPixmap(self.normalImage)
Wanttobepro
  • 77
  • 13