35 double outrad = sqrt(2.0)*radius;
43 cout <<
"DEBUG img_gold_particle: rad=" << radius << endl;
73 if ( radius < 1 )
return NULL;
77 if ( img_select > -1 ) {
78 if ( img_select >= p->
images() ) img_select = p->
images() - 1;
79 img_start = img_select;
80 img_end = img_start + 1;
85 size_t i, j, x, y, z, n, nn, np(0);
87 double max, fom_avg(0), fom_std(0), fom_max(0);
92 cout <<
"Finding particles:" << endl;
93 cout <<
"Particle radius: " << radius*p->
sampling().x()
94 <<
" A " << radius <<
" pixels" << endl;
95 cout <<
"Edge: " << edge <<
" pixels" << endl;
99 cout <<
"DEBUG img_find_gold_particles: radius=" << radius << endl;
105 size_t fomsize(imgsize);
106 if ( img_select < 0 ) fomsize *= p->
images();
108 float* fom =
new float[fomsize];
109 for ( i=0; i<fomsize; i++ ) fom[i] = 0;
113 for ( i=0, n=img_start; n<img_end; n++ ) {
118 fom_one = pcc->
FOM();
119 for ( j=0; j<imgsize; j++, i++ )
if ( fom_one[j] ) {
122 fom_std += fom[i]*fom[i];
123 if ( fom_max < fom[i] ) fom_max = fom[i];
128 cout <<
"Image " << n <<
": " << np <<
" gold fiducials" << endl;
132 fom_std = fom_std/np - fom_avg*fom_avg;
133 if ( fom_std > 0 ) fom_std = sqrt(fom_std);
135 if ( cutoff == 0 ) cutoff = fom_avg + fom_std;
136 else if ( cutoff < 0 ) cutoff = fom_max/2;
138 cout <<
"Cutoff = " << cutoff << endl;
145 cout <<
"Marker\tx\ty\tz\tn\tFOM" << endl;
146 for ( j=nn=0, n=img_start; n<img_end; n++, nn++ ) {
147 for ( z=0; z<p->
sizeZ(); z++ ) {
149 if ( zz < 0 ) zz += p->
sizeZ();
150 if ( zz >= ve.
z() && zz < p->
sizeZ()-ve.
z() )
151 for ( y=0; y<p->
sizeY(); y++ ) {
153 if ( yy < 0 ) yy += p->
sizeY();
154 if ( yy >= ve.
y() && yy < p->
sizeY()-ve.
y() )
155 for ( x=0; x<p->
sizeX(); x++ ) {
157 if ( xx < 0 ) xx += p->
sizeX();
158 if ( xx >= ve.
x() && xx < p->
sizeX()-ve.
x() ) {
159 i = p->
index(x, y, z, nn);
160 if ( fom[i] > cutoff ) {
162 if ( !mark ) mark = m;
191 cout <<
"Number of particles found: " << j << endl << endl;
212 double outrad = sqrt(2.0)*radius;
221 for ( m = mark; m; m = m->
next )
if ( m->
sel )
222 p->
place(0, pmark, (m->
loc - offset), outrad, 1, 0, 1);
224 for ( m = mark; m; m = m->
next )
if ( m->
sel ) {
225 loc = m->
loc - offset;
255 unsigned long i, j, x, y, z, n, xx, yy;
258 double dx, dy, a, v, oldx, oldy, fx, fy;
259 double cos_axis =
bcos(axis);
260 double sin_axis =
bsin(axis);
261 double cos_tilt =
bcos(tilt);
262 float* sdata =
new float[datasize];
265 cout <<
"Stretching image by " << cos_tilt << endl;
267 for ( i=n=0; n<p->
images(); n++ ) {
268 for ( z=0; z<p->
sizeZ(); z++ ) {
269 for ( y=0; y<p->
sizeY(); y++ ) {
271 for ( x=0; x<p->
sizeX(); x++, i++ ) {
273 a = atan2(dy, dx) - axis;
274 v = sqrt(dx*dx + dy*dy);
280 if ( ix >= 0 && ix < p->sizeX()-1 && iy >= 0 && iy < p->
sizeY()-1 ) {
283 for ( yy=iy; yy<iy+2; yy++ ) {
285 for ( xx=ix; xx<ix+2; xx++ ) {
288 j = p->
index(0,xx,yy,z,n);
289 sdata[i] += fx*fy* (*p)[j];
316 if ( p->
sizeZ() > 1 )
return -1;
317 if ( p->
images() > 1 )
return -1;
319 unsigned long i, x, y, c;
324 cout <<
"Clearing extraneous areas from micrograph " << p->
file_name() << endl;
327 double a,
b, d = 1e30;
328 if ( v.
x() && d > fabs(p->
sizeX()*0.5/v.
x()) ) d = fabs(p->
sizeX()*0.5/v.
x());
329 if ( v.
y() && d > fabs(p->
sizeY()*0.5/v.
y()) ) d = fabs(p->
sizeY()*0.5/v.
y());
331 a = d*
bcos(tilt_angle) + fabs(0.5*thickness*sin(tilt_angle));
333 for ( i=y=0; y<p->
sizeY(); y++ ) {
334 for ( x=0; x<p->
sizeX(); x++ ) {
336 for ( c=0; c<p->
channels(); c++, i++ )
void change_type(char letter)
Get the data type indicated by a single letter code.
Header file for image class.
double bcos(double x)
Avoid non-zero values for cos(PI/2) and cos(-PI/2).
int place(size_t nn, Bimage *p, Vector3< double > loc, double radius, double scale, double shift, int operation)
Places a small image into a large image.
int calculate_background(size_t nn)
Calculates the background for one sub-image.
Header file for general utilities.
char * add_item(char **list, unsigned long size)
Adds an item to a linked list.
Vector class for 3-value vectors used in 3D space. The internal variables are an array of 3 numbers...
size_t find_peaks(size_t kernelsize)
Finds peaks in a map with periodic boundaries.
Generalized matrix class.
size_t index(size_t nx, size_t ny) const
Vector3< size_t > size() const
size_t statistics()
Calculates the statistics for an image.
double bsin(double x)
Avoid non-zero values for sin(PI) and sin(-PI).
General image parameter class.
Header file for generalized linked list functions.
int img_stretch(Bimage *p, double axis, double tilt)
Stretches an image to what it should correspond to at 0 degree tilt.
int sphere(Vector3< double > center, double radius, double width=0, int fill_type=0, double fill=0)
Fills a sphere within an image with a uniform value.
unsigned char * data_assign(unsigned char *nudata)
Assign image data.
void file_name(Bstring s)
Bimage * cross_correlate(Bimage *p, Bimage *pmask=NULL)
Header file for trigonometry functions.
Bimage * img_marker_projection(Vector3< size_t > size, Vector3< double > offset, double radius, Bimage *pmark, Bmarker *mark)
Generates a projection image of the global marker model.
void origin(double x, double y, double z)
void set(size_t j, double v)
Sets a single value at the given index.
Bimage * extract(size_t nn)
Extracts one sub-image into new image structure.
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
Bmarker * img_find_gold_particles(Bimage *p, int img_select, double radius, size_t edge, double cutoff)
Finds gold particles in micrograph images.
int img_clear_extraneous_areas(Bimage *p, double tilt_axis, double tilt_angle, size_t thickness)
Clears areas from a micrograph not used in a reconstruction.
Bimage * img_gold_particle(Vector3< size_t > size, double radius)
Generates an image representing a gold particle.
Header file for tomographic applications.
Header file for image parameter functions.
ostream & tab(ostream &out)
void origin(double ox, double oy, double oz)
Header file for general utilities.