47 if ( map_size.
volume() <= 0 ) {
48 error_show(
"Error in project_back_projection", __FILE__, __LINE__);
49 cerr <<
"No reconstruction size set!" << endl << endl;
53 for ( field = project->
field; field && part == NULL; field = field->
next )
54 for ( mg = field->
mg; mg && part == NULL; mg = mg->
next )
55 if ( ( part = mg->
part ) )
break;
58 cerr <<
"Error: No particles found!" << endl;
64 map_size.
y(), map_size.
z(), 1);
79 cout <<
"3D backprojection:" << endl;
80 cout <<
"Map size: " << pmap->
size() << endl;
81 cout <<
"Resolution: " << resolution <<
" A" << endl;
82 cout <<
"Scale: " << scale << endl;
83 cout <<
"Sampling: " << pmap->
sampling() << endl;
84 cout <<
"Number of selected particles: " << nsel << endl << endl;
88 for ( field = project->
field; field; field = field->
next ) {
89 for ( mg = field->
mg; mg; mg = mg->
next ) {
90 for ( part = mg->
part; part; part = part->
next ) {
93 if ( num_select < 0 ) {
95 }
else if ( part->
sel == num_select ) {
101 error_show(
"project_back_projection", __FILE__, __LINE__);
107 if ( part->
ori.
x() <= 0 ) {
112 if ( part->
ori.
y() <= 0 ) {
131 cout <<
"Complete: " << nrec*100.0/nsel <<
"%\r" << flush;
138 cout << endl <<
"Particles used: " << nrec << endl << endl;
167 if ( !pmap->
FOM() ) {
168 cerr <<
"Map cannot be R-weighted!" << endl;
172 unsigned long i, j, x, y, z;
173 long ir, xr, yr, zr, xo, xo1, yo, xx, yy, yw;
174 double xf[2], yf[2], pi_z;
190 mat = mat.transpose();
194 float* fom = (
float *) pmap->
FOM();
198 cout <<
"Backprojecting" << endl << endl;
200 for ( i=z=0; z<pmap->
sizeZ(); z++ ) {
201 newcoor[2] = z - neworigin.
z();
203 if ( zr < 0 ) zr += pmap->
sizeZ();
204 for ( y=0; y<pmap->
sizeY(); y++ ) {
205 newcoor[1] = y - neworigin.
y();
207 if ( yr < 0 ) yr += pmap->
sizeY();
208 for ( x=0; x<pmap->
sizeX(); x++, i++ ) {
209 newcoor[0] = x - neworigin.
x();
211 if ( xr < 0 ) xr += pmap->
sizeX();
212 oldcoor = mat * newcoor + oldorigin;
213 yo = (long) oldcoor.
y();
215 if ( ( yo >= 0 ) && ( yo < p->sizeY() ) ) {
216 xo = (long) oldcoor.
x();
217 if ( ( xo >= 0 ) && ( xo < p->sizeX() ) ) {
218 yf[1] = oldcoor.
y() - yo;
220 xf[1] = oldcoor.
x() - xo;
222 for ( yy=0; yy<2; yy++, yo++ )
if ( yo < p->sizeY() ) {
224 for ( xx=0, xo1=xo; xx<2; xx++, xo1++ )
if ( xo1 < p->sizeX() ) {
226 v += (*p)[j]*xf[xx]*yf[yy];
232 ir = (zr*pmap->
sizeY() + yr)*pmap->
sizeX() + xr;
233 pi_z =
M_PI*fabs(oldcoor.
z());
235 fom[ir] += fabs(sin(pi_z)/pi_z);
258 if ( threshold < 1e-30 )
return 0;
262 unsigned long i, x, y, z, nzero = 0, nmax = 0;
264 double sx2, sy2, sz2, res2(0.25);
265 double inv_threshold = 1.0/threshold;
269 if ( resolution > 0 ) res2 = 1/(resolution*resolution);
271 float* fom = (
float *) p->
FOM();
274 cout <<
"Filtering to a resolution of " << 1/sqrt(res2) <<
" A" << endl;
275 cout <<
"R-weighting with a cutoff factor of " << threshold << endl << endl;
278 for ( i=z=0; z<p->
sizeZ(); z++ ) {
280 if ( z > (p->
sizeZ() - 1)/2 ) zz -= p->
sizeZ();
281 sz2 = zz/realsize.z();
283 for ( y=0; y<p->
sizeY(); y++ ) {
285 if ( y > (p->
sizeY() - 1)/2 ) yy -= p->
sizeY();
286 sy2 = yy/realsize.y();
288 for ( x=0; x<p->
sizeX(); x++, i++ ) {
290 if ( x > (p->
sizeX() - 1)/2 ) xx -= p->
sizeX();
291 sx2 = xx/realsize.x();
293 if ( sx2 + sy2 + sz2 > res2 ) {
296 }
else if ( fom[i] < threshold ) {
297 weight = inv_threshold;
308 cout <<
"Weighed fractions: zeroed=" << nzero*1.0/i <<
" maximum=" << nmax*1.0/i << endl << endl;
334 cout <<
"DEBUG img_backprojection_weigh: threshold=" << threshold << endl;
336 int maps_per_class = nthreads;
337 int iclass = imap/nmaps;
343 unsigned long i, j, k;
344 unsigned long datasize = (
unsigned long) prec->
size().volume();
347 unsigned long st(0), inc(1);
352 if ( nmaps == 3 && imap%3 ) {
358 cout <<
"DEBUG img_backprojection_weigh: nmaps=" << nmaps <<
" imap=" << imap << endl;
359 cout <<
"DEBUG img_backprojection_weigh: maps_per_class=" << maps_per_class <<
" iclass=" << iclass << endl;
360 cout <<
"DEBUG img_backprojection_weigh: st=" << st <<
" inc=" << inc << endl;
363 for ( i=iclass*maps_per_class+st, j=st; j<maps_per_class; i+=inc, j+=inc ) {
365 fom_acc = pacc[i]->
FOM();
366 for ( k=0; k<datasize; k++ ) {
367 prec->
add(k, pacc[i]->complex(k));
368 fom[k] += fom_acc[k];
373 cout <<
"DEBUG img_backprojection_weigh: Accumulation done" << endl;
377 unsigned long x, y, z, nzero = 0, nmax = 0;
379 double sx2, sy2, sz2, res2(1);
380 double inv_threshold = ( threshold )? 1.0/threshold: 1;
384 if ( resolution > 0 ) res2 = 1/(resolution*resolution);
387 cout <<
"Filtering to a resolution of " << 1/sqrt(res2) <<
" A" << endl;
388 cout <<
"R-weighting with a cutoff factor of " << threshold << endl << endl;
391 for ( i=z=0; z<prec->
sizeZ(); z++ ) {
393 if ( z > (prec->
sizeZ() - 1)/2 ) zz -= prec->
sizeZ();
394 sz2 = zz/realsize.z();
396 for ( y=0; y<prec->
sizeY(); y++ ) {
398 if ( y > (prec->
sizeY() - 1)/2 ) yy -= prec->
sizeY();
399 sy2 = yy/realsize.y();
401 for ( x=0; x<prec->
sizeX(); x++, i++ ) {
403 if ( x > (prec->
sizeX() - 1)/2 ) xx -= prec->
sizeX();
404 sx2 = xx/realsize.x();
406 if ( sx2 + sy2 + sz2 > res2 ) {
409 }
else if ( fom[i] <= threshold ) {
410 weight = inv_threshold;
421 cout <<
"Weighed fraction: " << (i-nzero-nmax)*1.0/i << endl;
422 cout <<
"Zeroed fraction: " << nzero*1.0/i << endl;
423 cout <<
"Fraction below threshold: " << nmax*1.0/i << endl << endl;
void change_type(char letter)
Get the data type indicated by a single letter code.
void view(double x, double y, double z, double a)
Header file for general utilities.
long project_count_mg_part_selected(Bproject *project)
Counts the number of particles in a project.
Class for complex numbers.
int error_show(const char *message, const char *file, int line)
Displays the error with file and line reference.
void check()
Checks an image for reasonable properties.
int img_weigh_transform(Bimage *p, double resolution, double threshold)
Weighs a transform with the FOM.
size_t statistics()
Calculates the statistics for an image.
3x3 Matrix manipulation functions
General image parameter class.
Vector3< double > real_size()
unsigned char * data_alloc()
Header file for 3D reconstruction by backprojection.
float * FOM_initialize()
Allocates and initializes the FOM block.
Bimage * read_img(const char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Complex< double > complex(size_t j)
Returns a complex value at the given index.
int img_back_project_one(Bimage *p, Bimage *pmap)
Back-projects a 2D image into a 3D volume.
General FFT for n-dimensional data.
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Bimage * img_backprojection_weigh(Bimage **pacc, int imap, int nmaps, int nthreads, double resolution, double threshold, fft_plan planf, fft_plan planb)
Accumulates multiple backprojections and weighs the transform with the FOM.
void origin(double x, double y, double z)
void add(size_t j, double v)
void set(size_t j, double v)
Sets a single value at the given index.
void view(double vx, double vy, double vz, double va)
void complex_to_real()
The real part of a complex image is written to a simple image.
unsigned char * data_pointer()
Bimage * project_back_projection(Bproject *project, int num_select, Vector3< int > map_size, Vector3< float > sampling, double scale, double resolution)
Back projects a set of 2D images into a 3D volume.
Header file for micrograph processing.
Header file for 2D and 3D image I/O.