当前位置:编程学习 > python >>

opencv for python之简单的图像变化

import cv2.cv as cv


#load image
filename = "../Video/cat.jpg"
image = cv.LoadImage(filename)


#set created image
size = cv.GetSize(image)#(100, 100)
depth = 8
channels = 1

灰度处理
grey = cv.CreateImage(size, depth, channels)#create one 100x100 single channels image
cv.CvtColor(image, grey, cv.CV_BGR2GRAY)

光滑去噪,使图像上剧烈变化的地方过度平滑,即让图像上不同颜色之间分界线模糊

smooth = cv.CreateImage(size, depth, channels)
cv.Smooth(grey, smooth, cv.CV_MEDIAN)

均衡化操作:统计一个图像的像素值,绘制成一个直方图,然后均衡化(均衡化印象中就是让直方图分布更接近正态分布)www.zzzyk.com

equalize = cv.CreateImage(size, depth, channels)
cv.Smooth(grey, equalize)

拉普拉斯操作:可以把图像中的轮廓突出出来

Laplace = cv.CreateImage(size, depth, channels)#create one 100x100 single channels image
cv.CvtColor(image, Laplace, cv.CV_BGR2GRAY)
dst_16s2 = cv.CreateImage(size, cv.IPL_DEPTH_16S, 1)
cv.Laplace(Laplace, dst_16s2)
cv.Convert(dst_16s2, Laplace)

#create a window
win_name1 = "grey"
win_name2 = "smooth"
win_name3 = "equalize"
win_name4 = "Laplace"
cv.NamedWindow(win_name1)
cv.NamedWindow(win_name2)
cv.NamedWindow(win_name3)
cv.NamedWindow(win_name4)
#cv.NamedWindow(win_name5)
cv.ShowImage(win_name1, grey)
cv.ShowImage(win_name2, smooth)
cv.ShowImage(win_name3, equalize)
cv.ShowImage(win_name4, Laplace)
cv.WaitKey()

灰度结果



光滑去噪

 
 

直方图均衡化结果

 
 

拉普拉斯操作结果

 
 

补充:Web开发 , Python ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,