• 大小: 6KB
    文件类型: .cpp
    金币: 2
    下载: 1 次
    发布日期: 2021-12-19
  • 语言: C/C++
  • 标签: 显著性  FT  opencv  

资源简介

图像显著性FT模型的代码,希望对你有帮助

资源截图

代码片段和文件信息

#include 
#include 
#include 
using namespace cv;
using namespace std;

void BGR2Lab(Mat srcImage vector& vlabImg);//BGR转为Lab空间
void GaussianSmooth(Mat& singleImg);//高斯平滑

int main()
{
Mat srcImage = imread(“E:\\VS2010\\ScratchProject\\SalientDetection\\SalientDetectionFT\\10.jpg“);
Mat srcImg(srcImage.size()CV_8UC3); //如果是灰度图,则先转换为3通道图像
if(srcImage.channels()==1)
cvtColor(srcImagesrcImgCV_GRAY2BGR);
else
srcImg=srcImage.clone();
imshow(“原始图像“  srcImg); 

//BGR转为LAB通道
vector vlabImg; //存放lab三通道的值
BGR2Lab(srcImgvlabImg);

//分别求LAB三通道的均值
vector meanVal;
for(int i = 0;i {
Scalar meanVals = mean(vlabImg[i]);
meanVal.push_back(meanVals.val[0]);         //求取LAB三通道的均值
}

//分别求LAB三通道的高斯滤波
GaussianSmooth(vlabImg[0]);
GaussianSmooth(vlabImg[1]);
GaussianSmooth(vlabImg[2]);

//求取显著图
Mat tempImg(srcImg.size()CV_64FC1Scalar::all(meanVal[0]));
absdiff(vlabImg[0]meanVal[0]vlabImg[0]); //L通道的 |均值-高斯滤波|
pow(vlabImg[0]2vlabImg[0]); //对以上结果求平方根

tempImg.setTo(meanVal[1]);
absdiff(vlabImg[1]meanVal[1]vlabImg[1]);
pow(vlabImg[1]2vlabImg[1]);

tempImg.setTo(meanVal[2]);
absdiff(vlabImg[2]meanVal[2]vlabImg[2]);
pow(vlabImg[2]2vlabImg[2]);

Mat salientMap(srcImg.size()CV_64FC1Scalar::all(0));
add(vlabImg[0]vlabImg[1]salientMap);
add(vlabImg[2]salientMapsalientMap);

//归一化
normalize(salientMapsalientMap10CV_MINMAX); 
//double型图像转为uchar型图像
Mat salientImg(srcImg.size()CV_8UC1Scalar::all(0));
salientMap.convertTo(salientImgCV_8UC12550);

imshow(“salientImg“salientImg);

waitKey(0);
return 0;
}

void BGR2Lab(Mat srcImg vector& vlabImg)//BGR转为Lab空间
{
Mat initImg(srcImg.size()CV_64FC1Scalar::all(0));
for(int i = 0; i {
vlabImg.push_back(initImg);//初始化vlabImg分别存放L A B 
}
Mat LImg(srcImg.size()CV_64FC1Scalar::all(0));
Mat AImg(srcImg.size()CV_64FC1Scalar::all(0));
Mat BImg(srcImg.size()CV_64FC1Scalar::all(0));

for(int i = 0; i < srcImg.rows; i++)     //行
{
for(int j = 0; j < srcImg.cols; j++) //列
{
int sB = (int)srcImg.at(ij)[0];
int sG = (int)srcImg.at(ij)[1];
int sR = (int)srcImg.at(ij)[2];
//------------------------
// sRGB to XYZ conversion
// (D65 illuminant assumption)
//------------------------
double R = (double)sR/255.0;
double G = (double)sG/255.0;
double B = (double)sB/255.0;

double r g b;

if(R <= 0.04045) r = (double)R/12.92;
else r = pow((R+0.055)/1.0552.4);
if(G <= 0.04045) g = (double)G/12.92;
else g = pow((G+0.055)/1.0552.4);
if(B <= 0.04045) b = (double)B/12.92;
else b = pow((B+0.055)/1.0552.4)

评论

共有 条评论