Exemplo n.º 1
0
void CmSaliencyRC::GetHC(CMat &binColor3f, CMat &colorNums1i, Mat &_colorSal)
{
	Mat weight1f;
	normalize(colorNums1i, weight1f, 1, 0, NORM_L1, CV_32F);

	int binN = binColor3f.cols; 
	_colorSal = Mat::zeros(1, binN, CV_32F);
	float* colorSal = (float*)(_colorSal.data);
	vector<vector<CostfIdx>> similar(binN); // Similar color: how similar and their index
	Vec3f* color = (Vec3f*)(binColor3f.data);
	float *w = (float*)(weight1f.data);
	for (int i = 0; i < binN; i++){
		vector<CostfIdx> &similari = similar[i];
		similari.push_back(make_pair(0.f, i));
		for (int j = 0; j < binN; j++){
			if (i == j)
				continue;
			float dij = vecDist<float, 3>(color[i], color[j]);
			similari.push_back(make_pair(dij, j));
			colorSal[i] += w[j] * dij;
		}
		sort(similari.begin(), similari.end());
	}

	SmoothSaliency(_colorSal, 0.25f, similar);
}
Exemplo n.º 2
0
void Saliency::GetHC(const Mat &binColor3f, const Mat &weight1f, Mat &_colorSal)
{
	int binN = binColor3f.cols; 
	_colorSal = Mat::zeros(1, binN, CV_32F);
	float* colorSal = (float*)(_colorSal.data);
	vector<vector<CostfIdx>> similar(binN); // Similar color: how similar and their index
	Vec3f* color = (Vec3f*)(binColor3f.data);
	float *w = (float*)(weight1f.data);
	for (int i = 0; i < binN; i++)
	{
		vector<CostfIdx> &similari = similar[i];
		similari.push_back(make_pair(0.f, i));
		for (int j = 0; j < binN; j++)
		{
			if (i == j)
				continue;
			float dij = vecDist3<float>(color[i], color[j]);
			similari.push_back(make_pair(dij, j));
			colorSal[i] += w[j] * dij;
		}
		sort(similari.begin(), similari.end());
	}

	SmoothSaliency(binColor3f, _colorSal, 4.0f, similar);
}
Exemplo n.º 3
0
void CmSaliencyRC::SmoothByHist(CMat &img3f, Mat &sal1f, float delta)
{
	//imshow("Before", sal1f); imshow("Src", img3f);

	// Quantize colors
	CV_Assert(img3f.size() == sal1f.size() && img3f.type() == CV_32FC3 && sal1f.type() == CV_32FC1);
	Mat idx1i, binColor3f, colorNums1i;
	int binN = Quantize(img3f, idx1i, binColor3f, colorNums1i);
	//CmShow::HistBins(binColor3f, colorNums1i, "Frequency");
	
	// Get initial color saliency
	Mat _colorSal =  Mat::zeros(1, binN, CV_64FC1);
	int rows = img3f.rows, cols = img3f.cols;{
		double* colorSal = (double*)_colorSal.data;
		if (img3f.isContinuous() && sal1f.isContinuous())
			cols *= img3f.rows, rows = 1;
		for (int y = 0; y < rows; y++){
			const int* idx = idx1i.ptr<int>(y);
			const float* initialS = sal1f.ptr<float>(y);
			for (int x = 0; x < cols; x++)
				colorSal[idx[x]] += initialS[x];
		}
		const int *colorNum = (int*)(colorNums1i.data);
		for (int i = 0; i < binN; i++)
			colorSal[i] /= colorNum[i];
		normalize(_colorSal, _colorSal, 0, 1, NORM_MINMAX, CV_32F);
	}
	// Find similar colors & Smooth saliency value for color bins
	vector<vector<CostfIdx>> similar(binN); // Similar color: how similar and their index
	Vec3f* color = (Vec3f*)(binColor3f.data);
	cvtColor(binColor3f, binColor3f, CV_BGR2Lab);
	for (int i = 0; i < binN; i++){
		vector<CostfIdx> &similari = similar[i];
		similari.push_back(make_pair(0.f, i));
		for (int j = 0; j < binN; j++)
			if (i != j)
				similari.push_back(make_pair(vecDist<float, 3>(color[i], color[j]), j));
		sort(similari.begin(), similari.end());
	}
	cvtColor(binColor3f, binColor3f, CV_Lab2BGR);
	//CmShow::HistBins(binColor3f, _colorSal, "BeforeSmooth", true);
	SmoothSaliency(colorNums1i, _colorSal, delta, similar);
	//CmShow::HistBins(binColor3f, _colorSal, "AfterSmooth", true);

	// Reassign pixel saliency values
	float* colorSal = (float*)(_colorSal.data);
	for (int y = 0; y < rows; y++){
		const int* idx = idx1i.ptr<int>(y);
		float* resSal = sal1f.ptr<float>(y);
		for (int x = 0; x < cols; x++)
			resSal[x] = colorSal[idx[x]];
	}
	//imshow("After", sal1f);
	//waitKey(0);
}
Exemplo n.º 4
0
void CmSaliencyRC::SmoothSaliency(Mat &sal1f, float delta, const vector<vector<CostfIdx>> &similar)
{
	Mat colorNum1i = Mat::ones(sal1f.size(), CV_32SC1);
	SmoothSaliency(colorNum1i, sal1f, delta, similar);
}