Пример #1
0
ColorChannel::ColorChannel(const cv::Mat& Image)
{
    //	cv::imshow("To Convert", Image);
    //	cv::waitKey(0);

    // Should check on width and height compatible with shrinking ...

    //Convert from bgr to rgb
    cv::Mat I_rgbO = Image.clone();
    cv::Mat I_rgb;
    cv::cvtColor(I_rgbO, I_rgb, CV_BGR2RGB);

    //Convert to float-image
    cv::Mat doubleImage;
    I_rgb.convertTo(doubleImage, CV_32FC3, 1 / 255.0);

    float* MImage = Convert_ToMatlab(doubleImage, 1.0f);

    //r is radius
    int r = 1;

    float RR = 12.0 / (r * (r + 2)) - 2;

    float* rgbImage = rgbConvert(MImage, Image.rows * Image.cols, Image.channels(), 2, 1.0f);
    this->setColorSpace("luv");

    float* rgbImage_smooth = (float*)malloc(sizeof(float) * Image.cols * Image.rows * I_rgb.channels());

    // Last argument was 1 for Inria-model, is 0 for CalltechModel
    convTri1(rgbImage, rgbImage_smooth, Image.rows, Image.cols, Image.channels(), RR, 1);

    free(MImage);
    free(rgbImage);
    setChanneldata(rgbImage_smooth, Image.cols, Image.rows, Image.channels());
}
Пример #2
0
void mexFunction( int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[] ) {
  int *ns, ms[3], nDims, d, m, r, s; float *A, *B, p;
  mxClassID id; char type[1024];

  // error checking on arguments
  if(nrhs!=4) mexErrMsgTxt("Four inputs required.");
  if(nlhs > 1) mexErrMsgTxt("One output expected.");
  nDims = mxGetNumberOfDimensions(prhs[1]);
  id = mxGetClassID(prhs[1]);
  ns = (int*) mxGetDimensions(prhs[1]);
  d = (nDims == 3) ? ns[2] : 1;
  m = (ns[0] < ns[1]) ? ns[0] : ns[1];
  if( (nDims!=2 && nDims!=3) || id!=mxSINGLE_CLASS || m<4 )
    mexErrMsgTxt("A must be a 4x4 or bigger 2D or 3D float array.");

  // extract inputs
  if(mxGetString(prhs[0],type,1024))
    mexErrMsgTxt("Failed to get type.");
  A = (float*) mxGetData(prhs[1]);
  p = (float) mxGetScalar(prhs[2]);
  r = (int) mxGetScalar(prhs[2]);
  s = (int) mxGetScalar(prhs[3]);
  if( s<1 ) mexErrMsgTxt("Invalid sampling value s");
  if( r<0 ) mexErrMsgTxt("Invalid radius r");

  // create output array (w/o initializing to 0)
  ms[0]=ns[0]/s; ms[1]=ns[1]/s; ms[2]=d;
  B = (float*) mxMalloc(ms[0]*ms[1]*d*sizeof(float));
  plhs[0] = mxCreateNumericMatrix(0, 0, mxSINGLE_CLASS, mxREAL);
  mxSetData(plhs[0], B); mxSetDimensions(plhs[0],(mwSize*)ms,nDims);

  // perform appropriate type of convolution
  if(!strcmp(type,"convBox")) {
    if(r>=m/2) mexErrMsgTxt("mask larger than image (r too large)");
    convBox( A, B, ns[0], ns[1], d, r, s );
  } else if(!strcmp(type,"convTri")) {
    if(r>=m/2) mexErrMsgTxt("mask larger than image (r too large)");
    convTri( A, B, ns[0], ns[1], d, r, s );
  } else if(!strcmp(type,"conv11")) {
    if( s>2 ) mexErrMsgTxt("conv11 can sample by at most s=2");
    conv11( A, B, ns[0], ns[1], d, r, s );
  } else if(!strcmp(type,"convTri1")) {
    if( s>2 ) mexErrMsgTxt("convTri1 can sample by at most s=2");
    convTri1( A, B, ns[0], ns[1], d, p, s );
  } else if(!strcmp(type,"convMax")) {
    if( s>1 ) mexErrMsgTxt("convMax cannot sample");
    convMax( A, B, ns[0], ns[1], d, r );
  } else {
    mexErrMsgTxt("Invalid type.");
  }
}
Пример #3
0
void ChannelFeatures::SmoothChannels()
{
    //	std::cout << "Channels will be smoothed" << std::endl;

    for (int C = 0; C < this->Features.size(); C++) {
        //Declare new data-space voor smoothed
        float* smoothed = (float*)malloc(sizeof(float) * Channelwidth * Channelheight);
        // Smooth the data
        convTri1(Features[C], smoothed, Channelheight, Channelwidth, 1, 2, 1);

        //Switch the data to the smoothed version
        free(Features[C]);
        Features[C] = smoothed;
    }
}