88 else if (radius <= 30)
93 else if (radius <= 100)
104 double smallballradius = radius / shrinkFactor;
105 if (smallballradius < 1)
107 double r2 = smallballradius * smallballradius;
108 int xtrim = (int) (arcTrimPer * smallballradius) / 100;
109 int halfWidth =
ROUND(smallballradius - xtrim);
110 int ballWidth = 2 * halfWidth + 1;
115 double temp = r2 -
i *
i -
j *
j;
116 ball(
i, j) = temp > 0. ?
sqrt(temp) : 0.;
121 int sXdim = (
XSIZE(I) + shrinkFactor - 1) / shrinkFactor;
122 int sYdim = (
YSIZE(I) + shrinkFactor - 1) / shrinkFactor;
125 for (
int ySmall = 0; ySmall < sYdim; ySmall++)
127 for (
int xSmall = 0; xSmall < sXdim; xSmall++)
129 double minVal = 1e38;
130 for (
int j = 0,
y = shrinkFactor * ySmall;
131 j < shrinkFactor &&
y < (int)
YSIZE(I);
j++, y++)
132 for (
int k = 0,
x = shrinkFactor * xSmall;
133 k < shrinkFactor &&
x < (int)
XSIZE(I);
k++, x++)
136 if (thispixel < minVal)
144 radius = ballWidth / 2;
148 for (
int yb = -radius; yb < (int)
YSIZE(shrinkI) + radius; yb++)
151 int y0 = yb - radius;
154 int y0b = y0 - yb + radius;
155 int yF = yb + radius;
156 if (yF >= (
int)
YSIZE(shrinkI))
157 yF = (
int)
YSIZE(shrinkI) - 1;
159 for (
int xb = -radius; xb < (int)
XSIZE(shrinkI) + radius; xb++)
162 int x0 = xb - radius;
165 int x0b = x0 - xb + radius;
166 int xF = xb + radius;
167 if (xF >= (
int)
XSIZE(shrinkI))
168 xF = (
int)
XSIZE(shrinkI) - 1;
171 for (
int yp = y0, ybp = y0b; yp <=
yF; yp++, ybp++)
172 for (
int xp = x0, xbp = x0b; xp <=
xF; xp++, xbp++)
179 for (
int yp = y0, ybp = y0b; yp <=
yF; yp++, ybp++)
180 for (
int xp = x0, xbp = x0b; xp <=
xF; xp++, xbp++)
208 std::queue<int> list_for_compute;
210 std::vector<double> bg_values;
211 size_t xdim =
XSIZE(bg);
212 size_t ydim =
YSIZE(bg);
213 size_t zdim =
ZSIZE(bg);
216 if (
j == 0 ||
j == xdim - 1 ||
i == 0 ||
i == ydim - 1 ||
k == 0
224 if ((
j == 1 ||
j == xdim - 2) && (
i != 0) && (
i != ydim - 1) && (
k != 0)
227 list_for_compute.push(
j);
228 list_for_compute.push(
i);
229 list_for_compute.push(
k);
231 if ((
i == 1 ||
i == ydim - 2) && (
j > 1) && (
j < xdim - 2) && (
k != 0)
234 list_for_compute.push(
j);
235 list_for_compute.push(
i);
236 list_for_compute.push(
k);
238 if ((
k == 1 ||
k == zdim - 2) && (
j > 1) && (
j < xdim - 2) && (
i > 1)
241 list_for_compute.push(
j);
242 list_for_compute.push(
i);
243 list_for_compute.push(
k);
253 while (!list_for_compute.empty())
265 A = avg - (z * stddev);
266 B = avg + (z * stddev);
270 int x_coord = list_for_compute.front();
271 list_for_compute.pop();
272 int y_coord = list_for_compute.front();
273 list_for_compute.pop();
274 int z_coord = list_for_compute.front();
275 list_for_compute.pop();
281 if (A <= value && value <= B)
286 bg_values.push_back(value);
291 for (
int xx = x_coord - 1; xx <= x_coord + 1; xx++)
292 for (
int yy = y_coord - 1; yy <= y_coord + 1; yy++)
293 for (
int zz = z_coord - 1; zz <= z_coord + 1; zz++)
298 list_for_compute.push(xx);
299 list_for_compute.push(yy);
300 list_for_compute.push(zz);
329 (*I)().rangeAdjust(0, 255);
342 float filling_colour,
bool less,
int neighbourhood)
344 I_in.checkDimension(2);
346 std::list<Coordinate2D> iNeighbours;
358 iNeighbours.push_front(coord);
361 A2D_ELEM(I_out, i, j) = filling_colour;
363 while (!iNeighbours.empty())
366 coord = iNeighbours.front();
367 iNeighbours.pop_front();
368 iCurrenti = coord.
ii;
369 iCurrentj = coord.
jj;
371 #define CHECK_POINT(i,j) \ 375 if (INSIDEXY(I_out,J,I)) { \ 376 double pixel=A2D_ELEM(I_out,I,J);\ 377 if (pixel!=filling_colour) \ 378 if ((less && pixel < stop_colour) || \ 379 (!less && pixel > stop_colour)) { \ 382 A2D_ELEM (I_out,coord.ii,coord.jj)=filling_colour; \ 383 iNeighbours.push_front(coord); \ 393 if (neighbourhood == 8)
414 float filling_colour,
bool less)
416 V_in.checkDimension(3);
418 std::list<Coordinate3D> iNeighbours;
432 iNeighbours.push_front(coord);
435 A3D_ELEM(V_out, k, i, j) = filling_colour;
437 while (!iNeighbours.empty())
440 coord = iNeighbours.front();
441 iNeighbours.pop_front();
442 iCurrenti = coord.
ii;
443 iCurrentj = coord.
jj;
444 iCurrentk = coord.
kk;
449 #define CHECK_POINT_3D(k,i,j) \ 454 if (INSIDEXYZ(V_out,J,I,K)) { \ 455 double voxel=A3D_ELEM(V_out,K,I,J); \ 456 if (voxel!=filling_colour) \ 457 if ((less && voxel < stop_colour)|| \ 458 (!less &&voxel > stop_colour)) { \ 462 A3D_ELEM (V_out,coord.kk,coord.ii,coord.jj)=filling_colour; \ 463 iNeighbours.push_front(coord); \ 501 V_in.checkDimension(3);
503 std::list<Coordinate3D> iNeighbours;
518 iNeighbours.push_front(coord);
524 while (!iNeighbours.empty())
527 coord = iNeighbours.front();
528 iNeighbours.pop_front();
529 iCurrenti = coord.
ii;
530 iCurrentj = coord.
jj;
531 iCurrentk = coord.
kk;
536 #undef CHECK_POINT_3D 537 #define CHECK_POINT_3D(k,i,j) \ 542 if (INSIDEXYZ(V_out,J,I,K)) { \ 543 if (A3D_ELEM(V_in,K,I,J)==bgColor && A3D_ELEM(V_out,K,I,J)==1) { \ 547 A3D_ELEM (V_out,coord.kk,coord.ii,coord.jj)=filling_value; \ 548 iNeighbours.push_front(coord); \ 587 std::list<int> toExplore;
589 in.checkDimension(2);
594 #define CHECK_POINT_DIST(i,j,proposedDistance) \ 600 ip=intWRAP(ip,STARTINGY(out),FINISHINGY(out));\ 601 jp=intWRAP(jp,STARTINGX(out),FINISHINGX(out));\ 603 if (ip>=STARTINGY(out) && ip<=FINISHINGY(out) && \ 604 jp>=STARTINGX(out) && jp<=FINISHINGX(out)) \ 605 if (out(ip,jp)>proposedDistance) \ 607 out(ip,jp)=proposedDistance; \ 608 toExplore.push_back(ip); \ 609 toExplore.push_back(jp); \ 610 toExplore.push_back(proposedDistance); \ 626 while (!toExplore.empty())
628 int i = toExplore.front();
629 toExplore.pop_front();
630 int j = toExplore.front();
631 toExplore.pop_front();
632 int proposedDistance = toExplore.front();
633 toExplore.pop_front();
635 if (proposedDistance == out(i, j))
657 if (label(
i,
j) != 1)
663 if (label(
i,
j) != 0)
664 label(
i,
j) = label(
i,
j) - 31999;
665 return colour - 32000;
677 if (label(
k,
i,
j) != 1)
685 return colour - 32000;
733 int nbest =
XSIZE(best) - 1;
734 double total = nlabel.
sum();
735 double explained = nlabel(best(nbest));
736 while (explained < percentage * total)
739 explained += nlabel(best(nbest));
745 bool among_the_best =
false;
746 for (
int k = nbest;
k < imax + 1;
k++)
749 among_the_best =
true;
764 I(
i,
j) = 1 - I(
i,
j);
768 if (label(
i,
j) == l0)
777 int kernelSize_2 = kernelSize/2;
779 kernel.
resize(kernelSize,kernelSize);
796 for (
int i=kernelSize_2;
i<=(int)
YSIZE(I)-kernelSize_2;
i+=kernelSize_2)
797 for (
int j=kernelSize_2;
j<=(int)
XSIZE(I)-kernelSize_2;
j+=kernelSize_2)
801 xF =
j+kernelSize_2-1;
802 yF =
i+kernelSize_2-1;
813 I.
window(kernel, y0, x0, yF, xF);
814 kernel.
computeStats(avgKernel, stdKernel, min_val, max_val);
823 filter.
w1 = kernelSize_2;
841 for (
int j=0;
j<kernelSize;
j++)
845 else if (
i>
YSIZE(I)-kernelSize)
855 else if (
i>
YSIZE(I)-kernelSize)
860 for (
int j=kernelSize;
j<
XSIZE(I)-kernelSize; ++
j)
861 for (
int i=0;
i<kernelSize;
i++)
863 for (
int j=kernelSize;
j<
XSIZE(I)-kernelSize; ++
j)
872 int kernelSize_2 = kernelSize/2;
874 kernel.
resize(kernelSize,kernelSize);
889 for (
int i=kernelSize_2;
i<(int)
YSIZE(I);
i+=kernelSize_2)
890 for (
int j=kernelSize_2;
j<(int)
XSIZE(I);
j+=kernelSize_2)
894 xF =
j+kernelSize_2-1;
895 yF =
i+kernelSize_2-1;
906 I.
window(kernel, y0, x0, yF, xF);
907 kernel.
computeStats(avgKernel, stdKernel, min_val, max_val);
908 varKernel = stdKernel*stdKernel;
918 filter.
w1 = kernelSize_2;
928 auto ysize =
static_cast<int>YSIZE(I);
929 auto xsize =
static_cast<int>XSIZE(I);
951 mAvgAuxBin = 1-mAvgAuxBin;
968 I = 1-(mVarBin*mAvgBin);
992 filter.
w1 = varKernelSize/8;
1011 hist.
sort(sortedList);
1014 for (
int i=0;
i<
XSIZE(sortedList);
i++)
1020 double fair_area = height*
XSIZE(hist)/2.0;
1022 double giniValue = (fair_area-area)/fair_area;
1046 mom1(0) = hist(0) *
x;
1047 for (
size_t i = 1;
i <
XSIZE(mom0);
i++)
1049 mom0(
i) = mom0(
i - 1) + hist(
i);
1051 mom1(
i) = mom1(
i - 1) + hist(
i) *
x;
1055 double bestSigma2B = -1;
1056 int ibestSigma2B = -1;
1057 for (
size_t i = 0;
i <
XSIZE(hist) - 1;
i++)
1059 double w1 = mom0(
i);
1060 double w2 = 1 - mom0(
i);
1061 double mu1 = mom1(
i);
1062 double mu2 = mom1(
XSIZE(mom1) - 1) - mom1(
i);
1063 double sigma2B = w1 * w2 * (mu1 - mu2) * (mu1 - mu2);
1064 if (sigma2B > bestSigma2B)
1066 bestSigma2B = sigma2B;
1093 for (
size_t i = 1;
i <
XSIZE(mom0);
i++)
1094 mom0(
i) = mom0(
i - 1) + hist(
i);
1102 for (
size_t i = 0;
i <
XSIZE(hist);
i++)
1105 double w1 = mom0(
i);
1107 for (
size_t ii = 0; ii <=
i; ii++)
1108 if (hist(ii) > epsilon)
1110 double aux = hist(ii) / w1;
1111 h1(
i) -= aux *
log10(aux);
1115 double w2 = 1 - mom0(
i);
1117 for (
size_t ii =
i + 1; ii <
XSIZE(hist); ii++)
1120 double aux = hist(ii) / w2;
1121 h2(
i) -= aux *
log10(aux);
1126 double Hmax = h1(0) + h2(0);
1128 for (
size_t i = 1;
i <
XSIZE(hist) - 1;
i++)
1130 double H = h1(
i) + h2(
i);
1146 bool binarizeVolume)
1164 mom1(0) = hist(0) *
x;
1165 for (
size_t i = 1;
i <
XSIZE(mom0);
i++)
1167 mom0(
i) = mom0(
i - 1) + hist(
i);
1169 mom1(
i) = mom1(
i - 1) + hist(
i) *
x;
1178 for (
size_t i = 0;
i <
XSIZE(hist);
i++)
1181 double w1 = mom0(
i);
1183 for (
size_t ii = 0; ii <=
i; ii++)
1184 if (hist(ii) > epsilon)
1186 double aux = hist(ii) / w1;
1187 h1(
i) -= aux *
log10(aux);
1191 double w2 = 1 - mom0(
i);
1193 for (
size_t ii =
i + 1; ii <
XSIZE(hist); ii++)
1196 double aux = hist(ii) / w2;
1197 h2(
i) -= aux *
log10(aux);
1208 for (
size_t i = 0;
i <
XSIZE(hist) - 1;
i++)
1210 double w1 = mom0(
i);
1211 double w2 = 1 - mom0(
i);
1212 double mu1 = mom1(
i);
1213 double mu2 = mom1(
XSIZE(mom1) - 1) - mom1(
i);
1214 sigma2B(
i) = w1 * w2 * (mu1 - mu2) * (mu1 - mu2);
1215 H(
i) = h1(
i) + h2(
i);
1216 HSigma2B(
i) = -
log10(sigma2B(
i)) / H(
i);
1224 HSigma2B.
sort(HSigma2Bsorted);
1230 while (
A1D_ELEM(HSigma2B,iTh) >= threshold)
1248 double retvalxy = 0;
1249 double isigma = 1.0 / sigma;
1265 return (retvalxy / maskSum);
1275 0.000049233388666, 0.000599785460091, 0.002688051941039, 0.004431848411938, 0.002688051941039, 0.000599785460091, 0.000049233388666,
1276 0.000599785460091, 0.007306882745281, 0.032747176537767, 0.053990966513188, 0.032747176537767, 0.007306882745281, 0.000599785460091,
1277 0.002688051941039, 0.032747176537767, 0.146762663173740, 0.241970724519143, 0.146762663173740, 0.032747176537767, 0.002688051941039,
1278 0.004431848411938, 0.053990966513188, 0.241970724519143, 0.398942280401433, 0.241970724519143, 0.053990966513188, 0.004431848411938,
1279 0.002688051941039, 0.032747176537767, 0.146762663173740, 0.241970724519143, 0.146762663173740, 0.032747176537767, 0.002688051941039,
1280 0.000599785460091, 0.007306882745281, 0.032747176537767, 0.053990966513188, 0.032747176537767, 0.007306882745281, 0.000599785460091,
1281 0.000049233388666, 0.000599785460091, 0.002688051941039, 0.004431848411938, 0.002688051941039, 0.000599785460091, 0.000049233388666};
1285 int imiddle=
YSIZE(I1)/2;
1286 int jmiddle=
XSIZE(I1)/2;
1287 int R2max=imiddle*imiddle;
1288 int ysize=(int)
YSIZE(I1);
1289 int xsize=(int)
XSIZE(I1);
1290 for (
int i=3;
i<ysize-3; ++
i)
1292 int i2=(
i-imiddle)*(
i-imiddle);
1293 for (
int j=3;
j<xsize-3; ++
j)
1295 int j2=(
j-jmiddle)*(
j-jmiddle);
1300 for (
int ii=-3; ii<=3; ++ii)
1305 double imedAux=(*refW++)*(*diffj++);
1306 imedAux+=(*refW++)*(*diffj++);
1307 imedAux+=(*refW++)*(*diffj++);
1308 imedAux+=(*refW++)*(*diffj++);
1309 imedAux+=(*refW++)*(*diffj++);
1310 imedAux+=(*refW++)*(*diffj++);
1311 imedAux+=(*refW++)*(*diffj++);
1313 imed+=imedAux*diffi;
1326 const double w[7][7]={
1327 {0.000049233388666, 0.000599785460091, 0.002688051941039, 0.004431848411938, 0.002688051941039, 0.000599785460091, 0.000049233388666},
1328 {0.000599785460091, 0.007306882745281, 0.032747176537767, 0.053990966513188, 0.032747176537767, 0.007306882745281, 0.000599785460091},
1329 {0.002688051941039, 0.032747176537767, 0.146762663173740, 0.241970724519143, 0.146762663173740, 0.032747176537767, 0.002688051941039},
1330 {0.004431848411938, 0.053990966513188, 0.241970724519143, 0.398942280401433, 0.241970724519143, 0.053990966513188, 0.004431848411938},
1331 {0.002688051941039, 0.032747176537767, 0.146762663173740, 0.241970724519143, 0.146762663173740, 0.032747176537767, 0.002688051941039},
1332 {0.000599785460091, 0.007306882745281, 0.032747176537767, 0.053990966513188, 0.032747176537767, 0.007306882745281, 0.000599785460091},
1333 {0.000049233388666, 0.000599785460091, 0.002688051941039, 0.004431848411938, 0.002688051941039, 0.000599785460091, 0.000049233388666}
1335 int imiddle=
YSIZE(I1)/2;
1336 int jmiddle=
XSIZE(I1)/2;
1337 int R2max=imiddle*imiddle;
1344 for (
int i=3;
i<ydim-3; ++
i)
1346 int i2=(
i-imiddle)*(
i-imiddle);
1347 for (
int j=3;
j<xdim-3; ++
j)
1349 int j2=(
j-jmiddle)*(
j-jmiddle);
1359 double diffAvg=avg1-avg2;
1364 for (
int i=3;
i<ydim-3; ++
i)
1366 int i2=(
i-imiddle)*(
i-imiddle);
1367 for (
int j=3;
j<xdim-3; ++
j)
1369 int j2=(
j-jmiddle)*(
j-jmiddle);
1375 for (
int ii=-3; ii<=3; ++ii)
1378 for (
int jj=-3; jj<=3; ++jj)
1383 double wiijj=w[ii+3][jj+3];
1384 imed+=wiijj*diffi*diffj;
1391 return imed/
sqrt((imed1+imed2)/2);
1420 double sumMI1I2=0.0;
1421 double sumMI1I1=0.0;
1422 double sumMI2I2=0.0;
1449 corrM1M2=sumMI1I2/
sqrt(sumMI1I1*sumMI2I2);
1493 double sumWI1I2=0.0;
1494 double sumWI1I1=0.0;
1495 double sumWI2I2=0.0;
1522 sumWI1I1 +=wp1a*p1a;
1523 sumWI2I2 +=wp2a*p2a;
1524 sumWI1I2 +=wp1a*p2a;
1527 corrW1W2=sumWI1I2/
sqrt(sumWI1I1*sumWI2I2);
1588 C*=1.0/(
YSIZE(I)-1.0);
1593 template<
typename T>
1606 bool neighbourhood =
true;
1614 if (mask !=
nullptr)
1616 if ((*mask).sum() < 2)
1618 shiftX = shiftY = 0.;
1625 double istdcorr = 1.0 / stdcorr;
1643 int maxShift2=maxShift*maxShift;
1644 double bestCorr=std::numeric_limits<T>::lowest();
1645 for (
int i=-maxShift;
i<=maxShift;
i++)
1646 for (
int j=-maxShift;
j<=maxShift;
j++)
1648 if (
i*
i+
j*
j>maxShift2)
1654 bestCorr=
A2D_ELEM(Mcorr, imax, jmax);
1662 while (neighbourhood)
1665 for (
int i = -n_max;
i <= n_max && neighbourhood;
i++)
1667 i_actual =
i + imax;
1670 neighbourhood =
false;
1673 for (
int j = -n_max;
j <= n_max && neighbourhood;
j++)
1675 j_actual =
j + jmax;
1678 neighbourhood =
false;
1681 else if (max / 1.414 >
A2D_ELEM(Mcorr, i_actual, j_actual))
1683 neighbourhood =
false;
1692 double sumcorr = 0.;
1701 for (
int i = -n_max;
i <= n_max;
i++)
1703 i_actual =
i + imax;
1704 for (
int j = -n_max;
j <= n_max;
j++)
1706 j_actual =
j + jmax;
1707 double val =
A2D_ELEM(Mcorr, i_actual, j_actual);
1708 ymax += i_actual * val;
1709 xmax += j_actual * val;
1715 shiftX = xmax / sumcorr;
1716 shiftY = ymax / sumcorr;
1726 I1.checkDimension(2);
1727 I2.checkDimension(2);
1732 return bestShift(Mcorr, shiftX, shiftY, mask, maxShift);
1740 return bestShift(I1,aux.
FFT1,I2,shiftX,shiftY,aux,mask,maxShift);
1751 return bestShift(Mcorr, shiftX, shiftY, mask, maxShift);
1756 double &shiftX,
double &shiftY,
double &shiftZ,
CorrelationAux &aux,
1759 I1.checkDimension(3);
1760 I2.checkDimension(3);
1776 bool neighbourhood =
true;
1787 if (mask !=
nullptr)
1789 if ((*mask).sum() < 2)
1791 shiftX = shiftY = shiftZ = 0.;
1798 double istdcorr = 1.0 / stdcorr;
1811 max =
A3D_ELEM(Mcorr, kmax, imax, jmax);
1815 while (neighbourhood)
1818 for (
int k = -n_max;
k <= n_max && neighbourhood;
k++)
1820 k_actual =
k + kmax;
1823 neighbourhood =
false;
1826 for (
int i = -n_max;
i <= n_max && neighbourhood;
i++)
1828 i_actual =
i + imax;
1831 neighbourhood =
false;
1834 for (
int j = -n_max;
j <= n_max && neighbourhood;
j++)
1836 j_actual =
j + jmax;
1840 neighbourhood =
false;
1844 / 1.414 >
A3D_ELEM(Mcorr, k_actual, i_actual, j_actual))
1846 neighbourhood =
false;
1855 zmax = xmax = ymax = sumcorr = 0.;
1868 for (
int k = -n_max;
k <= n_max;
k++)
1870 k_actual =
k + kmax;
1871 for (
int i = -n_max;
i <= n_max;
i++)
1873 i_actual =
i + imax;
1874 for (
int j = -n_max;
j <= n_max;
j++)
1876 j_actual =
j + jmax;
1877 double val =
A3D_ELEM(Mcorr, k_actual, i_actual, j_actual);
1878 zmax += k_actual * val;
1879 ymax += i_actual * val;
1880 xmax += j_actual * val;
1887 shiftX = xmax / sumcorr;
1888 shiftY = ymax / sumcorr;
1889 shiftZ = zmax / sumcorr;
1907 I1.checkDimension(2);
1908 I2.checkDimension(2);
1910 bestShift(I1, FFTI1, I2, shiftX, shiftY, aux);
1915 translate(1, Iaux, I1,
vectorR2(-shiftX, -shiftY), xmipp_transformation::DONT_WRAP);
1918 double finalX = shiftX;
1919 double finalY = shiftY;
1922 std::cout <<
"shiftX=" << shiftX <<
" shiftY=" << shiftY
1923 <<
" corr=" << corr << std::endl;
1926 save.
write(
"PPPI1.xmp");
1928 save.
write(
"PPPI2.xmp");
1930 save.
write(
"PPPpp.xmp");
1934 double testX = (shiftX > 0) ? (shiftX -
XSIZE(I1)) : (shiftX +
XSIZE(I1));
1935 double testY = shiftY;
1936 translate(1, Iaux, I1,
vectorR2(-testX, -testY), xmipp_transformation::DONT_WRAP);
1939 if (corr > bestCorr)
1943 std::cout <<
"shiftX=" << testX <<
" shiftY=" << testY
1944 <<
" corr=" << corr << std::endl;
1946 save.
write(
"PPPmp.xmp");
1951 testY = (shiftY > 0) ? (shiftY -
YSIZE(I1)) : (shiftY +
YSIZE(I1));
1952 translate(1, Iaux, I1,
vectorR2(-testX, -testY), xmipp_transformation::DONT_WRAP);
1955 if (corr > bestCorr)
1959 std::cout <<
"shiftX=" << testX <<
" shiftY=" << testY
1960 <<
" corr=" << corr << std::endl;
1962 save.
write(
"PPPpm.xmp");
1966 testX = (shiftX > 0) ? (shiftX -
XSIZE(I1)) : (shiftX +
XSIZE(I1));
1967 testY = (shiftY > 0) ? (shiftY -
YSIZE(I1)) : (shiftY +
YSIZE(I1));
1968 translate(1, Iaux, I1,
vectorR2(-testX, -testY), xmipp_transformation::DONT_WRAP);
1971 if (corr > bestCorr)
1977 std::cout <<
"shiftX=" << testX <<
" shiftY=" << testY
1978 <<
" corr=" << corr << std::endl;
1980 save.
write(
"PPPmm.xmp");
1990 double &shiftX,
double &shiftY,
1993 I1.checkDimension(2);
1994 I2.checkDimension(2);
1996 double bestCorr=-1e38;
2000 int maxShift2=maxShift*maxShift;
2002 for (
double y=-maxShift;
y<=maxShift;
y+=shiftStep)
2003 for (
double x=-maxShift;
x<=maxShift;
x+=shiftStep)
2005 if (
y*
y+
x*
x>maxShift2)
2051 I.checkDimension(2);
2069 for (
int i = 0;
i < 3;
i++)
2116 if (corrRS > corrSR)
2135 Iref.checkDimension(2);
2138 return alignImages(Iref, IrefTransforms, I, M, wrap, aux, aux2, aux3);
2147 return alignImages(Iref, I, M, wrap, aux, aux2, aux3);
2161 double corr=
alignImages(Iref, IrefTransforms, I, M, wrap, aux, aux2, aux3);
2162 double corrMirror=
alignImages(Iref, IrefTransforms, Imirror, Mmirror, wrap, aux, aux2, aux3);
2168 double bestCorr = corr;
2169 if (corrMirror > bestCorr)
2171 bestCorr = corrMirror;
2200 bool considerMirror)
2214 for (
int n = 0;
n < Niter; ++
n)
2216 bool lastIteration = (
n == (Niter - 1));
2219 for (
size_t objId : MD.
ids())
2223 I().setXmippOrigin();
2227 aux3, xmipp_transformation::WRAP);
2229 corr =
alignImages(Iavg, I(), M, xmipp_transformation::WRAP, aux, aux2, aux3);
2262 double bestAngle = 0;
2266 if (corr > bestCorr)
2272 bestAngle *= deltaAng * 180.0 /
PI;
2280 double deltaAng = atan(2.0 /
XSIZE(I));
2286 2 *
PI, deltaAng, v);
2294 double deltaAng = atan(2.0 /
XSIZE(I));
2300 2 *
PI, deltaAng, v);
2308 double deltaAng = atan(2.0 /
XSIZE(I));
2314 2 *
PI, deltaAng, v);
2345 const String &eulerAngles,
2360 Iref.checkDimension(3);
2361 I.checkDimension(3);
2364 "Both volumes should be of the same shape");
2366 double deltaAng = atan(2.0 /
XSIZE(I));
2372 0, 2 *
PI, deltaAng, v);
2382 double x =
XX(r) -
XX(mu);
2383 double y =
YY(r) -
YY(mu);
2386 * (sigmainv(0, 0) * x * x + 2 * sigmainv(0, 1) * x * y
2387 + sigmainv(1, 1) * y * y));
2394 I.checkDimension(2);
2404 for (
int n = 0;
n < iterations;
n++)
2419 double val =
z(
i,
j);
2430 double val =
z(
i,
j);
2431 double j_mu =
j -
XX(mu);
2432 double i_mu =
i -
YY(mu);
2433 sigma(0, 0) += val * j_mu * j_mu;
2434 sigma(0, 1) += val * i_mu * j_mu;
2435 sigma(1, 1) += val * i_mu * i_mu;
2437 sigma(1, 0) = sigma(0, 1);
2461 z(
i,
j) = I(
i,
j) - a * G;
2470 double r2,
int k1,
int k2)
2472 img_in.checkDimension(2);
2474 for (
int k = k1;
k <= k2;
k++)
2483 double my = 1 +
PI * r2 / 2 / k_1;
2484 double my4 = my * k_1;
2485 double ntot = 4 * my4;
2490 double my = 1 +
PI * r2 / 2;
2492 double ntot = 4 * my4;
2498 sine(
i) = sin((
i + 1) * h);
2516 img.checkDimension(2);
2518 int Ydim1 =
YSIZE(img) - 1;
2519 int Xdim1 =
XSIZE(img) - 1;
2521 double Kinv = 1.0 /
K;
2532 for (
int i = 1;
i < Ydim1;
i++)
2536 for (
int j = 1;
j < Xdim1;
j++)
2541 double D =
dAij(img,
i,
j);
2542 double F =
dAij(surface_strength,
i,
j);
2543 double S =
dAij(edge_strength,
i,
j);
2544 double diff = D - F;
2545 E1 += w0 * diff * diff;
2546 E3 += w2 * K * S * S;
2550 * (
dAij(surface_strength,
i, jp1)
2551 -
dAij(surface_strength,
i, jm1));
2553 * (
dAij(surface_strength, ip1,
j)
2554 -
dAij(surface_strength, im1,
j));
2557 * (
dAij(edge_strength,
i, jp1)
2558 -
dAij(edge_strength,
i, jm1));
2561 * (
dAij(edge_strength, ip1,
j)
2562 -
dAij(edge_strength, im1,
j));
2564 E2 += w1 * S_1 * S_1 * (Fx * Fx + Fy * Fy);
2565 E4 += w3 * Kinv * (Sx * Sx + Sy * Sy);
2569 return E1 + E2 + E3 + E4;
2581 img.checkDimension(2);
2585 size_t Ydim1 =
YSIZE(img) - 1;
2586 size_t Xdim1 =
XSIZE(img) - 1;
2591 for (
size_t i = 1;
i < Ydim1;
i++)
2595 for (
size_t j = 1;
j < Xdim1;
j++)
2600 double S =
dAij(edge_strength,
i,
j);
2603 * (
dAij(edge_strength,
i, jp1)
2604 -
dAij(edge_strength,
i, jm1));
2607 * (
dAij(edge_strength, ip1,
j)
2608 -
dAij(edge_strength, im1,
j));
2611 double nS2 = nS * nS;
2617 double SS_i_jp1 =
dAij(surface_strength,
i, jp1);
2618 double SS_i_jm1 =
dAij(surface_strength,
i, jm1);
2619 double SS_ip1_j =
dAij(surface_strength, ip1,
j);
2620 double SS_im1_j =
dAij(surface_strength, im1,
j);
2621 double Fx = 0.5 * (SS_i_jp1 - SS_i_jm1);
2622 double Fy = 0.5 * (SS_ip1_j - SS_im1_j);
2623 double Fxx = SS_i_jp1 + SS_i_jm1;
2624 double Fyy = SS_ip1_j + SS_im1_j;
2627 double wFx = 4 * w1 * nS * Sx;
2628 double wFy = 4 * w1 * nS * Sy;
2629 double wFxx = -2 * w1 * nS2;
2630 double wFyy = -2 * w1 * nS2;
2633 double Constant = -2 * w0 * D;
2634 double Central = -2 * w0 + 2 * wFxx + 2 * wFyy;
2635 double Neighbors = wFx * Fx + wFy * Fy + wFxx * Fxx + wFyy * Fyy;
2638 F = (Constant + Neighbors) / Central;
2642 double SS_i_j =
dAij(surface_strength,
i,
j);
2643 Diff += fabs(SS_i_j - F);
2644 Norm += fabs(SS_i_j);
2647 dAij(surface_strength,
i,
j) = F;
2662 img.checkDimension(2);
2666 size_t Ydim1 =
YSIZE(img) - 1;
2667 size_t Xdim1 =
XSIZE(img) - 1;
2668 double Kinv = 1.0 /
K;
2674 for (
size_t i = 1;
i < Ydim1;
i++)
2678 for (
size_t j = 1;
j < Xdim1;
j++)
2685 * (
dAij(surface_strength,
i, jp1)
2686 -
dAij(surface_strength,
i, jm1));
2688 * (
dAij(surface_strength, ip1,
j)
2689 -
dAij(surface_strength, im1,
j));
2690 double Constant = w1 * (Fx * Fx + Fy * Fy);
2693 double Central = w2 * K + w3 * Kinv * 4;
2694 double Neighbors = w3 * Kinv
2695 * (
dAij(edge_strength, im1,
j) +
dAij(edge_strength, ip1,
j)
2696 +
dAij(edge_strength,
i, jm1)
2697 +
dAij(edge_strength,
i, jp1));
2700 double Old_edge_strength =
dAij(edge_strength,
i,
j);
2701 double S = (Constant + Neighbors) / (Constant + Central);
2703 dAij(edge_strength,
i,
j) *= 0.5;
2705 dAij(edge_strength,
i,
j) = 0.5
2706 * (
dAij(edge_strength,
i,
j) + 1);
2708 dAij(edge_strength,
i,
j) = S;
2711 Diff += fabs(
dAij(edge_strength,
i,
j) - Old_edge_strength);
2712 Norm += fabs(Old_edge_strength);
2723 int OuterLoops,
int InnerLoops,
int RefinementLoops,
2727 img.checkDimension(2);
2734 for (
int k = 1;
k <= RefinementLoops;
k++)
2741 ((
i < OuterLoops) && OuterLoops)
2743 && !OuterLoops);
i++)
2748 for (
int j = 0;
j < InnerLoops;
j++)
2753 for (
int j = 0;
j < InnerLoops;
j++)
2757 Shah_energy(img, surface_strength, edge_strength,
k, W);
2767 V.checkDimension(3);
2769 double alphax =
XX(alpha);
2770 double alphay =
YY(alpha);
2771 double alphaz =
ZZ(alpha);
2777 double regError = 0;
2778 for (
size_t z = 1;
z <
ZSIZE(V) - 1;
z++)
2779 for (
size_t y = 1;
y <
YSIZE(V) - 1;
y++)
2780 for (
size_t x = 1;
x <
XSIZE(V) - 1;
x++)
2786 alphax * diffx * diffx + alphay * diffy * diffy
2787 + alphaz * diffz * diffz);
2794 for (
size_t z = 2;
z <
ZSIZE(V) - 2;
z++)
2795 for (
size_t y = 2;
y <
YSIZE(V) - 2;
y++)
2796 for (
size_t x = 2;
x <
XSIZE(V) - 2;
x++)
2805 diffx = V000 - V_200;
2806 diffy = V_110 - V_1_10;
2807 diffz = V_101 - V_10_1;
2810 alphax * diffx * diffx + alphay * diffy * diffy
2811 + alphaz * diffz * diffz);
2819 diffx = V200 - V000;
2820 diffy = V110 - V1_10;
2821 diffz = V101 - V10_1;
2824 alphax * diffx * diffx + alphay * diffy * diffy
2825 + alphaz * diffz * diffz);
2831 diffx = V1_10 - V_1_10;
2832 diffy = V000 - V0_20;
2833 diffz = V0_11 - V0_1_1;
2836 alphax * diffx * diffx + alphay * diffy * diffy
2837 + alphaz * diffz * diffz);
2843 diffx = V110 - V_110;
2844 diffy = V020 - V000;
2845 diffz = V011 - V01_1;
2848 alphax * diffx * diffx + alphay * diffy * diffy
2849 + alphaz * diffz * diffz);
2853 diffx = V10_1 - V_10_1;
2854 diffy = V01_1 - V0_1_1;
2855 diffz = V000 - V00_2;
2858 alphax * diffx * diffx + alphay * diffy * diffy
2859 + alphaz * diffz * diffz);
2863 diffx = V101 - V_101;
2864 diffy = V011 - V0_11;
2865 diffz = V002 - V000;
2868 alphax * diffx * diffx + alphay * diffy * diffy
2869 + alphaz * diffz * diffz);
2873 * (alphax * (t1 - t2) + alphay * (t3 - t4)
2874 + alphaz * (t5 - t6));
2879 save.
write(
"PPPvolume.vol");
2881 save.
write(
"PPPgradient.vol");
2882 std::cout <<
"Press any key\n";
2888 for (
size_t z = 2;
z <
ZSIZE(V) - 2;
z++)
2889 for (
size_t y = 2;
y <
YSIZE(V) - 2;
y++)
2890 for (
size_t x = 2;
x <
XSIZE(V) - 2;
x++)
2903 img.checkDimension(2);
2913 double normalize_x = 2.0 /
XSIZE(img);
2914 double normalize_y = 2.0 /
YSIZE(img);
2919 if (mask !=
nullptr)
2922 double val = img(
i,
j);
2923 double dx =
j * normalize_x;
2924 double dy =
i * normalize_y;
2925 double dx2 = dx *
dx;
2926 double dx3 = dx2 *
dx;
2927 double dy2 = dy * dy;
2928 double dy3 = dy2 * dy;
2930 m_11 += val * dx * dy;
2933 m_12 += val * dx * dy2;
2934 m_21 += val * dx2 * dy;
2943 v_out(0) = m_20 + m_02;
2944 v_out(1) = (m_20 - m_02) * (m_20 - m_02) + 4 * m_11 * m_11;
2945 v_out(2) = (m_30 - 3 * m_12) * (m_30 - 3 * m_12)
2946 + (3 * m_21 - m_03) * (3 * m_21 - m_03);
2947 v_out(3) = (m_30 + m_12) * (m_30 + m_12) + (m_21 + m_03) * (m_21 + m_03);
2949 (m_30 - 3 * m_12) * (m_30 + m_12)
2950 * ((m_30 + m_12) * (m_30 + m_12)
2951 - 3 * (m_21 + m_03) * (m_21 + m_03))
2952 + (3 * m_21 - m_03) * (m_21 + m_03)
2953 * (3 * (m_30 + m_12) * (m_30 + m_12)
2954 - (m_21 + m_03) * (m_21 + m_03));
2974 img.checkDimension(2);
2980 double normalize_x = 2.0 /
XSIZE(img);
2981 double normalize_y = 2.0 /
YSIZE(img);
2986 if (mask !=
nullptr)
2989 double val = img(
i,
j);
2990 double dx =
j * normalize_x;
2991 double dy =
i * normalize_y;
2992 double dx2 = dx *
dx;
2993 double dy2 = dy * dy;
2994 m_11 += val * dx * dy;
3004 A(0, 1) = A(1, 0) = m_11;
3008 v_out = v_out.
sort();
3014 img.checkDimension(2);
3023 for (
int y2 = 0; y2 < 2; y2++)
3025 if (ty[y2] > ty[y2 + 1]
3026 || (ty[y2] == ty[y2 + 1] && tx[y2] < tx[y2 + 1]))
3029 ty[y2] = ty[y2 + 1];
3032 tx[y2] = tx[y2 + 1];
3039 int dx1 = tx[1] - tx[0];
3040 int dx2 = tx[2] - tx[0];
3041 int dy1 = ty[1] - ty[0];
3042 int dy2 = ty[2] - ty[0];
3044 int sx1 =
SGN0(dx1);
3045 int sx2 =
SGN0(dx2);
3046 int sy1 =
SGN0(dy1);
3061 x1 = x2 = y1 = y2 = 0;
3103 for (
int myx = xl; myx <= xr; myx++)
3104 img(y, myx) = color;
3107 dx1 = tx[2] - tx[1];
3108 dy1 = ty[2] - ty[1];
3158 for (
int myx = xl; myx <= xr; myx++)
3159 img(y, myx) = color;
3173 if (mask !=
nullptr)
3181 for (
int ii = ii0; ii <= iiF; ii++)
3182 for (
int jj = jj0; jj <= jjF; jj++)
3184 if (mask ==
nullptr)
3186 convolved(
i,
j) += img(ii, jj);
3189 else if ((*mask)(
i,
j))
3191 convolved(
i,
j) += img(ii, jj);
3196 convolved(
i,
j) /= N;
3203 if (mask !=
nullptr)
3206 if (img(
i,
j) - convolved(
i,
j) > C)
3214 I.checkDimension(2);
3226 double meanShiftX = 0;
3227 double meanShiftY = 0;
3232 meanShiftX += shiftX;
3233 meanShiftY += shiftY;
3235 meanShiftX += shiftX;
3236 meanShiftY += shiftY;
3241 VECTOR_R2(shift, -meanShiftX, -meanShiftY);
3251 I.checkDimension(2);
3266 rotationalCorr.
resize(2 * polarFourierI.getSampleNoOuterRing() - 1);
3268 double bestRot =
best_rotation(polarFourierIx, polarFourierI, aux);
3271 rotate(3, I, auxI, -bestRot / 2, xmipp_transformation::WRAP);
3280 I.checkDimension(2);
3310 for (
int i = 0;
i < Niter;
i++)
3328 double meanShiftX = 0;
3329 double meanShiftY = 0;
3339 save.
write(
"PPPx.xmp");
3340 std::cout <<
"con Ix: " << shiftX <<
" " << shiftY << std::endl;
3343 if (fabs(shiftX) <
XSIZE(I) / 3 || !limitShift)
3345 meanShiftX += shiftX;
3348 if (fabs(shiftY) <
YSIZE(I) / 3 || !limitShift)
3350 meanShiftY += shiftY;
3357 save.
write(
"PPPy.xmp");
3358 std::cout <<
"con Iy: " << shiftX <<
" " << shiftY << std::endl;
3361 if (fabs(shiftX) <
XSIZE(I) / 3 || !limitShift)
3363 meanShiftX += shiftX;
3366 if (fabs(shiftY) <
YSIZE(I) / 3 || !limitShift)
3368 meanShiftY += shiftY;
3375 save.
write(
"PPPxy.xmp");
3376 std::cout <<
"con Ixy: " << shiftX <<
" " << shiftY << std::endl;
3379 if (fabs(shiftX) <
XSIZE(I) / 3 || !limitShift)
3381 meanShiftX += shiftX;
3384 if (fabs(shiftY) <
YSIZE(I) / 3 || !limitShift)
3386 meanShiftY += shiftY;
3394 MAT_ELEM(A,0,2) += -meanShiftX / 2;
3395 MAT_ELEM(A,1,2) += -meanShiftY / 2;
3404 std::cout <<
"Iter " <<
i << std::endl;
3405 std::cout <<
"shift=" << -meanShiftX <<
"," << -meanShiftY << std::endl;
3407 save.
write(
"PPP.xmp");
3409 save.
write(
"PPPshift.xmp");
3420 2 * polarFourierI.getSampleNoOuterRing() - 1);
3425 double bestRot =
best_rotation(polarFourierIx, polarFourierI, aux2);
3428 bestRot = bestRot - 180;
3440 std::cout <<
"rot=" << -bestRot/2 << std::endl;
3442 save.write(
"PPProt.xmp");
3453 else if (lineY(
i) < val)
3457 else if (lineX(
j) < val)
3466 while (lineX(x0) < thX)
3469 while (lineY(y0) < thY)
3472 while (lineX(xF) < thX)
3475 while (lineY(yF) < thY)
3477 if ((xF - x0) > (yF - y0))
3485 lineX.
write(
"PPPlineX.txt");
3486 lineY.
write(
"PPPlineY.txt");
3487 std::cout <<
"dev X=" << xF-x0 << std::endl;
3488 std::cout <<
"dev Y=" << yF-y0 << std::endl;
3490 save.write(
"PPPhorver.xmp");
3491 std::cout <<
"Press any key\n";
3534 (V_dx * V_dx) + (V_dy * V_dy) + (V_dz * V_dz));
3547 DWT(V,vol_wavelets);
3548 vol_wavelets_abs=vol_wavelets;
3555 vol_wavelets.
threshold(
"abs_below", threshold1, 0.0);
3556 IDWT(vol_wavelets,V);
3567 " [ --bad_pixels <type>] : Applied filters on bad pixels of the image.");
3570 " negative : Applied at those negative values. Positive values are untouched.");
3572 " mask <mask_file> : Applied at those pixels given by mask.");
3574 " outliers <factor> : Applied at those pixels out of the range [mean - factor*std, mean + factor*std].");
3584 if (typeStr ==
"negative")
3586 else if (typeStr ==
"mask")
3592 else if (typeStr ==
"outliers")
3619 program->
addParamsLine(
"== Log filter (for scanners) uses equation fa-fb*log(x+fc) ==");
3642 program->
addParamsLine(
"== Total Variation Denoising method for micrographs ==");
3664 " [ --background <type=plane> ] : Filters to remove the background.");
3667 " plane : Remove the plane that best fits the pixels.");
3669 " rollingball <radius> : The background is computed as a rolling ball operation.");
3679 if (typeStr ==
"plane")
3681 else if (typeStr ==
"rollingball")
3684 radius = program->
getIntParam(
"--background",
"rollingball");
3707 program->
addParamsLine(
" [ --median ] : Use median filter.");
3729 " [--diffusion] : Use anisotropic diffusion filter.");
3731 " [--shah_iter+ <outer=10> <inner=1> <refinement=1>] : Diffusion outer, inner and refinement iterations");
3734 " [--shah_weight+ <w0=0> <w1=50> <w2=50> <w3=0.02>]:Diffusion weights");
3736 " : w0 = data matching ");
3738 " : w1 = 1st derivative smooth ");
3740 " : w2 = edge strength ");
3742 " : w3 = edge smoothness ");
3745 " [--shah_only_edge+] : Produce the edge image of the diffusion");
3752 Shah_weight.resizeNoCopy(4);
3753 Shah_outer = program->
getIntParam(
"--shah_iter", 0);
3754 Shah_inner = program->
getIntParam(
"--shah_iter", 1);
3755 Shah_refinement = program->
getIntParam(
"--shah_iter", 2);
3760 Shah_edge = program->
checkParam(
"--shah_only_edge");
3765 std::cout <<
" Shah difussion\n" <<
" Outer iterations " << Shah_outer
3766 << std::endl <<
" Inner iterations " << Shah_inner << std::endl
3767 <<
" Refinement interations " << Shah_refinement << std::endl
3768 <<
" Weight " << Shah_weight.transpose() << std::endl;
3770 std::cout <<
" Generating edge image\n";
3779 smoothingShah(img, surface_strength, edge_strength, Shah_weight, Shah_outer,
3780 Shah_inner, Shah_refinement);
3782 img = edge_strength;
3784 img = surface_strength;
3792 " [--basis <file> <N=-1>] : Stack file with the basis, N is the number of elements to consider");
3798 fnBasis = program->
getParam(
"--basis");
3800 basis.read(fnBasis);
3802 basis().resize(Nbasis, 1,
YSIZE(basis()),
XSIZE(basis()));
3807 std::cout <<
" Basis filter\n" <<
" Basis file " << fnBasis << std::endl
3808 <<
" Number of basis " << Nbasis << std::endl;
3817 "Images and basis are of different size");
3839 " [ --retinex <percentile=0.9> <mask_file=\"\"> <eps=1>] : Retinex filter, remove a given percentile of the");
3840 program->
addParamsLine(
" : Laplacian within the mask, epsilon controls the behaviour at low frequency");
3863 for (
size_t k=0;
k<
ZSIZE(fimg);
k++)
3867 for (
size_t i=0;
i<
YSIZE(fimg);
i++)
3870 double filter_ki=filter_k-2*cos(
TWOPI*
YY(w));
3871 for (
size_t j=0;
j<
XSIZE(fimg);
j++)
3874 double filter_kij=filter_ki-2*cos(
TWOPI*
XX(w));
3875 if (!direct && filter_kij>0)
3876 filter_kij=1.0/filter_kij;
3885 for (
size_t i=0;
i<
YSIZE(fimg);
i++)
3889 for (
size_t j=0;
j<
XSIZE(fimg);
j++)
3892 double filter_ij=filter_i-2*cos(
TWOPI*
XX(w));
3893 if (!direct && filter_ij>0)
3894 filter_ij=1.0/filter_ij;
3909 laplacian(img,fimg,
true);
3913 double *sortedValues=
nullptr;
3918 sortedValues=
new double[Nsorted];
3929 sortedValues=
new double[Nsorted];
3935 std::sort(sortedValues,sortedValues+Nsorted);
3936 double threshold=sortedValues[(size_t)(percentile*Nsorted)];
3937 delete[] sortedValues;
3945 laplacian(img,fimg,
false);
3969 const double beta = 0.00001;
3970 const double beta2 = beta*
beta;
3974 const double K1 = ((3.0/8.0)*lambda*lambda + sigmag*sigmag - lambda*
g) / (s*s);
3975 const double K2 = lambda * (q/(s*s));
3976 const double K3 = 2.0 /
lambda;
3999 tv +=
sqrt(dXx*dXx + dXy*dXy + beta2);
4005 return 0.5*m + mu*tv;
4029 const double beta = 0.00001;
4030 const double beta2 = beta*
beta;
4033 double K1 = ((3.0/8.0)*lambda*lambda + sigmag*sigmag - lambda*
g) / (s*s);
4034 double K2 = lambda * (q/s*s);
4035 double K3 = (2.0 / (lambda*
lambda)) * (q / (s*s)) *
lambda;
4094 dTV = Xij * (2.0*dij + d_left + d_up) - X_left*d_left - X_up*d_up - dij*(X_right + X_down);
4096 if (K2*Xij + K1 > 0)
4097 dE = K3 - (q / (s*s)) * Yij /
sqrt(Xij * (q / (s*s)) * lambda + K1);
4133 double sigmag = 5.8;
4140 double xnewscale = 255.0 / (xnew.
computeMax() - xnewmin);
4143 double K1 = ((3.0/8.0)*lambda*lambda + sigmag*sigmag - lambda*
g);
4167 double thetamin = 0.001;
4168 double thetamax = 1000;
4169 double gamma = 0.0001;
4170 double sigma1 = 0.1;
4171 double sigma2 = 0.9;
4175 double fold =
denoiseTVenergy(mu, xold, origInput, mx, q, lambda, sigmag, g);
4189 for (
int kk=1; kk <= maxIter; kk++)
4201 fnew =
denoiseTVenergy(mu, xnew, origInput, mx, q, lambda, sigmag, g);
4205 while (fnew > fold + gamma*ksi*delta)
4207 double ksitsl = -0.5 * (ksi*ksi) * delta / (fnew - fold - ksi*delta);
4208 if ((ksitsl >= sigma1) && (ksitsl <= sigma2*ksi))
4219 fnew =
denoiseTVenergy(mu, xnew, origInput, mx, q, lambda, sigmag, g);
4232 if (xij > s_norm) s_norm = xij;
4265 size_t input_size =
XSIZE(X);
4274 for (
size_t i = 0;
i < input_size; ++
i)
4276 size_t order = filter_order - 1;
4290 template <
typename T>
4311 double retval = 0.0;
4316 aux_x.
resize(xdim * ydim * zdim);
4320 aux_y.
resize(xdim * ydim * zdim);
4324 if (mask !=
nullptr)
4325 if (!(*mask)(
k,
i,
j))
4340 nx = (int)((
log((
double) n) /
LOG2) + 1);
4344 ny = (int)((
log((
double) n) /
LOG2) + 1);
4353 for (
int i = 0;
i < nx;
i++)
4355 double histxi = (histx(
i)) / n;
4356 for (
int j = 0;
j < ny;
j++)
4358 double histyj = (histy(
j)) / n;
4359 double histxyij = (histxy(
i,
j)) / n;
4361 retval += histxyij *
log(histxyij / (histxi * histyj)) /
static void defineParams(XmippProgram *program)
#define FOR_ALL_ELEMENTS_IN_MATRIX2D(m)
#define VECTOR_R2(v, x, y)
static void defineParams(XmippProgram *program)
double Shah_energy(const MultidimArray< double > &img, const MultidimArray< double > &surface_strength, const MultidimArray< double > &edge_strength, double K, const Matrix1D< double > &W)
void denoiseTVFilter(MultidimArray< double > &xnew, int maxIter)
void centerImageRotationally(MultidimArray< double > &I, RotationalCorrelationAux &aux)
double imedNormalizedDistance(const MultidimArray< double > &I1, const MultidimArray< double > &I2)
void min(Image< double > &op1, const Image< double > &op2)
#define A2D_ELEM(v, i, j)
FourierTransformer transformer1
void set_DWT_type(int DWT_type)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
double giniCoeff(MultidimArray< double > &I, int varKernelSize)
MultidimArray< double > IauxRS
void centerImageTranslationally(MultidimArray< double > &I, CorrelationAux &aux)
double getDoubleParam(const char *param, int arg=0)
void threshold(const String &type, T a, T b=0, MultidimArray< int > *mask=NULL)
void subtractColumnMeans(Matrix2D< double > &A)
constexpr float INITIAL_ROTATE_THRESHOLD
void readParams(XmippProgram *program)
void forcePositive(MultidimArray< double > &V)
double alignImages(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, bool wrap, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3)
#define REPORT_ERROR(nerr, ErrormMsg)
void sort(MultidimArray< T > &result) const
void apply(MultidimArray< double > &img)
double fastBestRotationAroundY(const MultidimArray< double > &IrefCyl, const MultidimArray< double > &I, CorrelationAux &aux, VolumeAlignmentAux &aux2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
MultidimArray< double > Icyl
void matrixOperation_AB(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
void resizeNoCopy(const MultidimArray< T1 > &v)
double correlationMasked(const MultidimArray< double > &I1, const MultidimArray< double > &I2)
double OtsuSegmentation(MultidimArray< double > &V)
void readParams(XmippProgram *program)
void rotationalInvariantMoments(const MultidimArray< double > &img, const MultidimArray< int > *mask, MultidimArray< double > &v_out)
double beta(const double a, const double b)
void sqrt(Image< double > &op)
void BinaryCircularMask(MultidimArray< int > &mask, double radius, int mode, double x0, double y0, double z0)
MultidimArray< double > IauxSR
int getSampleNoOuterRing() const
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void apply(MultidimArray< double > &img)
#define DIRECT_A2D_ELEM(v, i, j)
void readParams(XmippProgram *program)
double correlationIndex(const MultidimArray< T > &x, const MultidimArray< T > &y, const MultidimArray< int > *mask=NULL, MultidimArray< double > *Contributions=NULL)
void computeAvgStdev(U &avg, U &stddev) const
void correlation_matrix(const MultidimArray< double > &m1, const MultidimArray< double > &m2, MultidimArray< double > &R, CorrelationAux &aux, bool center)
void maxIndex(int &jmax) const
double icdf_gauss(double p)
#define MULTIDIM_ARRAY(v)
void rangeAdjust(T minF, T maxF)
double fastBestRotationAroundZ(const MultidimArray< double > &IrefCyl, const MultidimArray< double > &I, CorrelationAux &aux, VolumeAlignmentAux &aux2)
void inv(Matrix2D< T > &result) const
static void defineParams(XmippProgram *program)
double fastCorrentropy(const MultidimArray< double > &x, const MultidimArray< double > &y, double sigma, const GaussianInterpolator &G, const MultidimArray< int > &mask)
double percentil(double percent_mass)
#define CHECK_POINT_DIST(i, j, proposedDistance)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(V)
void readParams(XmippProgram *program)
void readParams(XmippProgram *program)
Incorrect MultidimArray size.
void estimateGaussian2D(const MultidimArray< double > &I, double &a, double &b, Matrix1D< double > &mu, Matrix2D< double > &sigma, bool estimateMu, int iterations)
void fourierBesselDecomposition(const MultidimArray< double > &img_in, double r2, int k1, int k2)
void matrixOperation_AtA(const Matrix2D< double > &A, Matrix2D< double > &B)
void bestNonwrappingShift(const MultidimArray< double > &I1, const MultidimArray< double > &I2, double &shiftX, double &shiftY, CorrelationAux &aux)
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 rotate(a, i, j, k, l)
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define CHECK_POINT_3D(k, i, j)
double mutualInformation(const MultidimArray< T > &x, const MultidimArray< T > &y, int nx, int ny, const MultidimArray< int > *mask)
Matrix2D< double > centerImage(MultidimArray< double > &I, CorrelationAux &aux, RotationalCorrelationAux &aux2, int Niter, bool limitShift)
void detectBackground(const MultidimArray< double > &vol, MultidimArray< double > &mask, double alpha, double &final_mean)
void laplacian(const MultidimArray< double > &img, MultidimArray< std::complex< double > > &fimg, bool direct)
#define MAT_ELEM(m, i, j)
void threshold(double *phi, unsigned long nvox, double limit)
#define A3D_ELEM(V, k, i, j)
double Update_edge_Shah(MultidimArray< double > &img, MultidimArray< double > &surface_strength, MultidimArray< double > &edge_strength, double K, const Matrix1D< double > &W)
constexpr float ROTATE_THRESHOLD
void varianceFilter(MultidimArray< double > &I, int kernelSize, bool relative)
#define DIRECT_A1D_ELEM(v, i)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
double best_rotation(const Polar< std::complex< double > > &I1, const Polar< std::complex< double > > &I2, RotationalCorrelationAux &aux)
void closing3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
void index2val(double i, double &v) const
void log(Image< double > &op)
void window(MultidimArray< T1 > &result, int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T1 init_value=0) const
void computeAlignmentTransforms(const MultidimArray< double > &I, AlignmentTransforms &ITransforms, AlignmentAux &aux, CorrelationAux &aux2)
const char * getParam(const char *param, int arg=0)
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
MultidimArray< double > I12
double unnormalizedGaussian2D(const Matrix1D< double > &r, const Matrix1D< double > &mu, const Matrix2D< double > &sigmainv)
void distanceTransform(const MultidimArray< int > &in, MultidimArray< int > &out, bool wrap)
void binarize(double val=0, double accuracy=XMIPP_EQUAL_ACCURACY, MultidimArray< int > *mask=NULL)
static void defineParams(XmippProgram *program)
void DWT(const MultidimArray< T > &v, MultidimArray< double > &result, int isign=1)
double correlationWeighted(MultidimArray< double > &I1, MultidimArray< double > &I2)
void matrixOperation_AtB(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
double EntropyOtsuSegmentation(MultidimArray< double > &V, double percentil, bool binarizeVolume)
void computeAvgStddev(const std::vector< T > &V, double &avg, double &stddev)
#define XMIPP_EQUAL_ACCURACY
bool sameShape(const MultidimArrayBase &op) const
MultidimArray< double > corr
constexpr double INITIAL_SHIFT_THRESHOLD
void resize(size_t Xdim, bool copy=true)
void apply(MultidimArray< double > &img)
double imedDistance(const MultidimArray< double > &I1, const MultidimArray< double > &I2)
void alignSetOfImages(MetaData &MD, MultidimArray< double > &Iavg, int Niter, bool considerMirror)
void write(const FileName &fn) const
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
Error related to numerical calculation.
Polar< std::complex< double > > polarFourierI
void removeSmallComponents(MultidimArray< double > &I, int size, int neighbourhood)
void contrastEnhancement(Image< double > *I)
MultidimArray< double > rotationalCorr
void regionGrowing2D(const MultidimArray< double > &I_in, MultidimArray< double > &I_out, int i, int j, float stop_colour, float filling_colour, bool less, int neighbourhood)
#define DIRECT_MULTIDIM_ELEM(v, n)
double getValue(double x) const
void denoiseTVproj(const MultidimArray< double > &X, const MultidimArray< double > &Y, double theta, MultidimArray< double > &dold)
void apply(MultidimArray< double > &img)
void matrixOperation_ABt(const Matrix2D< double > &A, const Matrix2D< double > &B, Matrix2D< double > &C)
void computeEdges(const MultidimArray< double > &vol, MultidimArray< double > &vol_edge)
static void defineParams(XmippProgram *program)
void log10(Image< double > &op)
Matrix1D< double > vectorR2(double x, double y)
MultidimArray< std::complex< double > > FFT1
#define NZYX_ELEM(v, l, k, i, j)
void smoothingShah(MultidimArray< double > &img, MultidimArray< double > &surface_strength, MultidimArray< double > &edge_strength, const Matrix1D< double > &W, int OuterLoops, int InnerLoops, int RefinementLoops, bool adjust_range)
void sort(struct DCEL_T *dcel)
#define DIRECT_A3D_ELEM(v, k, i, j)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
static void defineParams(XmippProgram *program)
MultidimArray< double > I1
void svdcmp(const Matrix2D< T > &a, Matrix2D< double > &u, Matrix1D< double > &w, Matrix2D< double > &v)
#define NEXT_POWER_OF_2(x)
void pixelDesvFilter(MultidimArray< T > &V, double thresFactor)
double bestRotationAroundZ(const MultidimArray< double > &Iref, const MultidimArray< double > &I, CorrelationAux &aux, VolumeAlignmentAux &aux2)
void copyShape(const MultidimArrayBase &m)
template void polarFourierTransform< true >(MultidimArray< double > const &, Polar< double > &, Polar< std::complex< double > > &, bool, int, int, Polar_fftw_plans *&, int)
T fastCorrelation(const MultidimArray< T > &x, const MultidimArray< T > &y)
#define CHECK_POINT(i, j)
void apply(MultidimArray< double > &img)
void apply(MultidimArray< double > &img)
void regionGrowing3DEqualValue(const MultidimArray< double > &V_in, MultidimArray< int > &V_out, int filling_value=0)
void matlab_filter(Matrix1D< double > &B, Matrix1D< double > &A, const MultidimArray< double > &X, MultidimArray< double > &Y, MultidimArray< double > &Z)
constexpr double SHIFT_THRESHOLD
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
constexpr double SHAH_CONVERGENCE_THRESHOLD
MultidimArray< double > I123
void regionGrowing3D(const MultidimArray< double > &V_in, MultidimArray< double > &V_out, int k, int i, int j, float stop_colour, float filling_colour, bool less)
int labelImage2D(const MultidimArray< double > &I, MultidimArray< double > &label, int neighbourhood)
void boundMedianFilter(MultidimArray< T > &V, const MultidimArray< char > &mask, int n=0)
void fillBinaryObject(MultidimArray< double > &I, int neighbourhood)
double fastBestRotationAroundX(const MultidimArray< double > &IrefCyl, const MultidimArray< double > &I, CorrelationAux &aux, VolumeAlignmentAux &aux2)
double Update_surface_Shah(MultidimArray< double > &img, MultidimArray< double > &surface_strength, MultidimArray< double > &edge_strength, const Matrix1D< double > &W)
void translate(PDB *pdb_original, PDB *pdb_move, unsigned num_atoms, double x0, double y0, double z0)
double bestShiftRealSpace(const MultidimArray< double > &I1, MultidimArray< double > &I2, double &shiftX, double &shiftY, const MultidimArray< int > *mask, int maxShift, double shiftStep)
MultidimArray< double > IrefCyl
FourierTransformer local_transformer
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
void logFilter(MultidimArray< T > &V, double a, double b, double c)
void keepBiggestComponent(MultidimArray< double > &I, double percentage, int neighbourhood)
void medianFilter3x3(MultidimArray< T > &m, MultidimArray< T > &out)
void readParams(XmippProgram *program)
double psi(const double x)
void readParams(XmippProgram *program)
double svdCorrelation(const MultidimArray< double > &I1, const MultidimArray< double > &I2, const MultidimArray< int > *mask)
void substractBackgroundRollingBall(MultidimArray< double > &I, int radius)
#define realWRAP(x, x0, xF)
double tomographicDiffusion(MultidimArray< double > &V, const Matrix1D< double > &alpha, double lambda)
void IDWT(const MultidimArray< double > &v, MultidimArray< double > &result)
template float bestShift(MultidimArray< float > &, float &, float &, const MultidimArray< int > *, int)
void copy(Matrix2D< T > &op1) const
bool checkParam(const char *param)
void forceDWTSparsity(MultidimArray< double > &V, double eps)
void fillTriangle(MultidimArray< double > &img, int *tx, int *ty, double color)
void noisyZonesFilter(MultidimArray< double > &I, int kernelSize)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Matrix1D< T > sort() const
double EntropySegmentation(MultidimArray< double > &V)
void initZeros(const MultidimArray< T1 > &op)
double computeAvg() const
static void defineParams(XmippProgram *program)
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)
void localThresholding(MultidimArray< double > &img, double C, double dimLocal, MultidimArray< int > &result, MultidimArray< int > *mask)
int labelImage3D(const MultidimArray< double > &V, MultidimArray< double > &label)
int getIntParam(const char *param, int arg=0)
double alignImagesConsideringMirrors(const MultidimArray< double > &Iref, const AlignmentTransforms &IrefTransforms, MultidimArray< double > &I, Matrix2D< double > &M, AlignmentAux &aux, CorrelationAux &aux2, RotationalCorrelationAux &aux3, bool wrap, const MultidimArray< int > *mask)
double fastBestRotation(const MultidimArray< double > &IrefCyl, const MultidimArray< double > &Icyl, CorrelationAux &aux, VolumeAlignmentAux &aux2, double deltaAng)
void substractBackgroundPlane(MultidimArray< double > &I)
void denoiseTVgradient(double mu, const MultidimArray< double > &X, const MultidimArray< double > &Y, double s, double q, double lambda, double sigmag, double g, MultidimArray< double > &gradientI)
double denoiseTVenergy(double mu, const MultidimArray< double > &X, const MultidimArray< double > &Y, double s, double q, double lambda, double sigmag, double g)
void addParamsLine(const String &line)
void indexSort(MultidimArray< int > &indx) const
void statisticsAdjust(U avgF, U stddevF)
void applyMaskSpace(MultidimArray< double > &v)
void covarianceMatrix(const MultidimArray< double > &I, Matrix2D< double > &C)
void volume_convertCartesianToCylindrical(const MultidimArray< double > &in, MultidimArray< double > &out, double Rmin, double Rmax, double deltaR, float angMin, double angMax, float deltaAng, Matrix1D< double > &axis)
void inertiaMoments(const MultidimArray< double > &img, const MultidimArray< int > *mask, Matrix1D< double > &v_out, Matrix2D< double > &u)
void apply(MultidimArray< double > &img)