예제 #1
0
Mat CmSaliencyRC::GetBorderReg(CMat &idx1i, int regNum, double ratio, double thr)
{
	// Variance of x and y
	vecD vX(regNum), vY(regNum);
	int w = idx1i.cols, h = idx1i.rows;{
		vecD mX(regNum), mY(regNum), n(regNum); // Mean value of x and y, pixel number of region
		for (int y = 0; y < idx1i.rows; y++){
			const int *idx = idx1i.ptr<int>(y);
			for (int x = 0; x < idx1i.cols; x++, idx++)
				mX[*idx] += x, mY[*idx] += y, n[*idx]++;
		}
		for (int i = 0; i < regNum; i++)
			mX[i] /= n[i], mY[i] /= n[i];
		for (int y = 0; y < idx1i.rows; y++){
			const int *idx = idx1i.ptr<int>(y);
			for (int x = 0; x < idx1i.cols; x++, idx++)
				vX[*idx] += abs(x - mX[*idx]), vY[*idx] += abs(y - mY[*idx]);
		}
		for (int i = 0; i < regNum; i++)
			vX[i] = vX[i]/n[i] + EPS, vY[i] = vY[i]/n[i] + EPS;
	}

	// Number of border pixels in x and y border region
	vecI xbNum(regNum), ybNum(regNum); 
	int wGap = cvRound(w * ratio), hGap = cvRound(h * ratio);
	vector<Point> bPnts; { 
		ForPoints2(pnt, 0, 0, w, hGap) // Top region
			ybNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt);
		ForPoints2(pnt, 0, h - hGap, w, h) // Bottom region
			ybNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt);
		ForPoints2(pnt, 0, 0, wGap, h) // Left region
			xbNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt);
		ForPoints2(pnt, w - wGap, 0, w, h)
			xbNum[idx1i.at<int>(pnt)]++, bPnts.push_back(pnt);
	}

	Mat bReg1u(idx1i.size(), CV_8U);{  // likelihood map of border region
		double xR = 1.0/(4*hGap), yR = 1.0/(4*wGap);
		vector<byte> regL(regNum); // likelihood of each region belongs to border background
		for (int i = 0; i < regNum; i++) {
			double lk = xbNum[i] * xR / vY[i] + ybNum[i] * yR / vX[i];
			regL[i] = lk/thr > 1 ? 255 : 0; //saturate_cast<byte>(255 * lk / thr);
		}

		for (int r = 0; r < h; r++)	{
			const int *idx = idx1i.ptr<int>(r);
			byte* maskData = bReg1u.ptr<byte>(r);
			for (int c = 0; c < w; c++, idx++)
				maskData[c] = regL[*idx];
		}
	}

	for (size_t i = 0; i < bPnts.size(); i++)
		bReg1u.at<byte>(bPnts[i]) = 255;
	return bReg1u;
}
예제 #2
0
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
    // arguments
    
    const_marray mX(prhs[0]);
    const_marray mY(prhs[1]);
    const_marray mLam(prhs[2]);
    const_marray mAug(prhs[3]);
    const_marray mT0(prhs[4]);
    const_marray mSkip(prhs[5]);
    
    marray mW = duplicate(prhs[6]);
    marray mW0 = duplicate(prhs[7]);
    
    // take inputs
    
    cmat_t X = view2d<double>(mX);
    cvec_t Y = view_as_col<double>(mY);
    
    double lambda = mLam.get_scalar();
    double aug = mAug.get_scalar();
    
    double t0 = mT0.get_scalar();
    index_t skip = (index_t)mSkip.get_scalar();
    
    const index_t d = mX.nrows();
    
    // main
    
    if (aug == 0)
    {
        vec_t w(mW.ptr_real(), d, 1);
        SGD_QN trainer(w, lambda, skip, t0);
        run_sgdx(trainer, X, Y, 1);
    }
    else
    {
        vec_t w(mW.ptr_real(), d, 1);
        double& w0 = *(mW0.ptr_real());
        
        SGD_QN_A trainer(w, w0, lambda, aug, skip, t0);
        run_sgdx(trainer, X, Y, 1); 
    }
    
    // return
    
    plhs[0] = mW;
    plhs[1] = mW0;
}
예제 #3
0
파일: dataset.cpp 프로젝트: MLDL/bayesopt
  void Dataset::plotData(TLogLevel level)
  {
    // For logging purpose
    FILE_LOG(level) << "Initial points:" ;
    for(size_t i = 0; i < mY.size(); i++)
      {
	FILE_LOG(level) << "X:" << mX[i]
			<< "|Y:" << mY(i);
      }
    const double yPoint = getValueAtMinimum();
    const vectord xPoint = getPointAtMinimum();
    FILE_LOG(level) << "Best point so far:" ;
    FILE_LOG(level) << "X:" << xPoint
		    << "|Y:" << yPoint;
    
  } // plotData