I'm new to Python and have sorta c++ style coding background.
In short:
- tring to display 16 bit grayscale images in my GUI(pyqt6)
- have the stored the image data in bytearray, that is, 1024 by 768 (the total size of the byte array would be 1024 x 768 x 2 since it's 16 bit).
- having difficulties with using this data = bytearray(1572864) for displaying.
The following code is what I have used for displaying the same image (but downscaled to 8-bit). What I'm now trying to do is use the 16-bit data and have it converted to QPixmap in order to display.
The code for displaying 8-bit raw image is ( I have used rawpy for this, please feel free to get rid of the rawpy section if you could come up with a better way to do this)
raw = np.array( binary data read from file)
src = raw.postprocess()
buf = src.data.tobytes()
h, w, ch = src.shape
bytesperline = ch * w
image = QImage(buf, 1024, 768, bytesperline, QImage.Format_RGB888)
self.DisplayRect.setPixmap(QPixmap.fromImage(image))
self.DisplayRect.show()
Hope I explained my question without causing any confusion. In summary:
- trying to use data in bytearray(1572864) to display in my GUI
- in need of help with manipulating the binary data from/to different data structures
What I would have done if it were c++:
//declare a Mat with 16UC1 format
//easily memcpy(mat.data, source, size);
//stretchDiBits(dc, where_to_draw_imgs, mat.data);
Thank you very much in advance.