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; }
static void SubpictureUpdate( subpicture_t *p_subpic, const video_format_t *p_fmt_src, const video_format_t *p_fmt_dst, mtime_t i_ts ) { VLC_UNUSED( p_fmt_src ); VLC_UNUSED( p_fmt_dst ); VLC_UNUSED( i_ts ); decoder_sys_t *p_sys = p_subpic->updater.p_sys->p_dec_sys; video_format_t fmt = p_sys->fmt; ASS_Image *p_img = p_subpic->updater.p_sys->p_img; /* */ p_subpic->i_original_picture_height = fmt.i_visible_height; p_subpic->i_original_picture_width = fmt.i_visible_width; /* XXX to improve efficiency we merge regions that are close minimizing * the lost surface. * libass tends to create a lot of small regions and thus spu engine * reinstanciate a lot the scaler, and as we do not support subpel blending * it looks ugly (text unaligned). */ const int i_max_region = 4; rectangle_t region[i_max_region]; const int i_region = BuildRegions( region, i_max_region, p_img, fmt.i_width, fmt.i_height ); if( i_region <= 0 ) { vlc_mutex_unlock( &p_sys->lock ); return; } /* Allocate the regions and draw them */ subpicture_region_t **pp_region_last = &p_subpic->p_region; for( int i = 0; i < i_region; i++ ) { subpicture_region_t *r; video_format_t fmt_region; /* */ fmt_region = fmt; fmt_region.i_width = fmt_region.i_visible_width = region[i].x1 - region[i].x0; fmt_region.i_height = fmt_region.i_visible_height = region[i].y1 - region[i].y0; r = subpicture_region_New( &fmt_region ); if( !r ) break; r->i_x = region[i].x0; r->i_y = region[i].y0; r->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT; /* */ RegionDraw( r, p_img ); /* */ *pp_region_last = r; pp_region_last = &r->p_next; } vlc_mutex_unlock( &p_sys->lock ); }