32 double a1, a2, s1, s2, r, ds(1e30);
38 s2 = particle_diameter/2;
42 cout <<
"Calculating a template image:" << endl;
43 cout <<
"Sigma1\tRatio\tResidual" << endl;
46 while ( fabs(ds) > 1e-10 ) {
48 r = sqrt(exp(0.5*(r*r-1)));
51 cout << s1 <<
tab << r <<
tab << ds << endl;
59 cout <<
"Template variables:" << endl;
60 cout <<
"Gaussian amplitudes: " << a1 <<
" " << a2 << endl;
61 cout <<
"Gaussian sigmas: " << s1 <<
" " << s2 << endl << endl;
80 cout <<
"Calculating a template image:" << endl;
81 cout <<
"Particle diameter: " << particle_diameter << endl;
82 cout <<
"Gaussian edge: " << gauss_edge << endl << endl;
87 p->
sphere(center, (particle_diameter+gauss_edge)/2, gauss_edge,
FILL_USER, 1);
111 double hires,
double lores,
int bin)
134 cout <<
"Template origin: " << pt->
image->
origin() << endl;
135 cout <<
"Template avg & std: " << pt->
average() <<
171 unsigned long rad = (
unsigned long) excl_dist/2;
175 tile = tile.
min(rad);
178 start = start.
max(tile);
179 start = start.
min(pcc->
size()-1);
188 cout <<
"Finding peaks in the cross-correlation map:" << endl;
189 cout <<
"Exclusion distance: " << excl_dist << endl;
190 cout <<
"Threshold: " << threshold << endl;
191 cout <<
"Tile size: " << tile << endl;
192 cout <<
"Starting coordinates: " << start << endl;
193 cout <<
"Ending coordinates: " << end << endl;
196 unsigned long i, k, l, nc, ncp, x, y, z, xx, yy, zz, n;
197 unsigned long nt = ((pcc->
sizeX()-1)/tile.
x()+1)*((pcc->
sizeY()-1)/tile.
y()+1)*((pcc->
sizeZ()-1)/tile.
z()+1);
199 double sigma, pix_min(4), pix_max(10);
201 double* cc =
new double[nt];
204 cout <<
"Allocated number of coordinates: " << nt << endl;
206 for ( n=0, nc=0; n<pcc->
images(); n++ ) {
207 for ( z=start.
z(); z<end.
z(); z+=rad ) {
208 for ( y=start.
y(); y<end.
y(); y+=rad ) {
209 for ( x=start.
x(); x<end.
x(); x+=rad ) {
211 for ( zz=z; zz<z+tile.
z() && zz<end.
z(); zz++ ) {
212 for ( yy=y; yy<y+tile.
y() && yy<end.
y(); yy++ ) {
213 for ( xx=x; xx<x+tile.
x() && xx<end.
x(); xx++ ) {
214 i = pcc->
index(0,xx,yy,zz,n);
215 if ( (*pcc)[i] > threshold && cc[nc] < (*pcc)[i] ) {
224 if ( cc[nc] > threshold ) {
227 if ( sigma > pix_min && sigma < pix_max ) {
228 if ( max < cc[nc] ) max = cc[nc];
240 if (
verbose & VERB_PROCESS ) {
241 cout <<
"Number of peaks found: " << nc << endl;
242 cout <<
"Maximum CC: " << max << endl;
243 cout <<
"Threshold: " << threshold << endl;
246 for ( k=0, ncoor=0; k<nc; k++ ) if ( cc[k] > threshold ) {
247 for ( l=k+1; l<nc; l++ ) if ( cc[l] > threshold ) {
248 if ( (ct[k] - ct[l]).length() < excl_dist ) {
249 if ( cc[k] > cc[l] ) cc[l] = threshold - 1;
250 else cc[k] = threshold - 1;
253 if ( cc[k] > threshold ) ++ncoor;
258 for ( i=k=0; k<nc; k++ ) if ( cc[k] >= threshold )
265 cout <<
"Number of peaks found: " << ncoor << endl << endl;
274 if ( lores > 0 && hires > lores ) swap(hires, lores);
277 cout <<
"Local cross-correlation:" << endl;
278 cout <<
"Resolution limits: " << hires <<
" - ";
279 if ( lores > 0 ) cout << lores <<
" A" << endl;
280 else cout <<
"inf A" << endl << endl;
284 cout <<
"Calculating the cross-correlation map" << endl << endl;
294 cout <<
"Convolving the image with the mask" << endl << endl;
306 cout <<
"Convolving the squared image with the mask" << endl << endl;
321 for ( i=0; i<datasize; i++ ) {
322 v = (*pmc2)[i] - (*pmc)[i] * (*pmc)[i];
325 pcc->
set(i, (*pcc)[i]/v);
335 cout <<
"Calculating the local cross-correlation map:" << endl;
336 cout <<
"Sigma below zero: " << nn << endl << endl;
355 unsigned long x, y, z, n;
356 double v, sumin(0), sumout(0);
362 for ( n=0, mark = markin; mark; mark = mark->
next ) {
363 v = p->
get(0, mark->
loc + c, 0);
372 for ( n=0, mark = markout; mark; mark = mark->
next ) {
373 v = p->
get(0, mark->
loc + c, 0);
380 if ( n ) sumout /= n;
382 return sumin - sumout;
403 dispatch_apply(p->
data_size(), dispatch_get_global_queue(0, 0), ^(
size_t i){
407 #pragma omp parallel for
void change_type(char letter)
Get the data type indicated by a single letter code.
void square()
Calculates the square of an image.
Header file for image class.
Header file for general utilities.
int shift_wrap(Vector3< double > vec)
Shifts an image.
double get(size_t nn, size_t xx, size_t yy, size_t zz, size_t cc=0)
Returns the data value at the given coordinates.
Bimage * img_marker_set_difference(Bimage *p, Bmarker *markin, Bmarker *markout)
Calculates the average difference between voxels tagged by two marker sets.
size_t index(size_t nx, size_t ny) const
double average(size_t cc, double xf, double yf, double zf, size_t nn, double iscale)
Averages in the xy plane when scaling is less than 1.
Bimage * img_find_template(Bimage *p, Bimage *ptemp, Bimage *pmask, double hires, double lores, int bin)
Picks particles using cross-correlation with a template.
Vector3< size_t > size() const
size_t statistics()
Calculates the statistics for an image.
double kmeans_threshold(long n, double *v)
Finds a threshold that partitions an array into foreground and background clusters.
int gaussian_sphere(size_t nn, Vector3< double > center, double sigma, double amp)
Fills a gaussian sphere within an image with a uniform value.
General image parameter class.
unsigned char * data_alloc()
Bimage * pad_copy(size_t sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
int rescale_to_avg_std(double nuavg=0, double nustd=1)
Rescales the image data to a given average and standard deviation.
Bimage * img_local_cc(Bimage *p, Bimage *pt, Bimage *pm, double hires, double lores, fft_plan planf, fft_plan planb)
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.
void coordinates(size_t i, size_t &nx, size_t &ny, size_t &nz)
Bimage * cross_correlate(Bimage *p, Bimage *pmask=NULL)
void origin(double x, double y, double z)
void set(size_t j, double v)
Sets a single value at the given index.
double standard_deviation()
int write_img(const char *filename, Bimage *p)
General driver function to write multiple image formats This is the only image writing function that ...
double peak_sigma(size_t nn, Vector3< int > coor, int kernel_size)
Calculates a sigma value for a cross-correlation peak.
Bimage * copy()
Copies the header information and data of an image into a new image structure.
fft_plan fft_setup(fft_direction dir, int opt=0)
Sets up a plan for fast Fourier transforms.
int fft_destroy_plan(fft_plan plan)
Deallocates a plan for fast Fourier transforms.
int pad(size_t sz, int fill_type=0, double fill=0)
Pads an image to a new size with a given fill value.
Bimage * bin_copy(Vector3< int > bin)
Bins by an integer size and returns a new image.
Vector3< double > * img_find_peaks(Bimage *pcc, double excl_dist, long &ncoor)
Finds the peaks in a cross-correlation map corresponding to particles.
Header file for functions to pick particles in images.
Bimage * img_prepare_template(Vector3< int > size, double particle_diameter)
Prepares a template for particle picking.
double img_marker_set_difference_at_voxel(Bimage *p, long i, Bmarker *markin, Bmarker *markout)
ostream & tab(ostream &out)
void origin(double ox, double oy, double oz)
Header file for general utilities.