Exemplo n.º 1
0
//---------------------------------------------------------------------------
int CombFirst4Moments2D(const ImageMatrix &Im, std::vector<double> vec) {
	double **I,**J,**J1,z4[4]={0,0,0,0},z[4];
	double matr4moments[4][N_COMB_SAMPLES];
	long m,n,n2,m2;
	long a,x,y,ii;
	int matr4moments_index;
	int vec_count=0;
	readOnlyPixels pix_plane = Im.ReadablePixels();
	long step;
	Moments4 tmpMoments;
	for (a = 0; a < 4; a++)    /* initialize */
		for (matr4moments_index = 0; matr4moments_index < N_COMB_SAMPLES; matr4moments_index++)
			matr4moments[a][matr4moments_index] = 0;

	m=Im.height;
	n=Im.width;
	I=new double*[n];
	J=new double*[n];
	J1=new double*[n];
	for (a = 0; a < n; a++) {
		I[a] = new double[m];
		J[a] = new double[m];
		J1[a] = new double[m];
	}

	for (y = 0; y < m; y++) {
		for (x = 0; x < n; x++) {
			I[x][y] = y+1;
			J[x][y] = x+1;
		}
	}

	n2 = (int)(round(n/2));
	m2 = (int)(round(m/2));

	/* major diag -45 degrees */
	matr4moments_index=0;
	step = (int)(round((double)m/10));
	if (step < 1) step = 1;
	for (ii = 1-m; ii <= m; ii = ii+step) {
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index]=z4[a];

		tmpMoments.reset();
		for (y = 0; y < m; y++) {
			for (x = 0; x < n; x++) {
				if (fabs(I[x][y] + ii - J[x][y]) < 1)
					tmpMoments.add (pix_plane(y,x));
			}
		}

		tmpMoments.momentVector(z);
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index] = z[a];
		matr4moments_index++;
	}
	vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

	/* major diag +45 degrees */
	/* fliplr J */
	for (y = 0; y < m; y++)
		for (x = 0; x < n; x++)
			J1[x][y] = J[n-1-x][y];

	matr4moments_index=0;
	step = (int)(round((double)m/10));
	if (step < 1) step = 1;
	for (ii = 1-m; ii <= m; ii = ii+step) {
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index]=z4[a];

		tmpMoments.reset();
		for (y = 0; y < m; y++) {
			for (x = 0; x < n; x++) {
				if (fabs(I[x][y] + ii - J1[x][y]) < 1)
					tmpMoments.add (pix_plane(y,x));
			}
        }

		tmpMoments.momentVector(z);
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index] = z[a];
		matr4moments_index++;
	}
	vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

	/* vertical comb */
	matr4moments_index=0;
	step = (int)(round((double)n/10));
	if (step < 1) step = 1;
	for (ii = 1-n; ii <= n; ii = ii+step) {
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index]=z4[a];

		tmpMoments.reset();
		for (y = 0; y < m; y++) {
			for (x = 0; x < n; x++) {
				if (fabs(J[x][y] + ii - n2) < 1)
					tmpMoments.add (pix_plane(y,x));
			}
		}

		tmpMoments.momentVector(z);
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index] = z[a];
		matr4moments_index++;
	}
	vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

	/* horizontal comb */
	matr4moments_index=0;
	step = (int)(round((double)m/10));
	if (step < 1) step = 1;
	for (ii = 1-m; ii <= m; ii = ii+step) {
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index] = z4[a];

		tmpMoments.reset();
		for (y = 0; y < m; y++) {
			for (x = 0; x < n; x++) {
				if (fabs(I[x][y] + ii - m2) < 1)
					tmpMoments.add (pix_plane(y,x));
			}
        }

		tmpMoments.momentVector(z);
		for (a = 0; a < 4; a++) matr4moments[a][matr4moments_index] = z[a];
		matr4moments_index++;
	}
	vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

	/* free the memory used by the function */
	for (a=0;a<n;a++) {
		delete [] I[a];
		delete [] J[a];
		delete [] J1[a];
	}
	delete [] I;
	delete [] J;
	delete [] J1;

	return(vec_count);
}
int CombFirst4Moments2D(ImageMatrix *Im, double *vec)
{  double **I,**J,**J1,*tmp,z4[4]={0,0,0,0};
   double matr4moments[4][21];
   int m,n,n2,m2;
   int a,x,y,ii;
   int matr4moments_index;
   int vec_count=0;
   int step;

   for (a=0;a<4;a++)    /* initialize */
     for (matr4moments_index=0;matr4moments_index<21;matr4moments_index++)
       matr4moments[a][matr4moments_index]=0;

   m=Im->height;
   n=Im->width;
   I=new double*[n];
   J=new double*[n];
   J1=new double*[n];
   tmp=new double[m*n];
   for (a=0;a<n;a++)
   {  I[a]=new double[m];
      J[a]=new double[m];
      J1[a]=new double[m];
   }

   for (y=0;y<Im->height;y++)
     for (x=0;x<Im->width;x++)
     {  I[x][y]=y+1;
        J[x][y]=x+1;
     }

   n2=(int)(round(n/2));
   m2=(int)(round(m/2));

   /* major diag */
   matr4moments_index=0;
   step = (int)(round((double)m/10));
   if (step < 1) step = 1;
   for (ii=1-m;ii<=m;ii=ii+step)
   {  int count=0;
      for (y=0;y<m;y++)
        for (x=0;x<n;x++)
        {  if (fabs(I[x][y]+ii-J[x][y])<1)
             tmp[count++]=Im->pixel(x,y,0).intensity;
        }
        if (count==0)
        {  for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z4[a];
        }
        else
        {  double z[4];
           get4scalMoments(tmp,count,z);
           for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z[a];
        }
      matr4moments_index++;
   }

//   func(Im, I, J,tmp, m, n, z[], z4[],matr4moments[][]);
   vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

   /* fliplr J */
   for (y=0;y<m;y++)
     for (x=0;x<n;x++)
       J1[x][y]=J[n-1-x][y];

//   matr4moments = [];

   matr4moments_index=0;
   step = (int)(round((double)m/10));
   if (step < 1) step = 1;
   for (ii=1-m;ii<=m;ii=ii+step)
   {  int count=0;
      for (y=0;y<m;y++)
        for (x=0;x<n;x++)
        {  if (fabs(I[x][y]+ii-J1[x][y])<1)
             tmp[count++]=Im->pixel(x,y,0).intensity;
        }
        if (count==0)
        {  for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z4[a];
        }
        else
        {  double z[4];
           get4scalMoments(tmp,count,z);
           for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z[a];
        }
      matr4moments_index++;
   }

//   func(Im, I, J,tmp, m, n, z[], z4[],matr4moments[][]);
   vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

   /* vertical comb */
   matr4moments_index=0;
   step = (int)(round((double)n/10));
   if (step < 1) step = 1;
   for (ii=1-n;ii<=n;ii=ii+step)
   {  int count=0;
      for (y=0;y<m;y++)
        for (x=0;x<n;x++)
        {  if (fabs(J[x][y]+ii-n2)<1)
             tmp[count++]=Im->pixel(x,y,0).intensity;
        }
        if (count==0)
        {  for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z4[a];
        }
        else
        {  double z[4];
           get4scalMoments(tmp,count,z);
           for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z[a];
        }
      matr4moments_index++;
   }
   vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

   /* horizontal comb */
   matr4moments_index=0;
   step = (int)(round((double)m/10));
   if (step < 1) step = 1;
   for (ii=1-m;ii<=m;ii=ii+step)
   {  int count=0;
      for (y=0;y<m;y++)
        for (x=0;x<n;x++)
        {  if (fabs(I[x][y]+ii-m2)<1)
             tmp[count++]=Im->pixel(x,y,0).intensity;
        }
        if (count==0)
        {  for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z4[a];
        }
        else
        {  double z[4];
           get4scalMoments(tmp,count,z);
           for (a=0;a<4;a++)
             matr4moments[a][matr4moments_index]=z[a];
        }
      matr4moments_index++;
   }
   vec_count=matr4moments_to_hist(matr4moments,vec,vec_count);

   /* free the memory used by the function */
   for (a=0;a<n;a++)
   {  delete I[a];
      delete J[a];
      delete J1[a];
   }
   delete I;
   delete J;
   delete tmp;

   return(vec_count);
}