| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
mg_resolution.cpp
Go to the documentation of this file.
1
9 #include "mg_resolution.h"
10 #include "img_resolution.h"
11 #include "ps_plot.h"
12 #include "rwimg.h"
13 #include "linked_list.h"
14 #include "utilities.h"
15
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18
30 int mg_determine_resolution(Bproject* project, Bstring& ref_file,
31 Bstring& real_mask_file, Bstring& ft_mask_file,
32 double resolution, double sampling_ratio, float* cutoff)
33 {
34 // Get the number of reference maps and their file names
35 long i, j, k, m;
36 unsigned long nmap = count_list((char *)project->reference);
37 Bstring* map = project->reference;
38
39 // cout << "Reference map: " << *(project->reference) << endl;
40
41 if ( ref_file.length() ) {
42 string_kill(project->reference);
43 nmap = 1;
44 map = NULL;
45 project->reference = string_add(&map, ref_file);
46 }
47
48 if ( !map ) {
49 cerr << "Error: No reference map(s) specified!" << endl;
50 bexit(-1);
51 }
52
53 if ( verbose ) {
54 cout << "Determining particle resolution:" << endl;
55 cout << "Number\tMap" << endl;
56 for ( i=0, map = project->reference; i<nmap && map; i++, map = map->next )
57 cout << i+1 << tab << *map << endl;
58 cout << endl;
59 }
60
61 Bfield* field;
62 Bmicrograph* mg;
63 Bparticle* part;
64 long npart = project_count_mg_particles(project);
65
66 // Main loop over all reference maps
67 double maxfom;
68 Vector3<float> translate;
69 Matrix3 mat(1);
70 Bstring ps_file;
71 Bimage* p = NULL;
72 Bimage* pmap = NULL;
73 Bimage* prealmask = NULL;
74 Bimage* pftmask = NULL;
75 Bimage* proj = NULL;
76 Bplot* plot;
77 Bplot* plotsum = NULL;
78
79 int* num = new int[nmap+1];
80 double* fom = new double[npart*nmap];
81 for ( i=0; i<nmap+1; i++ ) num[i] = 0;
82 for ( i=0; i<npart*nmap; i++ ) fom[i] = 0;
83
84 if ( real_mask_file.length() ) {
85 prealmask = read_img(real_mask_file, 1, 0);
86 if ( !prealmask ) {
87 error_show("img_determine_resolution", __FILE__, __LINE__);
88 return -1;
89 }
90 }
91
92 if ( ft_mask_file.length() ) {
93 pftmask = read_img(ft_mask_file, 1, 0);
94 if ( !pftmask ) {
95 error_show("img_determine_resolution", __FILE__, __LINE__);
96 return -1;
97 }
98 }
99
100 if ( verbose & VERB_LABEL )
101 cout << "Map\tParticle\tID\tDPR" << endl;
102 for ( i=0, m=0, map=project->reference; i<nmap && map; i++, map=map->next ) {
103 pmap = read_img(*map, 1, 0);
104 if ( !pmap ) {
105 error_show("img_determine_resolution", __FILE__, __LINE__);
106 return -1;
107 }
108 pmap->change_type(Float);
109 if ( pmap->image->origin().x() <= 0 )
110 pmap->image->origin(pmap->size()/2);
111 for ( field=project->field; field; field=field->next ) {
112 for ( mg=field->mg; mg; mg=mg->next ) {
113 for ( part=mg->part; part; part=part->next ) {
114 p = read_img(mg->fpart, 1, part->id-1);
115 if ( !p ) {
116 error_show(mg->fpart.c_str(), __FILE__, __LINE__);
117 return -1;
118 }
119 if ( mg->pixel_size ) p->sampling(mg->pixel_size, mg->pixel_size, 1);
120 p->change_type(Float);
121 p->statistics();
122 p->rescale_to_avg_std(0, 1);
123 // Calculate the projected reference image
124 mat = part->view.matrix();
125 translate = part->ori - pmap->image->origin();
126 translate[2] = 0;
127 proj = pmap->rotate_project(mat, translate, pmap->sizeX()/2.0);
128 proj->change_type(Float);
129 proj->statistics();
130 proj->rescale_to_avg_std(0, 1);
131 plot = img_resolution(p, proj, prealmask, pftmask, resolution, 0, sampling_ratio);
132 fom[m*nmap+i] = plot->cut(2, cutoff[1]);
133 if ( verbose & VERB_LABEL )
134 cout << map << tab << mg->fpart << tab << part->id << tab << fom[m*nmap+i] << endl;
135 delete p;
136 delete proj;
137 if ( !plotsum ) plotsum = plot;
138 else {
139 plotsum->add(plot);
140 delete plot;
141 }
142 m++;
143 }
144 }
145 }
146 delete pmap;
147 }
148 if ( prealmask) delete prealmask;
149 if ( pftmask) delete pftmask;
150
151 if ( m ) plotsum->multiply(1.0/m);
152
153 // Get the best FOM and assign the particle to that map
154 if ( verbose & VERB_RESULT )
155 cout << "\nFilename\tID\tMap\tDPR\tFOM" << endl;
156 for ( m=0, field=project->field; field; field=field->next ) {
157 for ( mg=field->mg; mg; mg=mg->next ) {
158 for ( part=mg->part; part; part=part->next ) {
159 maxfom = -1e37;
160 part->sel = 0;
161 for ( i=0; i<nmap; i++ ) {
162 if ( maxfom < fom[m*nmap+i] ) { // FOM is resolution based on DPR
163 maxfom = fom[m*nmap+i];
164 if ( maxfom >= 0 ) part->sel = i+1;
165 }
166 }
167 num[part->sel]++;
168 part->fom[0] = 1/maxfom;
169 m++;
170 if ( verbose & VERB_RESULT )
171 cout << mg->fpart << tab << part->id << tab << part->sel
172 << tab << maxfom << tab << part->fom[0] << endl;
173 }
174 }
175 }
176
177 if ( verbose & VERB_RESULT ) {
178 cout << "Map\tNumber\tPercentage" << endl;
179 for ( i=0; i<=nmap; i++ )
180 cout << i << tab << num[i] << tab << num[i]*100.0/npart << endl;
181 cout << endl;
182 }
183
184 delete[] num;
185 delete[] fom;
186
187 if ( verbose ) {
188 cout << "k\ts\tFSC\tDPR" << endl;
189 for ( i=0, j=plotsum->rows(), k = j+plotsum->rows(); i<plotsum->rows(); i++, j++, k++ )
190 cout << i << tab << (*plotsum)[i] << tab << (*plotsum)[j] << tab << (*plotsum)[k] << endl;
191 }
192
193 delete plotsum;
194
195 return 0;
196 }
197
198
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1544
Bproject::reference
Bstring * reference
Definition: mg_processing.h:295
Bparticle::id
int id
Definition: mg_processing.h:55
string_add
Bstring * string_add(Bstring **list, const char *string)
Adds a string to a linked list.
Definition: Bstring.cpp:736
Bparticle::view
View view
Definition: mg_processing.h:63
utilities.h
Header file for general utilities.
verbose
int verbose
Matrix3
Definition: Matrix3.h:17
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
project_count_mg_particles
long project_count_mg_particles(Bproject *project)
Counts all the particles in the project structure.
Definition: mg_processing.cpp:713
Vector3< float >
error_show
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:687
Bimage::size
Vector3< size_t > size() const
Definition: Bimage.h:327
Bimage::statistics
size_t statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bfield::next
Bfield * next
Definition: mg_processing.h:217
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:200
Float
Definition: utilities.h:150
Bimage::rotate_project
Bimage * rotate_project(Matrix3 mat, Vector3< double > translate, double radial_cutoff)
Rotates a 3D map and projects it along the z-axis.
Definition: Bimage_project.cpp:103
Bimage
General image parameter class.
Definition: Bimage.h:152
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:169
Bfield
Definition: mg_processing.h:216
linked_list.h
Header file for generalized linked list functions.
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg=0, double nustd=1)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:100
Bmicrograph::pixel_size
float pixel_size
Definition: mg_processing.h:176
Bplot::cut
double cut(long icol, double threshold)
Definition: Bplot.h:245
read_img
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Bimage::sampling
void sampling(double s)
Definition: Bimage.h:440
Bproject::field
Bfield * field
Definition: mg_processing.h:300
img_resolution
Bplot * img_resolution(Bimage *p, Bimage *pmod, Bimage *prealmask, Bimage *pftmask, double hi_res, double aligned_res, double sampling_ratio)
Calculates resolution measures.
Definition: img_resolution.cpp:94
Bmicrograph
Definition: mg_processing.h:162
mg_determine_resolution
int mg_determine_resolution(Bproject *project, Bstring &ref_file, Bstring &real_mask_file, Bstring &ft_mask_file, double resolution, double sampling_ratio, float *cutoff)
Determines the resolution of particle images with respect to several reference maps.
Definition: mg_resolution.cpp:30
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:132
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:221
project
Bproject * project
Definition: tcltk_bshow.cpp:31
VERB_RESULT
#define VERB_RESULT
Definition: utilities.h:98
Bplot::add
void add(Bplot *p)
Definition: Bplot.h:239
Bparticle
Definition: mg_processing.h:52
Bparticle::fom
float fom[NFOM]
Definition: mg_processing.h:64
Bstring
Definition: Bstring.h:28
Bimage::sizeX
void sizeX(size_t nx)
Definition: Bimage.h:330
View::matrix
Matrix3 matrix()
Definition: View.h:138
Bplot::rows
void rows(long n)
Definition: Bplot.h:206
ps_plot.h
Header file for postscript output functions.
Bparticle::sel
int sel
Definition: mg_processing.h:65
mg_resolution.h
Library routines to estimate resolution.
rwimg.h
Header file for 2D and 3D image I/O.
img_resolution.h
Library routines to estimate resolution.
Bparticle::ori
Vector3< float > ori
Definition: mg_processing.h:62
Bstring::length
long length() const
Definition: Bstring.cpp:278
Bparticle::next
Bparticle * next
Definition: mg_processing.h:53
VERB_LABEL
#define VERB_LABEL
Definition: utilities.h:99
bexit
int bexit(int value)
Exit function for cleanup and debugging.
Definition: utilities.cpp:287
tab
ostream & tab(ostream &out)
Definition: utilities.cpp:21
Bproject
Definition: mg_processing.h:290
Bimage::image
Bsub_image * image
Definition: Bimage.h:183
Bplot::multiply
void multiply(double d)
Definition: Bplot.h:242
string_kill
int string_kill(Bstring *list)
Kills a string linked list.
Definition: Bstring.cpp:791
Bplot
Definition: Bplot.h:146
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:163