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)
  • 相关阅读:
    口腔溃疡
    English 好的报纸
    线段树
    归并排序 霍纳规则(法则) 统计逆序对
    xfce4桌面自动整理脚本
    解决xubuntu的thunar第一次启动慢
    解决ibus图标为红圈(图标丢失)
    linux tar 备份命令
    ubuntu中的Wine详解
    我的conky配置
  • 原文地址:https://www.cnblogs.com/Manuel/p/10430145.html
Copyright © 2011-2022 走看看