48 typedef unsigned char BYTE;
54 float r1,
r2,
r3,
cxp1,
cxp2,
cxp3,
cxm1,
cxm2,
cxm3,
rh = 1000.,
xc0,
yc0,
del,
76 unsigned element_size;
77 unsigned pointer_size;
96 element_size =
sizeof(
BYTE);
97 pointer_size =
sizeof(
BYTE *);
100 element_size =
sizeof(
UWORD);
101 pointer_size =
sizeof(
UWORD *);
104 element_size =
sizeof(
ULONG);
105 pointer_size =
sizeof(
ULONG *);
109 element_size =
sizeof(float);
110 pointer_size =
sizeof(
float *);
116 row_alloc =
ALLOC_SIZE / (col * element_size);
117 all_size = row_alloc * col * element_size;
118 tot_size = ((long) element_size) * ((long) row) * ((long) col);
119 no_blocks = tot_size / all_size;
120 rest_size = tot_size - ((long) no_blocks) * ((long) all_size);
121 rest_rows = rest_size / (col * element_size);
125 if ((temp = (
char **) malloc(row * pointer_size)) == NULL)
131 for (i = 0; i < no_blocks; i++)
133 if ((aux = (
char *)malloc((
long)all_size)) == NULL)
135 for (j = 0; j <
i; j++)
136 free(temp[j*row_alloc]);
140 for (k = 0; k < row_alloc; k++, j++)
141 temp [j] = aux + k * col * element_size;
148 if ((aux = (
char *)malloc((
long)rest_size)) == NULL)
150 for (j = 0; j < no_blocks; j++)
151 free(temp[j*row_alloc]);
155 for (k = 0; k < rest_rows; k++, j++)
156 temp [j] = aux + k * col * element_size;
161 return (
void **)temp;
174 unsigned element_size;
189 element_size =
sizeof(
BYTE);
192 element_size =
sizeof(
UWORD);
195 element_size =
sizeof(
ULONG);
199 element_size =
sizeof(float);
205 row_alloc =
ALLOC_SIZE / (col * element_size);
206 all_size = row_alloc * col * element_size;
207 tot_size = ((long) element_size) * ((long) row) * ((long) col);
208 no_blocks = tot_size / all_size;
212 for (i = 0; i < no_blocks; i++)
213 if (image [i*row_alloc] != NULL)
214 free(image [i*row_alloc]);
218 if (image [i*row_alloc] != NULL)
219 free(image [i*row_alloc]);
231 float intfila1, intfila2;
243 return intfila1 + (x -
i)*(intfila2 - intfila1);
251 static float a[266],
b[257];
253 double xp1, xp2, xp3, xm1, xm2, xm3;
254 double axp1, axp2, axp3, axm1, axm2, axm3;
255 short i7, iz2, iz1, kv, l1, l2, i1,
i,
j;
256 float r,
x,
y, zz, ai, bi;
266 for (i7 = 1; i7 <=
ir; i7++)
270 for (i = 1; i <=
mu; i++)
275 for (kv = 1; kv <=
ncic; kv++)
277 x = xc0 + r *
coseno[iz1];
278 y = yc0 + r * coseno[iz1-
mu4];
281 x = xc0 + r * coseno[iz1];
282 y = yc0 + r * coseno[iz1-
mu4];
286 x = xc0 + r * coseno[iz2];
287 y = yc0 + r * coseno[iz2-
mu4];
290 x = xc0 + r * coseno[iz2];
291 y = yc0 + r * coseno[iz2-
mu4];
303 xp2 = xm2 * coseno[mu4-
ncic2];
306 for (i = 1; i <=
mu1; i++)
311 xp1 += (ai * ai * coseno[l1]);
312 xp2 += (bi * bi * coseno[l1-
ncic2]);
313 xp3 += (ai * bi * coseno[l1-
ncic]);
316 xm3 += (ai * bi * coseno[mu4+
ncic]);
320 for (j = i1; j <=
mu; j++)
325 double ajai2=2.0*aj*ai;
326 double bjbi2=2.0*bj*bi;
329 xp1 += (ajai2 * coseno[l1]);
330 xm1 += (ajai2 * coseno[l2]);
331 xp2 += (bjbi2 * coseno[l1-
ncic2]);
332 xm2 += (bjbi2 * coseno[l2]);
333 xp3 += ((aibj + ajbi) * coseno[l1-
ncic]);
334 xm3 += (aibj * coseno[l2-
ncic] + ajbi * coseno[l2+
ncic]);
353 float racua, rbcua, dr, r;
360 dr = 3.141592653 / (ralto -
rbajo);
361 for (k = 1; k <=
lancho; k++)
364 for (j = 1; j <=
largo; j++)
375 i = (
short int)(((
float) isuma) / n + .5);
378 for (k = 1; k <=
lancho; k++)
381 for (j = 1; j <=
largo; j++)
396 printf(
"\nImage smoothed. Outer mean = %d\n",
m);
401 static float f[22][22];
402 float pi = 3.141592653;
403 short in1, mu5,
i, mu3, ind, ind1, indice, iflag,
j, ix=0, iy=0,
k;
404 float h, th, costh, sinth, fi, anc, xk0, yk0, hpi,
x,
y,
z, xx, yy;
405 float b,
g, d1, e1, ext;
424 b = 2. / (th * th) * (1. + costh * costh - sin(2. * th) / th);
425 g = 4. / (th * th) * (sinth / th - costh);
427 e1 = d1 * sinth * 2.;
430 for (i = 1; i <= mu5; i++)
437 for (i = 1; i <= mu5; i++)
457 anc = (int)(3. +
in *
del);
466 hpi = h / 2. / pi /
ir;
467 cxp1 = 2. * b * e1 * hpi;
468 cxp2 = -2. * g * d1 * hpi;
469 cxp3 = 2. * (g * e1 - b * d1) * hpi;
470 cxm1 = (b * b + e1 * e1) * hpi;
471 cxm2 = (g * g + d1 * d1) * hpi;
472 cxm3 = 2. * (b * g - d1 * e1) * hpi;
477 for (i = 1; i <= ind; i++)
479 for (j = 1; j <= ind; j++)
496 for (i = 1; i <= ind; i++)
497 for (j = 1; j <= ind; j++)
506 yc0 = yc0 + (iy -
in - 1) * del;
507 if (ix == 1 || ix == ind || iy == 1 || iy == ind)
517 f[1][1] = f[ix-1][iy-1];
518 f[ind][1] = f[ix+1][iy-1];
519 f[1][ind] = f[ix-1][iy+1];
520 f[ind][ind] = f[ix+1][iy+1];
521 f[1][in1] = f[ix-1][iy];
522 f[in1][1] = f[ix][iy-1];
523 f[ind][in1] = f[ix+1][iy];
524 f[in1][ind] = f[ix][iy+1];
525 f[in1][in1] = f[ix][iy];
526 x =
xc0 - (
in - 1) * del;
527 for (i = 2; i < ind1; i++)
528 { y = yc0 - (
in - 1) * del;
529 for (j = 2;j <= ind1; j++)
530 {
if (i == in1 && j == in1)
543 x =
xc0 - (
in - 1) * del;
544 y = yc0 - (
in - 1) * del;
546 for (
k = 2;
k <= ind1;
k++)
583 std::cout <<
"\nOptimal center coordinates: x= " << yc0-1 <<
" ,y= " <<
xc0-1 <<
" " << std::endl;
587 printf(
"\nNot-converged\n");
613 addUsageLine(
"Find the best symmetry of rotation of an image or collection of images");
614 addUsageLine(
"+It is very useful when you want to calculate the rotational symmetry of ");
615 addUsageLine(
"+a set of images (in fact it computes the center of the average image). ");
616 addUsageLine(
"+Image dimensions must be less than 512x512.");
618 addParamsLine(
" -i <file> : Image, image stack or image selfile");
619 addParamsLine(
" --oroot <rootname> : Rootname for output files");
620 addParamsLine(
" :+ <rootname>_center.xmd contains the image center");
621 addParamsLine(
" :+ <rootname>_analyzed_image.xmp (if verbose>=2) contains the image that was actually analyzed");
622 addParamsLine(
"[--r1+ <radius=15>] : Lowest integration radius (% of the image radius)");
623 addParamsLine(
"[--r2+ <radius=80>] : Highest integration radius (% of the image radius)");
624 addParamsLine(
"[--r3+ <radius=90>] : Lowest smoothing radius (% of the image radius)");
625 addParamsLine(
"[--r4+ <radius=100>] : Highest smoothing radius (% of the image radius)");
629 addParamsLine(
"[--opt+ <opt=-1>] : Type of optimization (-1=minimize, +1=maximize)");
657 std::cout <<
"Input: " << fnIn << std::endl
658 <<
"Output root: " << fnOroot << std::endl
659 <<
"R1: " << _r1 << std::endl
660 <<
"R2: " << _r2 << std::endl
661 <<
"R3: " << _r3 << std::endl
662 <<
"R4: " << _r4 << std::endl
663 <<
"Harmonic: " << _ncic << std::endl
664 <<
"Opt: " << _indmul << std::endl
665 <<
"Initial center: (" << x0 <<
"," << y0 <<
")\n" 679 for (
size_t objId : MD.
ids())
693 size_t Xdim, Ydim, Zdim, Ndim;
711 I().rangeAdjust(0,255);
713 I.
write(fnOroot+
"_analyzed_image.xmp");
728 r1=(float)(_r1/100.0*
XSIZE(I())/2.0);
729 r2=(float)(_r2/100.0*
XSIZE(I())/2.0);
756 MD.
write(fnOroot+
"_center.xmd");
float conv1x(double y, double x)
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
void sqrt(Image< double > &op)
There is not enough memory for allocation.
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void ergrot(double xc0, double yc0, float *zzz)
void imfree(char **image, int row, int col, int format)
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
void addSeeAlsoLine(const char *seeAlso)
const char * getParam(const char *param, int arg=0)
Incorrect argument received.
int _indmul
Optimization type.
void addExampleLine(const char *example, bool verbatim=true)
int verbose
Verbosity level.
double x0
Starting center.
bool isMetaData(bool failIfNotExists=true) const
void ** imalloc(int row, int col, int format)
void defineParams()
Define parameters.
bool checkParam(const char *param)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
void addParamsLine(const String &line)
#define IMGPIXEL(I, i, j)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const