def Example_ImSharpening(SpType): ip = cv2IP.ConvIP() Img = ip.ImRead(srcImg) cv2.imshow("original", Img) DstImg = ip.ImSharpening(Img, SpType) cv2.imshow("result", DstImg) del ip
def ImSharpening(self): def click_event(event, x, y, flags, param): global sign if event == cv2.EVENT_LBUTTONDOWN: sign += 1 if sign >4: sign = 1 F_UM = CONV.ImSharpening(img, SpType=cv2IP.SharpType(sign), Gain=Scale.get(self.scale_gain), SmType=cv2IP.SmoothType.GAUSSIAN) CONV.ImWindow(self.__UMTitle) CONV.ImShow(self.__UMTitle, F_UM) if event == cv2.EVENT_RBUTTONDBLCLK: sign -= 1 if sign <1: sign = 4 F_UM = CONV.ImSharpening(img, SpType=cv2IP.SharpType(sign), Gain=Scale.get(self.scale_gain), SmType=cv2IP.SmoothType.GAUSSIAN) CONV.ImWindow(self.__UMTitle) CONV.ImShow(self.__UMTitle, F_UM) global sign sign = 1 CONV = cv2IP.ConvIP() try: img = CONV.ImRead(self.img_path) except AttributeError: showinfo("錯誤", "請選擇圖片!") # img = cv2.resize(img, (640, 480)) else: while True: cv2.setMouseCallback(self.__Title, click_event) CONV.ImWindow(self.__Title) CONV.ImShow(self.__Title, img) key = cv2.waitKey(30) if key == ord('q') or key == 27: break
def EdgeDetect(self): def click_event(event, x, y, flags, param): global sign if event == cv2.EVENT_LBUTTONDOWN: sign += 1 if sign >5: sign = 1 F_ED = CONV.EdgeDetect(img, EdType=cv2IP.EdgeType(sign)) CONV.ImWindow(self.__EDTitle) CONV.ImShow(self.__EDTitle, F_ED) if event == cv2.EVENT_RBUTTONDBLCLK: sign -= 1 if sign <1: sign = 5 F_ED = CONV.EdgeDetect(img, EdType=cv2IP.EdgeType(sign)) CONV.ImWindow(self.__EDTitle) CONV.ImShow(self.__EDTitle, F_ED) global sign sign = 1 CONV = cv2IP.ConvIP() try: img = CONV.ImRead(self.img_path) except AttributeError: showinfo("錯誤", "請選擇圖片!") # img = cv2.resize(img, (640, 480)) else: while True: cv2.setMouseCallback(self.__Title, click_event) CONV.ImWindow(self.__Title) CONV.ImShow(self.__Title, img) key = cv2.waitKey(30) if key == ord('q') or key == 27: break
def Example_Smooth(smType): ip = cv2IP.ConvIP() img = ip.ImRead(srcImg) ip.ImShow("original image", img) outImg = ip.Smooth2D(img, 5, smType) ip.ImShow("smoothed image -5", outImg) outImg = ip.Smooth2D(img, 15, smType) ip.ImShow("smoothed image -15", outImg) del ip
def Example_ImConv2D_Prewitt(): ip = cv2IP.ConvIP() Img = ip.ImRead(srcImg) ip.ImShow("original", Img) src_gray = ip.ImBGR2Gray(Img) kernels = ip.GetPrewittKernel() grad_planes = [] for i in range(0, len(kernels)): grad_planes.append(ip.Conv2D(src_gray, kernels[i])) grad_planes[i] = cv2.convertScaleAbs(grad_planes[i]) GradImg = cv2.addWeighted(grad_planes[0], 0.5, grad_planes[i], 0.5, 0) ip.ImShow("Prewitt Images", GradImg) del ip
def Example_ImConv2D_Kirsch(): ip = cv2IP.ConvIP() Img = ip.ImRead(srcImg) ip.ImShow("original", Img) src_gray = ip.ImBGR2Gray(Img) kernels = ip.GetKirschKernel() grad_planes = [] for i in range(0, len(kernels)): grad_planes.append(ip.Conv2D(src_gray, kernels[i])) temp_1 = cv2.max(grad_planes[0], grad_planes[1], grad_planes[2]) temp_2 = cv2.max(grad_planes[3], grad_planes[4], grad_planes[5]) temp_3 = cv2.max(grad_planes[6], grad_planes[7]) final = cv2.max(temp_1, temp_2, temp_3) ip.ImShow("Kirsch Images", final) del ip
def Example_ImEdge(EdType): ip = cv2IP.ConvIP() Img = ip.ImRead(srcImg) outImg = ip.EdgeDetect(Img, EdType) if (EdType == cv2IP.EdgeType(1)): ip.ImShow("Sobel Edge", outImg) elif (EdType == cv2IP.EdgeType(2)): ip.ImShow("Canny Edge", outImg) elif (EdType == cv2IP.EdgeType(3)): ip.ImShow("Scharr Edge", outImg) elif (EdType == cv2IP.EdgeType(4)): ip.ImShow("Laplacian Edge", outImg) elif (EdType == cv2IP.EdgeType(5)): ip.ImShow("Color Sobel Edge", outImg) del ip