python给图片加滤镜的方程_Python OpenCV处理图像之滤镜和图像运算

import cv2.cv as cv

image=cv.LoadImage('img/lena.jpg', cv.CV_LOAD_IMAGE_COLOR) #Load the image

cv.ShowImage("Original", image)

grey = cv.CreateImage((image.width ,image.height),8,1) #8depth, 1 channel so grayscale

cv.CvtColor(image, grey, cv.CV_RGBA2GRAY) #Convert to gray so act as a filter

cv.ShowImage('Greyed', grey)

# 平滑变换

smoothed = cv.CloneImage(image)

cv.Smooth(image,smoothed,cv.CV_MEDIAN) #Apply a smooth alogrithm with the specified algorithm cv.MEDIAN

cv.ShowImage("Smoothed", smoothed)

# 均衡处理

cv.EqualizeHist(grey, grey) #Work only on grayscaled pictures

cv.ShowImage('Equalized', grey)

# 二值化处理

threshold1 = cv.CloneImage(grey)

cv.Threshold(threshold1,threshold1, 100, 255, cv.CV_THRESH_BINARY)

cv.ShowImage("Threshold", threshold1)

threshold2 = cv.CloneImage(grey)

cv.Threshold(threshold2,threshold2, 100, 255, cv.CV_THRESH_OTSU)

cv.ShowImage("Threshold 2", threshold2)

element_shape = cv.CV_SHAPE_RECT

pos=3

element = cv.CreateStructuringElementEx(pos*2+1, pos*2+1, pos, pos, element_shape)

cv.Dilate(grey,grey,element,2) #Replace a pixel value with the maximum value of neighboors

#There is others like Erode which replace take the lowest value of the neighborhood

#Note: The Structuring element is optionnal

cv.ShowImage("Dilated", grey)

cv.WaitKey(0)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值