日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

pyrMeanShiftFiltering函数

發布時間:2025/4/16 编程问答 12 豆豆
生活随笔 收集整理的這篇文章主要介紹了 pyrMeanShiftFiltering函数 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

pyrMeanShiftFiltering函數

對圖像進行:均值偏移濾波

調用格式:

void cvPyrMeanShiftFiltering( const CvArr* src, CvArr* dst,double sp, double sr, int max_level=1,CvTermCriteria termcrit=cvTermCriteria(CV_TERMCRIT_ITER+CV_TERMCRIT_EPS,5,1)); src
輸入的8-比特,3-信道圖象.
dst
和源圖象相同大小,相同格式的輸出圖象.
sp
The spatial window radius.
空間窗的半徑
sr
The color window radius.
色彩窗的半徑
max_level
Maximum level of the pyramid for the segmentation.
我們先借助Mean Shift算法的分割特性將灰度值相近的元素進行聚類,然后,在此基礎上應用閾值分割算法,

達到將圖像與背景分離的目的。 簡單來說,基于Mean Shift的圖像分割過程就是首先利用Mean Shift算法對圖像中的像素進行聚類,

即把收斂到同一點的起始點歸為一類,然后把這一類的標號賦給這些起始點,同時把包含像素點太少的類去掉。

然后,采用閾值化分割的方法對圖像進行二值化處理 基于Mean Shift的圖像分割算法將圖像中灰度值相近的像素點聚類為一個灰度級,

因此,經過Mean Shift算法分割后的圖像中的灰度級較該算法處理之前有所減少。



opencv代碼:

// meanshift_segmentation.cpp : 定義控制臺應用程序的入口點。 //#include "stdafx.h" #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include <opencv2/imgproc/imgproc.hpp> #include <iostream>using namespace cv; using namespace std;Mat src,dst; int spatialRad=10,colorRad=10,maxPryLevel=1; //const Scalar& colorDiff=Scalar::all(1);void meanshift_seg(int,void *) {//調用meanshift圖像金字塔進行分割pyrMeanShiftFiltering(src,dst,spatialRad,colorRad,maxPryLevel);RNG rng=theRNG();Mat mask(dst.rows+2,dst.cols+2,CV_8UC1,Scalar::all(0));for(int i=0;i<dst.rows;i++) //opencv圖像等矩陣也是基于0索引的for(int j=0;j<dst.cols;j++)if(mask.at<uchar>(i+1,j+1)==0){Scalar newcolor(rng(256),rng(256),rng(256));floodFill(dst,mask,Point(i,j),newcolor,0,Scalar::all(1),Scalar::all(1));// floodFill(dst,mask,Point(i,j),newcolor,0,colorDiff,colorDiff);}imshow("dst",dst); }int main(int argc, uchar* argv[]) {namedWindow("src",WINDOW_AUTOSIZE);namedWindow("dst",WINDOW_AUTOSIZE);src=imread("stuff.jpg");CV_Assert(!src.empty());spatialRad=10;colorRad=10;maxPryLevel=1;//雖然createTrackbar函數的參數onChange函數要求其2個參數形式為onChange(int,void*)//但是這里是系統響應函數,在使用createTrackbar函數時,其調用的函數可以不用寫參數,甚至//括號都不用寫,但是其調用函數的實現過程中還是需要滿足(int,void*)2個參數類型createTrackbar("spatialRad","dst",&spatialRad,80,meanshift_seg);createTrackbar("colorRad","dst",&colorRad,60,meanshift_seg);createTrackbar("maxPryLevel","dst",&maxPryLevel,5,meanshift_seg);// meanshift_seg(0,0);imshow("src",src);/*char c=(char)waitKey();if(27==c)return 0;*/imshow("dst",src);waitKey();//無限等待用戶交互響應 // while(1);//這里不能用while(1)的原因是需要等待用戶的交互,而while(1)沒有該功能。雖然2者都有無限等待的作用。return 0; }


總結

以上是生活随笔為你收集整理的pyrMeanShiftFiltering函数的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。