边缘检测和Otsu方法背景分割

import cv2import mathimport cv2.cvimport numpy as npfrom matplotlib import pyplot as plt################################################################################print 'Load Image'imgFile = 'images/big_alice.jpg'# load an original imageimg = cv2.imread(imgFile)################################################################################# color value rangecRange = 256rows,cols,channels = img.shape# convert color space from bgr to grayimg = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)################################################################################# laplacian edgeimgLap = cv2.Laplacian(imgGray,cv2.CV_8U)# otsu methodthreshold,imgOtsu = cv2.threshold(imgGray,0,255,cv2.THRESH_BINARY + cv2.THRESH_OTSU)# adaptive gaussian threshold imgAdapt = cv2.adaptiveThreshold(imgGray,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY,11,2)# imgAdapt = cv2.medianBlur(imgAdapt, 3)################################################################################# display original image and gray imageplt.subplot(2,2,1), plt.imshow(img), plt.title('Original Image'), plt.xticks([]), plt.yticks([])plt.subplot(2,2,2), plt.imshow(imgLap,cmap = 'gray'), plt.title('Laplacian Edge'), plt.xticks([]), plt.yticks([])plt.subplot(2,2,3), plt.imshow(imgOtsu,cmap = 'gray'), plt.title('Otsu Method'), plt.xticks([]), plt.yticks([])plt.subplot(2,2,4), plt.imshow(imgAdapt,cmap = 'gray'), plt.title('Adaptive Gaussian Threshold'), plt.xticks([]), plt.yticks([])plt.show()################################################################################print 'Goodbye!'3. 实现结果

,天下没有不散的宴席,也许这人间真的只有朦朦胧胧才是真。

边缘检测和Otsu方法背景分割

相关文章:

你感兴趣的文章:

标签云: