Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Intermittent errors displaying image with pixmap
metalshreds last edited by
Sometimes when I load an image (np array to QImage to pixmap) into my application, the image does not display but instead I get an image like the one attached. Without changing any code I can re-load the app and the image will display fine. I am not sure where to start troubleshooting as this does work but intermittently. Thanks in advance for any help.
Kent-Dorfman last edited by
show us yoru code that takes the raw array data and converts to the Qt intermediate and final formats. smells like you are not doing the conversions properly and are ending up with buffer overruns that are not being captured. so, sometimes it works and sometimes it does not.
metalshreds last edited by metalshreds
@Kent-Dorfman Hi sorry for the delayed response, I didn't get a notification on your reply. Below is the code that I'm using to take a 3d numpy array of data (im), collapsing it into a 2d x,y image and then converting it to a QImage. I then add this to a Qpixmap that I display in a QLabel. I am new to Qt so not sure if I'm doing that correctly :/
x, y, t = im.shape im = np.sum(im, axis=2) # collapse to 2d image img_8bit = ((im - im.min()) / (im.ptp() / 255.0)).astype(np.uint8) # map the data range to 0 - 255 return QImage(img_8bit, x, y, x, QImage.Format_Grayscale8)
Maybe Format_Grayscale8 isnt' the correct format to use but not sure which is, Format_Indexed8 also displays my image fine. the numpy array stores vlaues as uint16. Please let me know if you need more info.