im trying to write a code in python that will present the RGB channels of a picture in three separate labels in PyQt5 GUI. I'm reading the pictures via cv2, zero the un-necessary channels (e.g. for the red channel - I copy it to a separate variable and set Blue channel = 0 and Green channel = 0) then I reverse the channels with split/merge functions of cv2 (because cv2 uses [B,G,R] format instead of [R,G,B]) and use the result in: QPixmap.fromImage(QImage('cv2 array that represent the individual color channel', width, height, QtGui.QImage.Format_RGB888)).
So here is the weird part - 1) when the image is of even dimensions - everything works fine. But when the left dimension is odd (e.g. 627X626) I get garbage in the red channel but green and blue work fine. 2) When the odd dimension is on the right - I get the red channel fine but green and blue are corrupted. 3) When both the dimensions are odd - the program crushes at this very line with the code : Process finished with exit code -1073741819 (0xC0000005)
This is the code of the image aquisistion:
self.red_scale_img = cv2.imread(file_name)
self.red_scale_img[:, :, 0] = 0
self.red_scale_img[:, :, 1] = 0
b = self.red_scale_img[:, :, 0]
g = self.red_scale_img[:, :, 1]
r = self.red_scale_img[:, :, 2]
self.red_scale_img = cv2.merge([r, g, b])
self.green_scale_img = cv2.imread(file_name)
self.green_scale_img[:, :, 0] = 0
self.green_scale_img[:, :, 2] = 0
self.blue_scale_img = cv2.imread(file_name)
self.blue_scale_img[:, :, 1] = 0
self.blue_scale_img[:, :, 2] = 0
# the switching between red and blue scales
b = self.blue_scale_img[:, :, 0]
g = self.blue_scale_img[:, :, 1]
r = self.blue_scale_img[:, :, 2]
self.blue_scale_img = cv2.merge([r, g, b])
This is the line where the program crushes when the image is of dimension 627X627:
red_scale_image = QPixmap.fromImage(QImage(new_image_obj.red_scale_img, new_image_obj.red_scale_img.shape[1], new_image_obj.red_scale_img.shape[0], QtGui.QImage.Format_RGB888)).scaled(int(self.image_height/3.1746), int(self.image_width/3.1746))
User contributions licensed under CC BY-SA 3.0