33 #include <sys/types.h> 43 single_particle.
clear();
45 fn_coords = fn_micrograph =
"";
46 X_window_size = Y_window_size = -1;
50 compute_transmitance =
false;
51 compute_inverse =
false;
65 fn_micrograph = _fn_micrograph;
74 "Micrograph::open_micrograph: Only files with a single micrograph may be processed. Error reading " + fn_micrograph);
81 std::cerr <<
"x,y,z,n, datatype : " 126 std::cerr <<
"Micrograph::open_micrograph: Unknown datatype " 127 << datatype << std::endl;
135 (std::string)
"Micrograph::open_micrograph: There is a " 136 "problem opening " + fn_micrograph +
"\nCheck that the file has write permission");
164 std::cerr <<
"Micrograph::close_micrograph: Unknown datatype " 165 << datatype << std::endl;
177 return (8 *
sizeof(
unsigned char));
179 return (8 *
sizeof(
unsigned short));
181 return (8 *
sizeof(
short));
183 return (8 *
sizeof(
unsigned int));
185 return (8 *
sizeof(
int));
187 return (8 *
sizeof(
float));
189 std::cerr <<
"Micrograph::getDatatypeDetph: Unknown datatype " 190 << datatype << std::endl;
201 if (_fn_coords !=
"")
202 fn_coords = _fn_coords;
205 MD.
setComment((std::string)
"Selected Coordinates for file " + fn_coords);
207 for (
int i = 0;
i < imax;
i++)
227 fn_coords = _fn_coords;
242 for (
size_t objId : MD.
ids())
262 for (
int i = 0;
i < imax;
i++)
278 for (
int i = 0;
i < imax;
i++)
291 double Dmin,
double Dmax,
double scaleX,
double scaleY,
292 bool only_check,
bool fillBorders)
294 if (X_window_size == -1 || Y_window_size == -1)
296 "Micrograph::scissor: window size not set");
299 only_check, fillBorders);
302 only_check, fillBorders);
305 only_check, fillBorders);
308 only_check, fillBorders);
309 else if (datatype ==
DT_Int)
311 only_check, fillBorders);
314 only_check, fillBorders);
317 "Micrograph::scissor: unknown datatype");
324 bool rmStack,
bool fillBorders,
325 bool extractNoise,
int Nnoise)
348 M->
size(MXdim, MYdim);
349 this->
size(thisXdim, thisYdim);
350 double scaleX = (double) MXdim / thisXdim;
351 double scaleY = (double) MYdim / thisYdim;
357 if (compute_transmitance || compute_inverse)
359 (*this).computeDoubleMinMax(Dmin, Dmax);
361 if (compute_transmitance)
371 std::cout <<
"Angle from Y axis to tilt axis " << ang << std::endl
372 <<
" applying appropriate rotation\n";
374 int nparticles =
nmax;
375 if (extractNoise && Nnoise>0)
398 int minNoiseDistance=Y_window_size/2;
399 std::vector<Particle_coords> noiseCoords;
426 Pnoise.
X=int(
rnd_unif(X_window_size,thisXdim-X_window_size));
427 Pnoise.
Y=int(
rnd_unif(Y_window_size,thisYdim-Y_window_size));
429 for (
int nn=0;
nn<nparticles;
nn++)
438 noiseCoords.push_back(Pnoise);
439 t = M->
scissor(Pnoise, I(), Dmin, Dmax, scaleX, scaleY,
false, fillBorders);
442 t = M->
scissor(
coords[
n], I(), Dmin, Dmax, scaleX, scaleY,
false, fillBorders);
445 std::cout <<
"Particle " << fn_aux
446 <<
" is very near the border, " 447 <<
"corresponding image is set to blank\n";
453 double mean=I().computeAvg();
482 int prec2 = prec * prec;
483 for (
int i = 0;
i < imax;
i++)
496 "Micrograph::invalidate_coord: Index out of range");
551 else if (datatype ==
DT_Int)
574 "Micrograph::set_val::(): non supported datatype UHalfByte");
588 else if (datatype ==
DT_Int)
598 "Micrograph::set_val::(): unknown datatype");
625 coordU.push_back(_muX);
626 coordU.push_back(_muY);
627 coordT.push_back(_mtX);
628 coordT.push_back(_mtY);
633 std::cout <<
"Adding point U(" << U.X <<
"," << U.Y <<
") T(" << T.X <<
"," 635 std::cout <<
"A at input" << Au <<
"B at input" << Bt;
661 std::cout <<
"A at output" << Au <<
"B at output" << Bt;
671 addCoordinatePair(_muX, _muY, _mtX, _mtY);
672 calculatePassingMatrix();
680 Put = Put.transpose();
729 constexpr
int TRIANGLE_NO = 15000;
730 constexpr
int MIN_AREA = 15;
731 constexpr
int MAX_AREA = 250000;
748 noCombinations = Nu * (Nu - 1) * (Nu - 2) / 6;
749 while (triang < TRIANGLE_NO && counter1 < noCombinations)
757 VECTOR_R2(iju, coordU[j] - coordU[i], coordU[j+1] - coordU[i+1]);
758 VECTOR_R2(iku, coordU[k] - coordU[i], coordU[k+1] - coordU[i+1]);
759 double untilted_area = fabs(
dotProduct(iju, iku));
760 if (untilted_area < MIN_AREA
765 VECTOR_R2(ijt, coordT[j] - coordT[i], coordT[j+1] - coordT[i+1]);
766 VECTOR_R2(ikt, coordT[k] - coordT[i], coordT[k+1] - coordT[i+1]);
767 double tilted_area = fabs(
dotProduct(ijt, ikt));
768 if (tilted_area < MIN_AREA
771 if (tilted_area > MAX_AREA
778 if (tilted_area > untilted_area)
781 gamma += acos(tilted_area / untilted_area);
790 std::cout <<
"Not many particles, tilt angle may not be accurate" 800 for (
int i = 0;
i < 2;
i++)
801 for (
int j = 0;
j < 2;
j++)
806 retval += error *
error;
814 alpha_u = alpha_t = 0;
822 double best_alpha_u = 0;
823 double best_alpha_t = 0;
824 double best_fit = 1e8;
826 for (aux[1] = 0; aux[1] < 180; aux[1] += 5)
827 for (aux[2] = 0; aux[2] < 180; aux[2] += 5)
833 best_alpha_u = aux[1];
834 best_alpha_t = aux[2];
838 angles(0) = best_alpha_u;
839 angles(1) = best_alpha_t;
void addCoordinatePair(int _muX, int _muY, int _mtX, int _mtY)
Add coordinates pair.
#define VECTOR_R2(v, x, y)
void transform_coordinates(const Matrix2D< double > &M)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
int scissor(const Particle_coords &P, MultidimArray< double > &result, double Dmin, double Dmax, double scaleX=1, double scaleY=1, bool only_check=false, bool fillBorders=false)
void calculatePassingMatrix()
Calculate passing matrix.
void clear()
Clear set of coordinates.
FileName removeLastExtension() const
#define REPORT_ERROR(nerr, ErrormMsg)
FileName removeFileFormat() const
void passToUntilted(int _mtX, int _mtY, int &_muX, int &_muY)
Pass to untilted.
void read_coordinates(int label, const FileName &fn_coords)
void Euler_angles2matrix(T alpha, T beta, T gamma, Matrix2D< T > &A, bool homogeneous)
void adjustPassingMatrix(int _muX, int _muY, int _mtX, int _mtY)
Adjust passing matrix.
FileName addExtension(const String &ext) const
void write(const FileName &fileName, CastWriteMode castMode=CW_CAST)
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)
std::vector< Particle_coords > coords
void compose(const String &str, const size_t no, const String &ext="")
void abs(Image< double > &op)
void produce_all_images(int label, double minCost, const FileName &fn_root, const FileName &fn_image="", double ang=0, bool rmStack=false, bool fillBorders=false, bool extractNoise=false, int Nnoise=-1)
void passToTilted(int _muX, int _muY, int &_mtX, int &_mtY)
Pass to tilted.
Incorrect MultidimArray size.
bool containsLabel(MDLabel label) const override
void invalidate_coord(int n)
TiltPairAligner()
Empty constructor.
void set_window_size(int _X_window_size, int _Y_window_size)
double scoreVar
Score by var and Gini.
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
void open_micrograph(const FileName &fn_micrograph)
T & getValue(MDLabel label)
#define MAT_ELEM(m, i, j)
void computeAngles(double &ualpha, double &talpha, double &ogamma)
void scale_coordinates(const double &c)
int templateScissor(const Image< T > &I, const Particle_coords &P, MultidimArray< double > &result, double Dmin, double Dmax, double scaleX, double scaleY, bool only_check, bool fillBorders)
double scoreGini
Score by Gini.
Error related to numerical calculation.
File or directory does not exist.
void log10(Image< double > &op)
#define M3x3_BY_V3x1(a, M, b)
void move_last_coord_to(int x, int y)
void pixelDesvFilter(MultidimArray< T > &V, double thresFactor)
int search_coord_near(int x, int y, int prec=3) const
int add_coord(int x, int y, int label, double cost)
FileName withoutExtension() const
T dotProduct(const Matrix1D< T > &v1, const Matrix1D< T > &v2)
void set_transmitance_flag(bool flag_value)
#define VECTOR_R3(v, x, y, z)
String getFileFormat() const
double cost
Cost, scaled between 0 and 1.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Incorrect MultidimArray dimensions.
unsigned int randomize_random_generator()
bool hasStackExtension() const
void set_inverse_flag(bool flag_value)
void size(int &_Xdim, int &_Ydim) const
T * adaptForNumericalRecipes() const
int getDatatypeDetph() const
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
double fitness(double *p)
void killAdaptationForNumericalRecipes(T *m) const
void computeGamma()
Compute gamma.
#define SPEED_UP_temps012
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
void write_coordinates(int label, double minCost, const FileName &fn_coords="")
double matrix_fitness(double *p, void *prm)
void resize(int Xdim, int Ydim, const FileName &filename="")
Set micrograph size (when you do not read the file from disk)