Esempio n. 1
0
File: C_gdt.c Progetto: hosang/gdt
static void dt2d(float *images, int depth, int height, int width) {
    int stacksize = height;
    if (width > height) stacksize = width;
    int *intstack = malloc(stacksize * sizeof(int));
    float *floatstack = malloc(stacksize * sizeof(float));
    int q, d;

    float *line_in = malloc(stacksize * sizeof(float));
    float *line_out = malloc(stacksize * sizeof(float));
    for (d = 0; d < depth; d++) {
        float *f = images + d * height * width;
        // transform rows
        for (q = 0; q < height; q++) {
            memcpy(line_in, f + (q * width), width * sizeof(float));
            dt1d(line_in, f + (q * width), width, intstack, floatstack);
        }

        // transform cols
        for (q = 0; q < width; q++) {
            strided_load(line_in, f + q, height, width);
            memcpy(line_out, line_in, height * sizeof(float));
            dt1d(line_in, line_out, height, intstack, floatstack);
            strided_store(f + q, line_out, height, width);
        }
    }
    free(line_in);
    free(line_out);

    free(intstack);
    free(floatstack);
}
void ObjectDetDeformationRule::dt(ScorePyramid pyr)
{
	m_optimum_shift_x_pyramid.shallowcopy(pyr);
	m_optimum_shift_y_pyramid.shallowcopy(pyr);

	int levels=pyr.levels();
	for (int index=0;index<levels;++index)
	{
		if (pyr.flags(index))
		{
			//judge whether the current level is valid
			Matrix<float> score_img=pyr[index];
			int rows=score_img.rows();
			int cols=score_img.cols();

			Matrix<int> shift_x(rows,cols);
			Matrix<int> shift_y(rows,cols);

			//find the optimum shift along "row" direction
			Matrix<float> intermidinate_score_img(rows,cols);
			float* inter_score_img_data=NULL;
			float* score_img_data=NULL;

			for (int i=0;i<rows;++i)
			{
				score_img_data=score_img.row(i);
				int* ix_data=shift_x.row(i);
				inter_score_img_data=intermidinate_score_img.row(i);

				dt1d(score_img_data,inter_score_img_data,ix_data,1,cols,m_def_w_x0,m_def_w_x1);
			}

			//find the optimum shift along "col" direction
			inter_score_img_data=intermidinate_score_img.row(0);
			score_img_data=score_img.row(0);

			int* iy_data=shift_y.row(0);
			for (int i=0;i<cols;++i)
			{
				dt1d(inter_score_img_data+i,score_img_data+i,iy_data+i,cols,rows,m_def_w_y0,m_def_w_y1);
			}

			Matrix<int> optimum_shift_img_x(rows,cols);
			Matrix<int> optimum_shift_img_y(rows,cols);

			int* optimum_shift_img_x_data=optimum_shift_img_x.row(0);
			int* optimum_shift_img_y_data=optimum_shift_img_y.row(0);

			int* shift_x_data=shift_x.row(0);
			int* shift_y_data=shift_y.row(0);

			for (int i=0;i<rows;++i)
			{
				for (int j=0;j<cols;++j)
				{
					int p=i*cols+j;
					optimum_shift_img_y_data[p]=shift_y_data[p];
					optimum_shift_img_x_data[p]=shift_x_data[shift_y_data[p]*cols+j];
				}
			}

			m_optimum_shift_x_pyramid[index]=optimum_shift_img_x;
			m_optimum_shift_y_pyramid[index]=optimum_shift_img_y;
		}
	}
}
Esempio n. 3
0
void dt2d(float *data, long int * label, const long int *sz) 
{
  long len = lmax2(sz[0], sz[1]); //std::max(sz[0],sz[1]);
  float *f = farray_malloc(len); //new float[len];
  long int tmp_j;
  long int i,j;
  long int *lab1 = (long int *) malloc(sz[0] * sz[1] * sizeof(long int));//new long int [sz[0]*sz[1]];
  long int *lab2 = (long int *) malloc(sz[0] * sz[1] * sizeof(long int)); //new long int [sz[0]*sz[1]];
	
	
  for (i = 0; i < sz[0]; i++) 
    {
      for (j = 0; j < sz[1]; j++) 
	{
	  f[j] = *(data + j*sz[0] + i); 
	}
		
      float *d = dt1d(f, lab1 + i*sz[1], sz[1]);
		
      for (j = 0; j < sz[1]; j++) 
	{
	  *(data + j*sz[0] + i) = d[j];
	}
      //delete [] d; 
      free(d);
      d = 0;
    }

  for (j = 0; j < sz[1]; j++) 
    {
      tmp_j = j*sz[0];
		
      for (i = 0; i < sz[0]; i++) 
	{
	  f[i] = *(data + tmp_j + i); 
	}
		
      float *d = dt1d(f, lab2 + j*sz[0], sz[0]);
		
      for (i = 0; i < sz[0]; i++) 
	{
	  long tmp = tmp_j + i;
	  *(data + tmp) = d[i];
	  long ii,jj;
		  
	  ii = *(lab2 + j*sz[0] + i);
	  jj = *(lab1 + ii*sz[1] +j);
		  
          if (label != NULL) {
            *(label + tmp) = jj*sz[0] + ii;
          }
	}
		
      //delete [] d;
      free(d);
      d = 0;
    }
  /*	  
  delete []f; f = 0;
  delete []lab1; lab1 = 0;
  delete []lab2; lab2 = 0;
  */
  free(f);
  free(lab1);
  free(lab2);
	  
  return;
	  
}
Esempio n. 4
0
void dt3d(float *data, long int * label, const long int *sz) 
{
	
	long int i,j,k;
	
	long int sz10 = sz[1]*sz[0];
	long int sz20 = sz[2]*sz[0];
	long int sz12 = sz[1]*sz[2];
	long int count;
	long int tmp_k, tmp_j;
	
	long len = std::max(std::max(sz[0], sz[1]),sz[2]);
	long len2 = sz[0]*sz[1]*sz[2];
	
	printf("%ld %ld %ld %ld %ld \n",sz10, sz20, sz12, len, len2);
	
	float *f = new float [len];
	long int *lab1 = new long int [len2];
	long int *lab2 = new long int [len2];
	long int *lab3 = new long int [len2];
	
	
	// transform along the i dimension
	for (k = 0; k<sz[2]; k++)
	{
		tmp_k =  k*sz10;
		
		for (j = 0; j < sz[1]; j++) 
		{
			tmp_j = j*sz[0];
			
			for (i = 0; i < sz[0]; i++) 
			{
				f[i] = *(data + tmp_k + tmp_j + i); 
			}
			
			float *d = dt1d(f, lab1+tmp_k+tmp_j, sz[0]); 
			
			for (i = 0; i < sz[0]; i++) 
			{					
				*(data + tmp_k + tmp_j + i) = d[i];
			}
			
			if (d) {delete [] d; d = 0;}
		}	
	}
	
	// transform along the j dimension
	for (k = 0; k < sz[2]; k++)
	{
		tmp_k =  k*sz10;
		
		for (i = 0; i < sz[0]; i++) 
		{
			
			for (j = 0; j < sz[1]; j++) 
			{
				f[j] = *(data + tmp_k + j*sz[0] + i); 
			}
			
			float *d = dt1d(f, lab2+k*sz10+i*sz[1], sz[1]);
			
			for (j = 0; j < sz[1]; j++) 
			{			
				*(data + tmp_k + j*sz[0] + i) = d[j];			
			}
			
			if (d) {delete [] d; d = 0;}
		}	
	}
	
	
	// transform along the k dimension
	for (j = 0; j<sz[1]; j++)
	{		
		tmp_j = j*sz[0];
		
		for (i = 0; i < sz[0]; i++) 
		{			
			for (k = 0; k < sz[2]; k++) 
			{
				f[k] = *(data + k*sz10 + tmp_j + i); 
			}
			
			float *d = dt1d(f, lab3+j*sz20+i*sz[2], sz[2]);
			
			for (k = 0; k < sz[2]; k++) 
			{
				*(data + k*sz10 + tmp_j + i) = d[k]; 
			}
			
			if (d) {delete [] d; d = 0;}
		}	
	}
	
	// assign pixel index
	long int ii,jj,kk;
	
	for (i = 0; i<sz[0]; i++)
	{		
		for (j = 0; j < sz[1]; j++) 
		{			
			for (k = 0; k < sz[2]; k++) 
			{
				kk = *(lab3+j*sz20+i*sz[2]+k);
				jj = *(lab2+kk*sz10+i*sz[1]+j);
				ii = *(lab1+kk*sz10+jj*sz[0]+i);
				
				*(label + k*sz10+j*sz[0]+i) = kk*sz10 + jj*sz[0] + ii;
			}
		}	
	}
	
	
	if (f) {delete [] f; f = 0;}
	if (lab1) {delete [] lab1; lab1 = 0;}
	if (lab2) {delete [] lab2; lab2 = 0;}
	if (lab3) {delete [] lab3; lab3 = 0;}
	
}