I want to display images using cv2 and combine QLabel with SetPixmap method to display images in my GUI. I use CV2 because of image processing purpose in Tumor Segmentation using UNET architecture. can anyone solve this? or any alternate code to make my program work as well.
Here is the code
class Autosegmentation(QMainWindow, Ui_MainWindow):
def __init__(self):
super().__init__()
self.setupUi(self)
self.open_image_button.clicked.connect(self.opendialog)
def opendialog(self):
file_filter = "Images (*.png *.jpg *.tiff *.jpeg)"
filename = QFileDialog.getOpenFileName(
parent = self,
caption = 'select a File',
filter = file_filter)[0]
self.setImage(filename)
def setImage(self, image_path):
self.cvimage = cv2.imread(image_path, cv2.IMREAD_COLOR)
if self.cvimage is None:
print('error')
return
self.cvimage = cv2.cvtColor(self.cvimage, cv2.COLOR_BGR2RGB)
self.cvimage = self.cvimage/255.0
self.cvimage = self.cvimage.astype(np.float32)
height, width, channel = self.cvimage.shape
bytes_per_line = 3 * width
self.qt_image = QImage(self.cvimage.data, width, height, bytes_per_line * channel, QImage.Format.Format_RGB888)
self.pixmap = QtGui.QPixmap.fromImage(self.qt_image)
self.image_view.setPixmap(self.pixmap)
self.image_view_2.setPixmap(self.pixmap)
and the output like this as you can see, the images output really bad and it shows only small grid.
if anyone have an idea to solve this or any alternative code. please Help me. Thankyou!