大清早的咱們就來作一個簡單有趣的圖像處理算法實現,做爲對圖像處理算法學習的開端吧。之因此有趣就在於筆者把算法處理的各個方式的處理效果拿出來作了對比,給你看到原圖和各類處理後的圖像你是否可以知道那幅圖對應那種算法模式呢?嘻嘻,拭目以待吧算法
平滑的意義:函數
圖像平滑image smoothing:壓制、弱化或消除圖像中的細節、突變、邊緣和噪聲,就是圖像平滑化。學習
圖像平滑是對圖像做低通濾波,可在空間域或頻率域實現。空間域圖像平滑方法主要用低通卷積濾波、中值濾波等;頻率域圖像平滑經常使用的低通濾波器有低通梯形濾波器、低通高斯濾波器、低通指數濾波器、巴特沃思低通濾波器等。ui
自動對工程項目目錄下的圖片lena.jpg進行平滑處理:採用五種平滑算法,分別顯示在五個窗口中方便對比查看效果和各自特色。spa
#include "stdafx.h" #include"cv.h" #include"highgui.h" void main() { IplImage* pImg = cvLoadImage("lena.jpg",1); cvNamedWindow("Example4-in"); cvNamedWindow("Example4-out-GAUSSIAN"); cvNamedWindow("Example4-out-CV_BLUR_NO_SCALE"); cvNamedWindow("Example4-out-CV_BLUR"); cvNamedWindow("Example4-out-CV_MEDIAN"); cvNamedWindow("Example4-out-CV_BILATERAL"); cvShowImage("Example4-in",pImg); /* 分配各個圖像的結構空間用來存儲平滑後的圖像 */ IplImage* out1 = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3); IplImage* out2 = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3); IplImage* out3 = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3); IplImage* out4 = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3); IplImage* out5 = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3); cvSmooth(pImg,out1,CV_GAUSSIAN,3,3); //平滑處理 cvSmooth(pImg,out2,CV_BLUR_NO_SCALE,3,3); cvSmooth(pImg,out3,CV_BLUR,3,3); cvSmooth(pImg,out4,CV_MEDIAN,3,3); cvSmooth(pImg,out5,CV_BILATERAL,3,3); cvShowImage("Example4-out-GAUSSIAN",out1); cvShowImage("Example4-out-CV_BLUR_NO_SCALE",out2); cvShowImage("Example4-out-CV_BLUR",out3); cvShowImage("Example4-out-CV_MEDIAN",out4); cvShowImage("Example4-out-CV_BILATERAL",out5); cvWaitKey(0); cvReleaseImage(&out1); cvReleaseImage(&out2); cvReleaseImage(&out3); cvReleaseImage(&out4); cvReleaseImage(&out5); cvWaitKey(0); cvDestroyWindow("Example4-in"); cvDestroyWindow("Example4-out-GAUSSIAN"); cvDestroyWindow("Example4-out-CV_BLUR_NO_SCALE"); cvDestroyWindow("Example4-out-CV_MEDIAN"); cvDestroyWindow("Example4-out-CV_BILATERAL"); cvDestroyWindow("Example4-out-CV_BLUR"); }