def __houghLineTransformSlot(self): # 如果当前不是二值图像 则直接返回 if not isBinaryImage(self.__imgList[-1]): MessageDialog(self, '需要先在「分割」菜单中进行二值化') return newImg, flag = houghLineTransform(self.__imgList[-1]) if flag: self.__appendImg(newImg) else: MessageDialog(self, '未检测到直线')
def __orbFeatureDetectionSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') return self.__appendImg(orbFeatureDetection(self.__imgList[-1]))
def __contourTracingSlot(self): # 如果当前不是二值图像 则直接返回 if not isBinaryImage(self.__imgList[-1]): MessageDialog(self, '需要先在「分割」菜单中进行二值化') return self.__appendImg(contourTracing(self.__imgList[-1]))
def __morphologyPreviewSlot(self): # 如果当前不是二值图像 则直接返回 if not isBinaryImage(self.__imgList[-1]): MessageDialog(self, '需要先在「分割」菜单中进行二值化') self.ui.hs_morphology_radius.setValue(0) return if self.ui.radio_morphology_shape_rect.isChecked(): shape = 'rect' elif self.ui.radio_morphology_shape_circle.isChecked(): shape = 'circle' else: shape = 'cross' radius = self.ui.hs_morphology_radius.value() if self.ui.radio_morphology_type_dilate.isChecked(): self.__previewImgDict['morphology'] = dilateOperation( self.__imgList[-1], shape, radius) elif self.ui.radio_morphology_type_erode.isChecked(): self.__previewImgDict['morphology'] = erodeOperation( self.__imgList[-1], shape, radius) elif self.ui.radio_morphology_type_open.isChecked(): self.__previewImgDict['morphology'] = openOperation( self.__imgList[-1], shape, radius) else: self.__previewImgDict['morphology'] = closeOperation( self.__imgList[-1], shape, radius) self.__viewer.changeImage(self.__previewImgDict['morphology'])
def __otsuThresholdBtnSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') return self.__appendImg(otsuThresholdSegmentation(self.__imgList[-1]))
def __histogramEqualizationBtnSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先进行灰度化') return self.__appendImg(histogramEqualization(self.__imgList[-1]))
def __toGrayImageBtnSlot(self): # 如果已经是灰度图 则直接返回 if self.__imgList[-1].ndim == 2: MessageDialog(self, '当前已经是灰度图像') return self.__appendImg(cv.cvtColor(self.__imgList[-1], cv.COLOR_BGR2GRAY))
def _OnFind(self, event): start, end = self.DoFind(event.GetFindString()) if start == -1: msg = MessageDialog(self, 'Find/Replace', 'Cannot find "' + event.GetFindString() + '"', icon='information') msg.ShowModal() else: self.fSetSelection(start, end)
def __fixedThresholdPreviewSlot(self, threshold): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') self.ui.hs_fixed_threshold.setValue(127) return self.__previewImgDict['fixedThreshold'] = fixedThresholdSegmentation( self.__imgList[-1], threshold) self.__viewer.changeImage(self.__previewImgDict['fixedThreshold']) self.__fixedThresholdActiveFlag = True # 置为激活状态
def __laplacianEdgeDetectionBtnSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') return if self.ui.radio_laplacian_edge_detection_type_4.isChecked(): neighbourhood = 4 else: neighbourhood = 8 self.__appendImg( laplacianEdgeDetection(self.__imgList[-1], neighbourhood))
def __cannyEdgePreviewSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') self.ui.hs_canny_low_threshold.setValue(100) self.ui.hs_canny_high_threshold.setValue(200) return lowThreshold = self.ui.hs_canny_low_threshold.value() highThreshold = self.ui.hs_canny_high_threshold.value() self.__previewImgDict['cannyEdge'] = cannyEdgeDetection( self.__imgList[-1], lowThreshold, highThreshold) self.__viewer.changeImage(self.__previewImgDict['cannyEdge']) self.__cannyEdgeActiveFlag = True # 置为激活状态
def __sobelEdgeDetectionBtnSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') return if self.ui.radio_sobel_edge_detection_axis_x.isChecked(): axis = 'x' else: axis = 'y' if self.ui.radio_sobel_edge_detection_radius_1.isChecked(): radius = 1 elif self.ui.radio_sobel_edge_detection_radius_2.isChecked(): radius = 2 else: radius = 3 self.__appendImg(sobelEdgeDetection(self.__imgList[-1], axis, radius))
def __adaptiveThresholdPreviewSlot(self): # 如果当前不是灰度图 则直接返回 if not self.__imgList[-1].ndim == 2: MessageDialog(self, '需要先在「基本」菜单中进行灰度化') self.ui.hs_adaptive_threshold_radius.setValue(0) self.ui.hs_adaptive_threshold_offset.setValue(0) return if self.ui.radio_adaptive_threshold_type_average.isChecked(): method = 'mean' else: method = 'gaussian' radius = self.ui.hs_adaptive_threshold_radius.value() offset = self.ui.hs_adaptive_threshold_offset.value() if radius == 0: self.__previewImgDict['adaptiveThreshold'] = self.__imgList[-1] else: self.__previewImgDict[ 'adaptiveThreshold'] = adaptiveThresholdSegmentation( self.__imgList[-1], method, radius, offset) self.__viewer.changeImage(self.__previewImgDict['adaptiveThreshold'])