 |
Bsoft
2.1.0
Bernard's software package
|
Go to the documentation of this file.
44 for ( n=0; n<p->
images(); n++ ) {
77 float mg_rot_ang,
int mg_ori_select,
Bstring outimg)
84 double inplane_angle(0);
104 cout <<
"Merging particle images on micrograph series:" << endl;
105 if ( mg_ori_select == 0 ) cout <<
"Origins obtained from parameter files." << endl;
106 else if ( mg_ori_select == 1 ) cout <<
"Origins obtained from cross-correlation with reference micrograph." << endl;
107 else if ( mg_ori_select == 2 ) cout <<
"Origins obtained from particle image files." << endl;
108 else if ( mg_ori_select == -1 ) cout <<
"Images are merged without translational or rotational alignment." << endl;
112 for ( field =
project->
field, ifield=0; field; field = field->
next, ifield++ ) {
120 cout << endl <<
"Reference image file for field " << field->
id <<
": " << mg_ref->
fpart << endl;
124 error_show(
"Error in mg_particle_merge_series", __FILE__, __LINE__);
125 cerr <<
"File " << mg_ref->
fpart <<
" was not found or read in properly." << endl;
129 if ( mg_ori_select == 1 ) pref = psum->
copy();
137 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg != mg_ref ) {
139 cout <<
"Aligning and adding images in " << mg->
fpart <<
" to reference in " << mg_ref->
fpart << endl;
142 if ( mg_ori_select > -1 ) {
145 cout <<
"in-plane rotation angle = " << (180/
M_PI)*inplane_angle << endl;
154 cerr <<
"WARNING: The number of images is not consistent (" << psum->
images() <<
" and " << pimg->
images() <<
") and may cause program to crash." << endl;
158 if ( mg_ori_select > -1 ) {
162 if ( mg_ori_select == 0 ) {
164 for ( i=0, particle=mg->
part, particle_ref=mg_ref->
part; particle; i++, particle=particle->
next, particle_ref=particle_ref->
next) {
165 shifts[i] = particle_ref->
ori - particle->
ori;
166 origins[i] = particle->
ori;
172 else if ( mg_ori_select == 1 ) {
175 for ( i=0, particle=mg->
part; particle; i++, particle=particle->
next) {
182 else if ( mg_ori_select == 2 ) {
184 for ( i=0, particle=mg->
part, particle_ref=mg_ref->
part; particle; i++, particle=particle->
next, particle_ref=particle_ref->
next) {
199 for ( i=0, j=0; i<datasize; i++, j++ ) psum->
set(i, (*psum)[i] + (*pimg)[j]);
205 if ( mg_ori_select == 1 )
delete pref;
208 for ( i=0; i<datasize; i++ ) psum->
set(i, (*psum)[i] / nmgs);
214 for ( mg = field->
mg; mg; mg = mg->
next )
if ( (mg->
id.
length() > 6) || (mg->
id.
length() == 0) ) long_ids++;
216 cerr <<
"Error: Micrograph ids are too long to add together, revert to default file name." << endl;
221 for ( mg = field->
mg; mg; mg = mg->
next )
if ( mg != mg_ref ) {
227 cout <<
"Writing summed images to " << filename << endl;
233 for ( mg = field->
mg; mg; ) {
240 mg_ref->
block = ifield;
241 mg_ref->
fpart = filename;
291 if ( field->
id != fieldo->
id ) {
292 error_show(
"Error in mg_particle_unmerge", __FILE__, __LINE__);
293 cerr <<
"Field-of-view IDs do not match. Please check your data." << endl;
294 cerr <<
"ID of reference field: " << fieldo->
id << endl;
295 cerr <<
"ID of other field: " << field->
id << endl;
298 if (
verbose ) cout <<
"\nUnmerging field: " << fieldo->
id << endl;
299 for ( mgo=fieldo->
mg; mgo; mgo=mgo->
next ) {
301 for ( mg=field->
mg; mg; mg=mg->
next ) {
305 error_show(
"Error in mg_particle_unmerge", __FILE__, __LINE__);
306 cerr <<
"Error: The number of particles in micrographs " << mg->
id
307 <<
" (" << num <<
") and " << mgo->
id <<
" (" << numo
308 <<
") do not match." << endl;
309 cerr <<
"Please check your data" << endl;
313 for ( particle=mg->
part, particleo=mgo->
part; particle && particleo; particle=particle->
next, particleo=particleo->
next ) {
314 if ( particle->
id != particleo->
id ) {
315 error_show(
"Error in mg_particle_unmerge", __FILE__, __LINE__);
316 cerr <<
"Error: Particle IDs do not match. Please check your data" << endl;
320 if ( fom_diff > 0 ) {
321 if ( particle->
fom[0] - particleo->
fom[0] > fom_diff ) {
328 particle->
fom[0] = particleo->
fom[0];
329 particle->
sel = particleo->
sel;
330 particle->
view[3] += rotang_diff;
338 total = ccount + ucount;
340 cout <<
"\nUn-merge option:" << endl;
341 if ( fom_diff > 0 ) {
342 cout <<
"Total number of particles: " << total << endl;
343 cout <<
"Number of unchanged particles: " << ucount << endl;
344 cout <<
"FOM-difference threshold: " << fom_diff << endl << endl;
346 cout <<
"Particle orientations changed: " << ccount << endl << endl;
long field_count_micrographs(Bfield *field)
Counts all the micrographs in the field-of-view structure.
Bmicrograph * field_find_micrograph(Bfield *field, int mg_select, int mg_index, double mg_ang)
Returns a pointer to a specific micrograph in a field-of-view structure based on a unique characteris...
int mg_particle_unmerge(Bproject *project, Bproject *orientations, float fom_diff)
Gives corresponding particles in a field-of-view the same orientation, figure-of-merit (FOM),...
void set(long j, double v)
Sets a single value at the given index.
int micrograph_kill(Bmicrograph *mg)
Frees a whole micrograph parameter structure.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
long micrograph_count_particles(Bmicrograph *mg)
Counts all the particles in the micrograph structure.
Header file for micrograph processing.
int error_show(string message, string file, int line)
Displays the error with file and line reference.
double background(long nn)
Vector3< long > size() const
int transform(Vector3< double > scale, Vector3< double > origin, Vector3< double > translate, Matrix3 mat, int fill_type=0, double fill=0)
Transforms an image by translation, rotation, scaling and skewing, in place.
int find_shift(Bimage *pref, Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Calculates a cross-correlation map to find the shift for the pair of images.
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
void origin(double x, double y, double z)
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
string insert(string &filename, string ins)
General image parameter class.
int replace(Bimage *img)
Replaces the data with that from the given image.
Header file for functions to merge images.
Header file for general utilities.
int mg_particle_merge_series(Bproject *project, int mg_ref_select, int mg_index, float mg_rot_ang, int mg_ori_select, Bstring outimg)
Aligns and merges (sums) 2D particle images from a focal, or other, series and writes to new image fi...
void change_type(char letter)
Get the data type indicated by a single letter code.
void sampling(long nn, Vector3< double > u)
int img_unique_shift_global_rotate(Bimage *p, Vector3< float > *origin, Vector3< float > *shift, float angle)
Shifts and rotates each image as defined in individual shift vectors.