Ejemplo n.º 1
0
void TimgFilterLogoaway::Tplane::createBorderV(unsigned char *border,const unsigned char *s,const unsigned char *e,int h,stride_t pitch,int bmode)
{
    int i;

    switch (bmode) {
        case TlogoawaySettings::BM_INTERPOLATE: {
            FIX rt,rd;
            calcGradient(s,e,h,
                         &rt,
                         &rd);
            for (i=0; i<h; i++) {
                *border++=uint8_t(rt>>16);
                rt+=rd;
            }
            break;
        }
        case TlogoawaySettings::BM_DIRECT:
        case TlogoawaySettings::BM_OPPOSITE:
            for (i=0; i<h; i++) {
                *border++=*s;
                s+=pitch;
            }
            break;
    }
}
Ejemplo n.º 2
0
bool WindscreenLocator::initialize(IplImage* imgOrigin, IplImage *src, FaceDetector* faceDetector)
{
    this->faceDetector = faceDetector;
    this->imgOrigin = imgOrigin;
    imgRGB = cvCloneImage(src);
    imgGray = cvCreateImage(cvSize(imgRGB->width, imgRGB->height), IPL_DEPTH_8U, 1);
    imgGrad = cvCloneImage(imgGray);
    imgGradV=  cvCloneImage(imgGrad);
    imgGradH=  cvCloneImage(imgGrad);

    cvCvtColor(imgRGB, imgGray, CV_RGB2GRAY);
    cvSmooth(imgGray, imgGray, CV_GAUSSIAN, 5, 5);
    calcGradient();

    vertical2X = (double*)malloc(sizeof(double) * imgGrad->width);
    horizon2X = (double*)malloc(sizeof(double) * imgGrad->width);
    horizon2Y = (double*)malloc(sizeof(double) * imgGrad->height);

    if(!vertical2X || !horizon2X || !horizon2Y)
        return false;

    memset(vertical2X, 0, sizeof(double) * imgGrad->width);
    memset(horizon2X, 0, sizeof(double) * imgGrad->width);
    memset(horizon2Y, 0, sizeof(double) * imgGrad->height);

    StripeCleaner stripeCleaner(0.08 * imgGrad->width, 3, DIR_HORIZON);
    stripeCleaner.clearStripe(imgGradV, imgRGB, 1);

    return true;
}
Ejemplo n.º 3
0
void vFileVolume::load(int loadx, int loady, int loadz) {
	setLoadDims(loadx,loady,loadz);
	voxelData = new GLubyte[dimZ*dimY*dimX];
	loadVolumeFromFile(filename);
	if (gradientFile)
		loadGradientFromFile(gradientFile);
	else
		calcGradient(); //create grad volume
}
Ejemplo n.º 4
0
int regionDetector::traverse(int x, int y, int direction)
{
  // input: coordinate, int
  //        direction, const int, LEFT, RIGHT, TOP, BOTTOM or NONE
  // output: make binary image in 'result', white pixels represents the same region
  // return: 0
  //
  // Recursive function.
  // Traverse pixels and then label.
  // When search process reaches the pixel, calcurate gradient value 
  // between current pixel and around of current pixel, 
  // total these gradient values, and then if total of gradient is 
  // smaller than threshold (default 20 or 2000), current pixel is setted as inner region
  // and next searches around pixels,
  // if larger than threshold, current pixel is setted as inner region
  // but not traverse around pixels.

  int sumGradient = 0;
  int i, j;
  CvScalar tmp;

  // check 'x' and 'y' range
  if(x < 0 || y < 0 || x >= original->width || y >= original->height)
    return 0;

  // if current pixel is already labeled, exit
  tmp = cvGet2D(result, y, x);
  if(tmp.val[0] == WHITE)
    return 0;

  // set label to current pixel
  cvSet2D(result, y, x, cvScalar(WHITE));

  // check gradient value between current pixel and around pixels
  for(i=x-1; i<=x+1; i+=2)
    for(j=y-1; j<=y+1; j+=2)
      if(i > 0 && j > 0 && i < original->width && j < original->height)
	sumGradient += calcGradient(cvPoint(x, y), cvPoint(i, j));

  // diverge by 'sumGradient'
  if(sumGradient > threshold)
    return 0;

  // search near pixel
  if(direction != BOTTOM) traverse(x, y-1, TOP);
  if(direction != TOP) traverse(x, y+1, BOTTOM);
  if(direction != LEFT) traverse(x+1, y, RIGHT);
  if(direction != RIGHT) traverse(x-1, y, LEFT);

  return 0;
}
Ejemplo n.º 5
0
void TimgFilterLogoaway::Tplane::createBorderH(unsigned char *border,const unsigned char *s,const unsigned char *e,int width,int bmode)
{
    int i;
    FIX rt,rd;

    switch (bmode) {
        case TlogoawaySettings::BM_INTERPOLATE:
            calcGradient(s,e,width,
                         &rt,
                         &rd);
            for (i=0; i<width; i++) {
                *border++=uint8_t(rt>>16);
                rt+=rd;
            }
            break;
        case TlogoawaySettings::BM_DIRECT:
        case TlogoawaySettings::BM_OPPOSITE:
            memcpy(border,s,width);
            break;
    }
}
void GeneticAlgorithm::initialiseMatrices(){
	_emat = calcEmat(_R, _basis);

	int address = 0;
	int addresses[8];
			
		for(int i = 0; i < 8; i ++){
			addresses[i] = address;
			address += (_basisPop[i])*(_R+1);
		}
		
		
		
		for(int i = 0; i < 8; i++){
		
			int ch0 = LAPACKE_dpotrf(LAPACK_ROW_MAJOR, 'U', _basisPop[i], &_emat[addresses[i]], _R);

			
		}


	_gradientCalcs = calcGradient(_R,_basis);
	return;
}
Ejemplo n.º 7
0
void TimgFilterLogoaway::Tplane::setAverageVH(const TlogoawaySettings *cfg)
{
    int i,j;
    int vstart,vend;
    int hstart,hend;
    FIX px,py;

    // Precalculate vertical (north->south) gradient parameters:
    // For each column: starting R,G,B and per-row deltas R,G,B
    for(i=0; i<w; i++)
        calcGradient(&bordn[i],&bords[i],h,
                     &vt[i],
                     &vd[i]);

    // CALCULATE RECTANGLE START AND END
    // BM_INTERPOLATE overwrites border
    // other methods do not - just leave border alone.

    if(cfg->bordn_mode==TlogoawaySettings::BM_INTERPOLATE) {
        vstart=0;
    } else {
        vstart=1;
    }

    if(cfg->bords_mode==TlogoawaySettings::BM_INTERPOLATE) {
        vend=h;
    } else {
        vend=h-1;
    }

    if(cfg->bordw_mode==TlogoawaySettings::BM_INTERPOLATE) {
        hstart=0;
    } else {
        hstart=1;
    }

    if(cfg->borde_mode==TlogoawaySettings::BM_INTERPOLATE) {
        hend=w;
    } else {
        hend=w-1;
    }

    unsigned char *pRow=logotempdata;

    // If north border unused
    // we need to skip this border with
    // one empty vertical gradient step
    if (vstart==1) {
        pRow+=logotempstride; // fix added on
        for (i=0; i<w; i++) {
            vt[i]+=vd[i];
        }
    }

    // Now fill logo area by walking each scanline
    // step by step through the logo h
    for (i=vstart; i<vend; i++) {
        int r,rd;
        // Horizontal gradient for this row
        calcGradient(&bordw[i],&borde[i],w,&r,&rd);

        if (hstart==1) { // First column step skip
            r+=rd;
        }

        // Make whole logo row
        for (j=hstart; j<hend; j++) {
            // Update vertical gradient current component
            // Next row we will need next vertical step
            vt[j]+=vd[j];
            // Make weighted H gradient component
            px=r*(10-cfg->vhweight);
            // Make weighted V gradient component
            py=vt[j]*cfg->vhweight;
            // Calc
            pRow[j]=uint8_t(((px+py)/10)>>16);
            // Next pixel, one gradient step
            r+=rd;
        }
        // Get next row start Real UP->DOWN, not VirtualDub down->up
        pRow+=logotempstride;
    }
}
Ejemplo n.º 8
0
int BaseCostFunction::applyGradient(){
   if(DEBUG) std::cout << "Cost function layer " << name << " applying gradient\n";
   //Sets gradient based on cost function subclass
   calcGradient();
   return Activation::applyGradient();
}