zoukankan      html  css  js  c++  java
  • 二值化与高斯模糊化

    1.高斯模糊化

    # -*- coding: utf-8 -*-
    """
    Created on Wed Dec  5 14:57:40 2018
    
    @author: 1
    """
    
    
    #import numpy as np
    import cv2
    #import matplotlib.pyplot as plt
    
    img = cv2.imread('WIN_20190110_16_56_25_Pro.jpg')
    img_ = cv2.GaussianBlur(img, ksize=(29,29), sigmaX=0, sigmaY=0)
    
    
    cv2.imshow('Source image',img)
    cv2.imshow('blur image',img_)
    
    
    
    cv2.waitKey()

    2.二值化

    # -*- coding: utf-8 -*-
    """
    Created on Wed Nov 21 14:52:55 2018
    
    @author: 1
    """
    
    
    import cv2 
    import matplotlib.pyplot as plt
     
    img = cv2.imread('YCbCr.jpg',0) #直接读为灰度图像
    #简单滤波
    ret1,th1 = cv2.threshold(img,10,255,cv2.THRESH_BINARY)
    
    #Otsu 滤波
    ret2,th2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
    th3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,11,2)
    ret, dst = cv2.threshold(img, 127, 255,  cv2.THRESH_BINARY)
    
    cv2.imshow("ss",th1)
    ##cv2.imwrite("aaa.jpg", th3)
    cv2.imwrite("Binary_5.jpg",th1)
    #print(ret2)
    #plt.figure()
    #plt.subplot(221),plt.imshow(img,'gray')
    #plt.subplot(222),plt.hist(img.ravel(),256)#.ravel方法将矩阵转化为一维
    #plt.subplot(223),plt.imshow(th1,'gray')
    #plt.subplot(224),plt.imshow(th3,'gray')
    
    #img=cv2.imread('1111.jpg')
    #cv2.imshow("1111.jpg",img)
  • 相关阅读:
    HDU4003 Find Metal Mineral
    POJ1125 Stockbroker Grapevine
    HDU4028The time of a day
    弱校ACM奋斗史
    POJ1236 Network of Schools
    HDU4004 The Frog's Games
    HDU4001 To Miss Our Children Time
    POJ2186 Popular Cows
    POJ1094 Sorting It All Out
    hadoop2.7.1单机和伪集群的搭建0
  • 原文地址:https://www.cnblogs.com/Manuel/p/10430145.html
Copyright © 2011-2022 走看看