顯著性區(qū)域檢測(cè)代碼課件_第1頁(yè)
顯著性區(qū)域檢測(cè)代碼課件_第2頁(yè)
顯著性區(qū)域檢測(cè)代碼課件_第3頁(yè)
顯著性區(qū)域檢測(cè)代碼課件_第4頁(yè)
顯著性區(qū)域檢測(cè)代碼課件_第5頁(yè)
已閱讀5頁(yè),還剩8頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、/ Saliency.h#if !defined(_SALIENCY_H_INCLUDED_) #define _SALIENCY_H_INCLUDED_ #include <vector> #include <cfloat> using namespace std; class Saliency public: Saliency(); virtual Saliency(); public: void GetSaliencyMap( const vector<unsigned int>& inputimg,/INPUT: ARGB buffer in

2、 row-major order const int& width, const int& height, vector<double>& salmap,/OUTPUT: Floating point buffer in row-major order const bool& normalizeflag = true);/false if normalization is not needed private: void RGB2LAB( const vector<unsigned int>& ubuff, vector<d

3、ouble>& lvec, vector<double>& avec, vector<double>& bvec); void GaussianSmooth( const vector<double>& inputImg, const int& width, const int& height, const vector<double>& kernel, vector<double>& smoothImg); /= / Normalize /= void Norma

4、lize( const vector<double>& input, const int& width, const int& height, vector<double>& output, const int& normrange = 255) double maxval(0); double minval(DBL_MAX); int i(0); for( int y = 0; y < height; y+ ) for( int x = 0; x < width; x+ ) if( maxval < input

5、i ) maxval = inputi; if( minval > inputi ) minval = inputi; i+; double range = maxval-minval; if( 0 = range ) range = 1; int i(0); output.clear(); output.resize(width*height); for( int y = 0; y < height; y+ ) for( int x = 0; x < width; x+ ) outputi = (normrange*(inputi-minval)/range); i+; ;

6、 #endif / !defined(_SALIENCY_H_INCLUDED_) / Saliency.cpp: implementation of the Saliency class. / / /= / Copyright (c) 2009 Radhakrishna Achanta EPFL /= #include "StdAfx.h" #include "Saliency.h" #include <cmath> / / Construction/Destruction / Saliency:Saliency() Saliency:Sa

7、liency() /= / RGB2LAB /= void Saliency:RGB2LAB( const vector<unsigned int>& ubuff, vector<double>& lvec, vector<double>& avec, vector<double>& bvec) int sz = int(ubuff.size(); lvec.resize(sz); avec.resize(sz); bvec.resize(sz); for( int j = 0; j < sz; j+ ) i

8、nt r = (ubuffj >> 16) & 0xFF; int g = (ubuffj >> 8) & 0xFF; int b = (ubuffj ) & 0xFF; double xval = 0.412453 * r + 0.357580 * g + 0.180423 * b; double yval = 0.212671 * r + 0.715160 * g + 0.072169 * b; double zVal = 0.019334 * r + 0.119193 * g + 0.950227 * b; xval /= (255.0 *

9、 0.950456); yval /= 255.0; zVal /= (255.0 * 1.088754); double fX, fY, fZ; double lval, aval, bval; if (yval > 0.008856) fY = pow(yval, 1.0 / 3.0); lval = 116.0 * fY - 16.0; else fY = 7.787 * yval + 16.0 / 116.0; lval = 903.3 * yval; if (xval > 0.008856) fX = pow(xval, 1.0 / 3.0); else fX = 7.7

10、87 * xval + 16.0 / 116.0; if (zVal > 0.008856) fZ = pow(zVal, 1.0 / 3.0); else fZ = 7.787 * zVal + 16.0 / 116.0; aval = 500.0 * (fX - fY)+128.0; bval = 200.0 * (fY - fZ)+128.0; lvecj = lval; avecj = aval; bvecj = bval; /= / GaussianSmooth / / Blur an image with a separable binomial kernel passed

11、in. /= void Saliency:GaussianSmooth( const vector<double>& inputImg, const int& width, const int& height, const vector<double>& kernel, vector<double>& smoothImg) int center = int(kernel.size()/2; int sz = width*height; smoothImg.clear(); smoothImg.resize(sz); v

12、ector<double> tempim(sz); int rows = height; int cols = width; /- / Blur in the x direction. /- int index(0); for( int r = 0; r < rows; r+ ) for( int c = 0; c < cols; c+ ) double kernelsum(0); double sum(0); for( int cc = (-center); cc <= center; cc+ ) if(c+cc) >= 0) && (c+

13、cc) < cols) sum += inputImgr*cols+(c+cc) * kernelcenter+cc; kernelsum += kernelcenter+cc; tempimindex = sum/kernelsum; index+; /- / Blur in the y direction. /- int index = 0; for( int r = 0; r < rows; r+ ) for( int c = 0; c < cols; c+ ) double kernelsum(0); double sum(0); for( int rr = (-ce

14、nter); rr <= center; rr+ ) if(r+rr) >= 0) && (r+rr) < rows) sum += tempim(r+rr)*cols+c * kernelcenter+rr; kernelsum += kernelcenter+rr; smoothImgindex = sum/kernelsum; index+; /= / GetSaliencyMap / / Outputs a saliency map with a value assigned per pixel. The values are / normalized

15、 in the interval 0,255 if normflag is set true (default value). /= void Saliency:GetSaliencyMap( const vector<unsigned int>& inputimg, const int& width, const int& height, vector<double>& salmap, const bool& normflag) int sz = width*height; salmap.clear(); salmap.resi

16、ze(sz); vector<double> lvec(0), avec(0), bvec(0); RGB2LAB(inputimg, lvec, avec, bvec); /- / Obtain Lab average values /- double avgl(0), avga(0), avgb(0); for( int i = 0; i < sz; i+ ) avgl += lveci; avga += aveci; avgb += bveci; avgl /= sz; avga /= sz; avgb /= sz; vector<double> slvec

17、(0), savec(0), sbvec(0); /- / The kernel can be 1 2 1 or 1 4 6 4 1 as needed. / The code below show usage of 1 2 1 kernel. /- vector<double> kernel(0); kernel.push_back(1.0); kernel.push_back(2.0); kernel.push_back(1.0); GaussianSmooth(lvec, width, height, kernel, slvec); GaussianSmooth(avec,

18、width, height, kernel, savec); GaussianSmooth(bvec, width, height, kernel, sbvec); for( int i = 0; i < sz; i+ ) salmapi = (slveci-avgl)*(slveci-avgl) + (saveci-avga)*(saveci-avga) + (sbveci-avgb)*(sbveci-avgb); if( true = normflag ) vector<double> normalized(0); Normalize(salmap, width, hei

19、ght, normalized); swap(salmap, normalized); / SaliencyMapDlg.cpp : 實(shí)º¦Ì現(xiàn)?文?件t/#include "stdafx.h"#include "SaliencyMap.h"#include "SaliencyMapDlg.h"#include "afxdialogex.h"#include "opencv2opencv.hpp" #include "Saliency.h"#if

20、def _DEBUG#define new DEBUG_NEW#endif/ 用®?于®¨²應(yīng)®|用®?程¨¬序¨°“¡ã關(guān)?于®¨²”¡À菜?單Ì£¤項(xiàng)?的Ì? CAboutDlg 對(duì)?話¡ã框¨°class CAboutDlg : public CDialogExpublic:CAboutDlg();/ 對(duì)?話¡ã框

21、8;°數(shù)ºy據(jù)Yenum IDD = IDD_ABOUTBOX ;protected:virtual void DoDataExchange(CDataExchange* pDX); / DDX/DDV 支¡ì持?/ 實(shí)º¦Ì現(xiàn)?protected:DECLARE_MESSAGE_MAP();CAboutDlg:CAboutDlg() : CDialogEx(CAboutDlg:IDD)void CAboutDlg:DoDataExchange(CDataExchange* pDX)CDialogEx:DoDataExcha

22、nge(pDX);BEGIN_MESSAGE_MAP(CAboutDlg, CDialogEx)END_MESSAGE_MAP()/ CSaliencyMapDlg 對(duì)?話¡ã框¨°CSaliencyMapDlg:CSaliencyMapDlg(CWnd* pParent /*=NULL*/): CDialogEx(CSaliencyMapDlg:IDD, pParent)m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);void CSaliencyMapDlg:DoDataExchange(CDataE

23、xchange* pDX)CDialogEx:DoDataExchange(pDX);BEGIN_MESSAGE_MAP(CSaliencyMapDlg, CDialogEx)ON_WM_SYSCOMMAND()ON_WM_PAINT()ON_WM_QUERYDRAGICON()ON_BN_CLICKED(IDC_BUT_OPEN, &CSaliencyMapDlg:OnBnClickedButOpen)END_MESSAGE_MAP()/ CSaliencyMapDlg 消?息¡é處ä|理¤¨ª程¨¬序&

24、#168;°BOOL CSaliencyMapDlg:OnInitDialog()CDialogEx:OnInitDialog();/ 將?“¡ã關(guān)?于®¨².”¡À菜?單Ì£¤項(xiàng)?添¬¨ª加¨®到Ì?系¦Ì統(tǒng)ª3菜?單Ì£¤中D。¡ê/ IDM_ABOUTBOX 必À?須?在¨²系¦Ì統(tǒng)ª

25、;3命¨¹令¢?范¤?圍¡ì內(nèi)¨²。¡êASSERT(IDM_ABOUTBOX & 0xFFF0) = IDM_ABOUTBOX);ASSERT(IDM_ABOUTBOX < 0xF000);CMenu* pSysMenu = GetSystemMenu(FALSE);if (pSysMenu != NULL)BOOL bNameValid;CString strAboutMenu;bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX)

26、;ASSERT(bNameValid);if (!strAboutMenu.IsEmpty()pSysMenu->AppendMenu(MF_SEPARATOR);pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);/ 設(shè)¦¨¨置?此ä?對(duì)?話¡ã框¨°的Ì?圖ª?標(biāo)À¨º。¡ê當(dāng)Ì¡À應(yīng)®|用®?程¨

27、72;序¨°主¡Â窗ä¡ã口¨²不?是º?對(duì)?話¡ã框¨°時(shí)º¡À,ê?框¨°架¨¹將?自Á?動(dòng)¡¥/ 執(zhí)¡ä行D此ä?操¨´作Á¡ÂSetIcon(m_hIcon, TRUE);/ 設(shè)¦¨¨置?大䨮圖&#

28、170;?標(biāo)À¨ºSetIcon(m_hIcon, FALSE);/ 設(shè)¦¨¨置?小?圖ª?標(biāo)À¨º/ TODO: 在¨²此ä?添¬¨ª加¨®額?外ªa的Ì?初?始º?化¡¥代䨲碼?return TRUE; / 除y非¤?將?焦1點(diǎn)Ì?設(shè)¦¨¨置?到Ì?控?件t,ê

29、?否¤?則¨°返¤¦Ì回? TRUEvoid CSaliencyMapDlg:OnSysCommand(UINT nID, LPARAM lParam)if (nID & 0xFFF0) = IDM_ABOUTBOX)CAboutDlg dlgAbout;dlgAbout.DoModal();elseCDialogEx:OnSysCommand(nID, lParam);/ 如¨?果?向¨°對(duì)?話¡ã框¨°添¬¨ª加¨

30、®最Á?小?化¡¥按ã¡ä鈕£¤,ê?則¨°需¨¨要°a下?面?的Ì?代䨲碼?/ 來(lái)¤¡ä繪?制?該?圖ª?標(biāo)À¨º。¡ê對(duì)?于®¨²使º1用®?文?檔̦Ì/視º¨®圖ª?模¡

31、4;型¨ª的Ì? MFC 應(yīng)®|用®?程¨¬序¨°,ê?/ 這a將?由®¨¦框¨°架¨¹自Á?動(dòng)¡¥完ª¨º成¨¦。¡êvoid CSaliencyMapDlg:OnPaint()if (IsIconic()CPaintDC dc(this); / 用®?于®¨²繪?制?的Ì?設(shè)

32、¦¨¨備À?上¦?下?文?SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc(), 0);/ 使º1圖ª?標(biāo)À¨º在¨²工¡è作Á¡Â區(qū)?矩?形?中D居¨®中Dint cxIcon = GetSystemMetrics(SM_CXICON);int cyIcon = GetSystemMetrics(SM_C

33、YICON);CRect rect;GetClientRect(&rect);int x = (rect.Width() - cxIcon + 1) / 2;int y = (rect.Height() - cyIcon + 1) / 2;/ 繪?制?圖ª?標(biāo)À¨ºdc.DrawIcon(x, y, m_hIcon);elseCDialogEx:OnPaint();/當(dāng)Ì¡À用®?戶¡ì拖ª?動(dòng)¡¥最Á?小?化¡¥窗ä

34、¡ã口¨²時(shí)º¡À系¦Ì統(tǒng)ª3調(diào)Ì¡Â用®?此ä?函¡¥數(shù)ºy取¨?得Ì?光a標(biāo)À¨º/顯?示º?。¡êHCURSOR CSaliencyMapDlg:OnQueryDragIcon()return static_cast<HCURSOR>(m_hIcon);/*/src IPL_DEPTH_8U/dst IPL_DEPTH_

35、64F*/傅¦Ì里¤?葉°?正y變À?換?void fft2(IplImage *src, IplImage *dst) /實(shí)º¦Ì部?、¡é虛¨¦部? IplImage *image_Re = 0, *image_Im = 0, *Fourier = 0; / int i, j; image_Re = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); /實(shí)º¦Ì部? /Imaginary part

36、 image_Im = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); /虛¨¦部? /2 channels (image_Re, image_Im) Fourier = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 2); / Real part conversion from u8 to 64f (double) cvConvertScale(src, image_Re, 1, 0); / Imaginary part (zeros) cvZero(image_Im); / J

37、oin real and imaginary parts and stock them in Fourier image cvMerge(image_Re, image_Im, 0, 0, Fourier); / Application of the forward Fourier transform cvDFT(Fourier, dst, CV_DXT_FORWARD); cvReleaseImage(&image_Re); cvReleaseImage(&image_Im); cvReleaseImage(&Fourier);void CSaliencyMapDlg

38、:OnBnClickedButOpen() IplImage *src, *ImageRe, *ImageIm, *Fourier, *Inverse, *LogAmplitude, *Sine, *Cosine; IplImage *Saliency, *Residual; IplImage *tmp1, *tmp2, *tmp3; double minNum = 0, maxNum = 0, scale, shift; int i, j, nRow, nCol; CString Path;CFileDialog dlg(true,_T("*.bmp"),NULL,OFN

39、_FILEMUSTEXIST|OFN_PATHMUSTEXIST|OFN_HIDEREADONLY,_T("image file(*.bmp;*.jpg)|*.bmp;*.jpg|All Files(*.*)|*.*|"),NULL);dlg.m_ofn.lpstrTitle=_T("open Image");if(dlg.DoModal()!=IDOK)return ;Path = dlg.GetPathName();Path.Replace(_T("/"),_T("/");src = cvLoadImage(C

40、T2CA) Path,0); Fourier = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 2); Inverse = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 2); ImageRe = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); ImageIm = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); LogAmplitude = cvCreateImage(cvGetSize(src), IPL_

41、DEPTH_64F, 1); Sine = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); Cosine = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); Residual = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); Saliency = cvCreateImage(cvGetSize(src), src->depth, src->nChannels); tmp1 = cvCreateImage(cvGetSize(src)

42、, IPL_DEPTH_64F, 1); tmp2 = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); tmp3 = cvCreateImage(cvGetSize(src), IPL_DEPTH_64F, 1); nRow = src->height; nCol = src->width; /歸¨¦一°?化¡¥一°?下? scale = 1.0/255.0; cvConvertScale(src, tmp1, scale, 0); /傅¦Ì里¤

43、;?葉°?變À?換?,ê?得Ì?到Ì?的Ì?Fourier有®D兩¢?個(gè)?通ª¡§道̨¤,ê?一°?個(gè)?是º?實(shí)º¦Ì部?,ê?一°?個(gè)?是º?虛¨¦部? fft2(tmp1, Fourier); /將?傅¦Ì里¤?葉°?譜¡Á的Ì?實(shí)º¦Ì部?和

44、¨ª虛¨¦部?存ä?放¤?到Ì?對(duì)?應(yīng)®|的Ì?圖ª?像?中D去¨£¤。¡ê cvSplit(Fourier, ImageRe, ImageIm, 0, 0); /計(jì)?算?傅¦Ì里¤?葉°?振?幅¤¨´譜¡Á,ê?實(shí)º¦Ì部?和¨ª虛¨¦部?平?方¤?和¨&#

45、170;再¨´開(kāi)a方¤?,ê?得Ì?到Ì?振?幅¤¨´譜¡Á存ä?到Ì?tmp3中D cvPow( ImageRe, tmp1, 2.0); cvPow( ImageIm, tmp2, 2.0); cvAdd( tmp1, tmp2, tmp3); cvPow( tmp3, tmp3, 0.5 ); /計(jì)?算?正y弦¨°譜¡Á和¨ª余®¨¤弦¨°譜¡

46、;Á和¨ª自Á?然¨?對(duì)?數(shù)ºy譜¡Á cvLog( tmp3, LogAmplitude ); cvDiv(ImageIm, tmp3, Sine); cvDiv(ImageRe, tmp3, Cosine); /對(duì)?LogAmplitude做Á?3*3均¨´值¦Ì濾?波¡§ cvSmooth(LogAmplitude, tmp3, CV_BLUR, 3, 3); /計(jì)?算?出?剩º¡ê余®¨&

47、#164;普? cvSub(LogAmplitude, tmp3, Residual); /*/ /* 對(duì)?exp(Residual+i*Phase)作Á¡Â傅¦Ì里¤?葉°?反¤¡ä變À?換? 由®¨¦歐¡¤拉¤-公?式º?:êo exp(r+i*¡§) = exp(r)*(cos(¡§) + i*sin(¡§) = exp(r)*cos(¡§) + i*exp(r)*sin(¡§) 其?中D¡§是º?相¨¤位?。¡ê 而?sin(¡§) = ImageIm/Amplitude; cos(¡§) = Imag

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

最新文檔

評(píng)論

0/150

提交評(píng)論