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

1
  • Make sure the image data in the numpy array is with right bit depth and the data range is normalized. Commented May 20, 2020 at 10:30

1 Answer 1

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.