1. 参考文献
// Itti L, Koch C, Niebur E. A Model of Saliency-Based Visual Attention for Rapid Scene Analysis[J]. IEEE Transactions on Pattern Analysis & Machine Intelligence, 1998, 20(11):1254-1259.
// Itti L, Koch C. Computational modelling of visual attention.[J]. Nature Reviews Neuroscience, 2001, 2(3):194.
2. 模型实现
2.1 显著性检测公共头文件
#ifndef SALIENTCOMMON_H
#define SALIENTCOMMON_H
// std lib
#include <iostream>
#include <string>
#include <vector>
#include <fstream>
// opencv lib
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/ml/ml.hpp>
using namespace std;
using namespace cv;
#endif // SALIENTCOMMON_H
2.2 显著性检测头文件
#ifndef SALIENTITTI_H
#define SALIENTITTI_H
#include "salientcommon.h"
// Itti L, Koch C, Niebur E. A Model of Saliency-Based Visual Attention for Rapid Scene Analysis[J]. IEEE Transactions on Pattern Analysis & Machine Intelligence, 1998, 20(11):1254-1259.
// Itti L, Koch C. Computational modelling of visual attention.[J]. Nature Reviews Neuroscience, 2001, 2(3):194.
//高斯金字塔结构体
typedef struct GaussPyr
{
IplImage *lev[9];
}GaussPyr;
class salientITTI
{
public:
salientITTI(string imageName);
void m_getSalientITTI(Mat& result);
~salientITTI();
private:
void initPyr(GaussPyr *p);
int downsample(int x, int level);
void Gscale(GaussPyr *p, IplImage *data, int level, double sigma);
void overScaleSub(IplImage *s1, IplImage *s2, IplImage *dst);
void getLocalMaxima(IplImage *scr, double thresh, double *lm_sum, int *lm_num, double*lm_avg);
void N_operation(IplImage *scr, IplImage *dst);
void CS_operation(GaussPyr *p1, GaussPyr *p2, IplImage *dst);
void PyrSub(GaussPyr *s1, GaussPyr *s2, GaussPyr *dst);
void cvGabor(IplImage *scr, IplImage *dst, int width, double lamda, double theta);
void runItti(const char* filename);
private:
Mat m_orgImg;
Mat m_resultImg;
string m_imageName;
};
#endif // SALIENTITTI_H
2.3 显著性检测实现
#include "salientitti.h"
#define PI 3.1415926
//将金字塔尺寸定义为全局变量
CvSize PyrSize[9] = {NULL};
salientITTI::salientITTI(string imageName)
{
m_imageName = imageName;
}
salientITTI::~salientITTI()
{
}
void salientITTI::m_getSalientITTI(Mat &result)
{
runItti(m_imageName.c_str());
m_resultImg.copyTo(result);
}
//初始化金字塔结构体
void salientITTI::initPyr(GaussPyr *p)
{
for(int i = 0; i < 9; i++)
p->lev[i] = cvCreateImage(PyrSize[i], IPL_DEPTH_64F, 1);
}
//根据层数,求第i层的尺寸
int salientITTI::downsample(int x, int level)
{
if(level-- > 0)
{
if(x%2 == 0)
x = x/2;
else
x = (x+1)/2;
downsample(x,level);
}
if(level == -1)
return x;
}
//计算并产生一幅图的高斯金字塔 每层的图像
void salientITTI::Gscale(GaussPyr *p, IplImage *data, int level, double sigma)
{
for(int i = 0; i<level; i++)
{
if(i == 0)
cvSmooth(data, p->lev[0], CV_GAUSSIAN, 5, 5, sigma, 0);
else
{
IplImage *tem = cvCreateImage(PyrSize[i-1], IPL_DEPTH_64F, 1);
cvSmooth(p->