Mat RegionSaliency::GetRCNoColorConversion(const Mat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma) { Mat regIdx1i, colorIdx1i, regSal1v, tmp, _img3f, color3fv; if (Quantize(img3f, colorIdx1i, color3fv, tmp) <= 2) // Color quantization return Mat::zeros(img3f.size(), CV_32F); _img3f = img3f.clone(); // cvtColor(img3f, _img3f, CV_BGR2Lab); // cvtColor(color3fv, color3fv, CV_BGR2Lab); int regNum = SegmentImage(_img3f, regIdx1i, segSigma, segK, segMinSize); vector<Region> regs(regNum); BuildRegions(regIdx1i, regs, colorIdx1i, color3fv.cols); RegionContrast(regs, color3fv, regSal1v, sigmaDist); Mat sal1f = Mat::zeros(img3f.size(), CV_32F); cv::normalize(regSal1v, regSal1v, 0, 1, NORM_MINMAX, CV_32F); float* regSal = (float*)regSal1v.data; for (int r = 0; r < img3f.rows; r++){ const int* regIdx = regIdx1i.ptr<int>(r); float* sal = sal1f.ptr<float>(r); for (int c = 0; c < img3f.cols; c++) sal[c] = regSal[regIdx[c]]; } GaussianBlur(sal1f, sal1f, Size(3, 3), 0); return sal1f; }
Mat RegionSaliency::GetRCCB(const Mat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma, double centerBiasWeight, double centerBiasHeightSigma, double centerBiasWidthSigma, const CenterBiasCombinationType_t cbct) { Mat regIdx1i, colorIdx1i, regSal1v, tmp, _img3f, color3fv; if (Quantize(img3f, colorIdx1i, color3fv, tmp) <= 2) // Color quantization return Mat::zeros(img3f.size(), CV_32F); cvtColor(img3f, _img3f, CV_BGR2Lab); cvtColor(color3fv, color3fv, CV_BGR2Lab); int regNum = SegmentImage(_img3f, regIdx1i, segSigma, segK, segMinSize); vector<Region> regs(regNum); BuildRegions(regIdx1i, regs, colorIdx1i, color3fv.cols); RegionContrast(regs, color3fv, regSal1v, sigmaDist); float* regsCenterBias = new float[regNum]; // the center-bias for each region float w0 = (float)centerBiasWidthSigma; // std. dev. of the Gaussian (width) float h0 = (float)centerBiasHeightSigma; // std. dev. of the Gaussian (height) for (int i = 0; i < regNum; i++) { const float x0 = 0.5; const float y0 = 0.5; regsCenterBias[i] = ( exp((-SQR(regs[i].centroid.x-x0))/SQR(w0)) * exp((-SQR(regs[i].centroid.y-y0))/SQR(h0)) ); } Mat sal1f = Mat::zeros(img3f.size(), CV_32F); cv::normalize(regSal1v, regSal1v, 0, 1, NORM_MINMAX, CV_32F); float* regSal = (float*)regSal1v.data; for (int r = 0; r < img3f.rows; r++) { const int* regIdx = regIdx1i.ptr<int>(r); float* sal = sal1f.ptr<float>(r); for (int c = 0; c < img3f.cols; c++) { switch (cbct) { case CB_LINEAR: sal[c] = (1-centerBiasWeight)*regSal[regIdx[c]] + centerBiasWeight*regsCenterBias[regIdx[c]]; break; case CB_PRODUCT: sal[c] = regSal[regIdx[c]] * regsCenterBias[regIdx[c]]; // weighting in this case would have no influence break; case CB_MAX: sal[c] = std::max((1-centerBiasWeight)*regSal[regIdx[c]], centerBiasWeight*regsCenterBias[regIdx[c]]); break; case CB_MIN: sal[c] = std::min((1-centerBiasWeight)*regSal[regIdx[c]], centerBiasWeight*regsCenterBias[regIdx[c]]); break; default: assert(false); exit(-1); } } } GaussianBlur(sal1f, sal1f, Size(3, 3), 0); delete [] regsCenterBias; return sal1f; }
Mat CmSaliencyRC::GetRC(CMat &img3f, CMat ®Idx1i, int regNum, double sigmaDist) { Mat colorIdx1i, regSal1v, tmp, color3fv; int QuatizeNum = Quantize(img3f, colorIdx1i, color3fv, tmp); if (QuatizeNum == 2){ printf("QuatizeNum == 2, %d: %s\n", __LINE__, __FILE__); Mat sal; compare(colorIdx1i, 1, sal, CMP_EQ); sal.convertTo(sal, CV_32F, 1.0/255); return sal; } if (QuatizeNum <= 2) // Color quantization return Mat::zeros(img3f.size(), CV_32F); cvtColor(color3fv, color3fv, CV_BGR2Lab); vector<Region> regs(regNum); BuildRegions(regIdx1i, regs, colorIdx1i, color3fv.cols); RegionContrast(regs, color3fv, regSal1v, sigmaDist); Mat sal1f = Mat::zeros(img3f.size(), CV_32F); cv::normalize(regSal1v, regSal1v, 0, 1, NORM_MINMAX, CV_32F); float* regSal = (float*)regSal1v.data; for (int r = 0; r < img3f.rows; r++){ const int* regIdx = regIdx1i.ptr<int>(r); float* sal = sal1f.ptr<float>(r); for (int c = 0; c < img3f.cols; c++) sal[c] = regSal[regIdx[c]]; } Mat bdReg1u = GetBorderReg(regIdx1i, regNum, 0.02, 0.4); sal1f.setTo(0, bdReg1u); SmoothByHist(img3f, sal1f, 0.1f); SmoothByRegion(sal1f, regIdx1i, regNum); sal1f.setTo(0, bdReg1u); GaussianBlur(sal1f, sal1f, Size(3, 3), 0); return sal1f; }