首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 平面设计 > 图形图像 >

opencv for python 之 简略的图像变化

2012-12-20 
opencv for python 之 简单的图像变化import cv2.cv as cv#load imagefilename ../Video/cat.jpgimage

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)

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

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()

灰度结果
opencv for python 之 简略的图像变化

光滑去噪

opencv for python 之 简略的图像变化

直方图均衡化结果

opencv for python 之 简略的图像变化

拉普拉斯操作结果

opencv for python 之 简略的图像变化

热点排行