| Bsoft 2.0.5 Bernard's software package

mg_extract.cpp
Go to the documentation of this file.
1
9 #include "mg_extract.h"
10 #include "linked_list.h"
11 #include "spline.h"
12 #include "utilities.h"
13
14 #include <sys/stat.h>
15
16 // Declaration of global variables
17 extern int verbose; // Level of output to the screen
18
19 int mask_filament_particles(Bstring& filename, Bparticle* partlist, int mask_width);
20 int rotate_mask_filament_particles(Bstring& filename, Bparticle* partlist,
21 int rotation_axis, int back_flag, int mask_width);
22
35 int particle_setup_filenames(Bparticle* part, Bstring filename, Bstring partpath)
36 {
37 long n(0);
38 char format[32] = "%03d";
39 Bstring path;
40
41 if ( verbose & VERB_DEBUG )
42 cout << "DEBUG particle_setup_filenames: base=" << filename << endl;
43
44 if ( partpath.length() ) {
45 if ( !partpath.empty() )
46 if ( partpath[-1] == '/' ) partpath = partpath.truncate(1);
47 n = partpath.count('?');
48 if ( n > 0 ) {
49 partpath = partpath.remove('?');
50 snprintf(format, 32, "%%0%ldd", n);
51 }
52 if ( verbose & VERB_DEBUG )
53 cout << "DEBUG particle_setup_filenames: path=" << partpath << endl;
54 }
55
56 if ( partpath.length() > 1 ) if ( filename.contains("/") ) filename = filename.post_rev('/');
57 for ( ; part; part = part->next ) {
58 if ( partpath.length() > 1 ) {
59 if ( n < 1 ) path = partpath;
60 else path = partpath + Bstring(part->id, format);
61 part->fpart = path + "/" + filename;
62 } else part->fpart = filename;
63 mkdir(path.c_str(), (mode_t)0755);
64 part->fpart = part->fpart.pre_rev('.') +
65 Bstring(part->id, format) + "." + part->fpart.post_rev('.');
66 if ( verbose & VERB_DEBUG )
67 cout << "DEBUG particle_setup_filenames: id=" << part->id << " path=" << part->fpart << endl;
68 }
69
70 return 0;
71 }
72
85 int filament_setup_filenames(Bfilament* fil, Bstring filename, Bstring filpath)
86 {
87 long n(0);
88 char format[32] = "%03d";
89 Bstring path;
90
91 if ( filpath.length() ) {
92 if ( !filpath.empty() )
93 if ( filpath[-1] == '/' ) filpath = filpath.truncate(1);
94 n = filpath.count('?');
95 if ( n > 0 ) {
96 filpath = filpath.remove('?');
97 snprintf(format, 32, "%%0%ldd", n);
98 }
99 if ( verbose & VERB_DEBUG )
100 cout << "DEBUG filament_setup_filenames: path=" << filpath << endl;
101 }
102
103 if ( filpath.length() > 1 ) if ( filename.contains("/") ) filename = filename.post_rev('/');
104 for ( ; fil; fil = fil->next ) {
105 if ( filpath.length() > 1 ) {
106 if ( n < 1 ) path = filpath;
107 else path = filpath + Bstring(fil->id, format);
108 fil->ffil = path + "/" + filename;
109 } else fil->ffil = filename;
110 mkdir(path.c_str(), (mode_t)0755);
111 fil->ffil = fil->ffil.pre_rev('.') +
112 Bstring(fil->id, format) + "." + fil->ffil.post_rev('.');
113 }
114
115 return 0;
116 }
117
127 Vector3<double>* vector3_spline_from_nodes(Bfilnode* fnode, long& nspline)
128 {
129 int n;
130 Bfilnode* fn;
131
132 for ( n=0, fn = fnode; fn; fn=fn->next ) n++;
133
134 Vector3<double>* coords = new Vector3<double>[n];
135
136 for ( n=0, fn = fnode; fn; fn=fn->next, n++ ) coords[n] = fn->loc;
137
138 Vector3<double>* spline = vector3_catmull_rom_spline(n, coords, nspline);
139
140 delete[] coords;
141
142 return spline;
143 }
144
160 long project_extract_particles(Bproject* project, double scale,
161 int back_flag, int norm_flag, int fill_type, double fill, int mask_width,
162 int split, Bstring& partbase, Bstring& partpath, Bstring& partext)
163 {
164 long i(1), npart(0);
165 Bstring filename;
166 Bfield* field = project->field;
167 Bmicrograph* mg;
168 Breconstruction* rec = project->rec;
169 Bimage* p = NULL;
170
171 if ( !partpath.empty() ) if ( partpath[-1] != '/' ) partpath += "/";
172
173 if ( partext.length() < 1 ) partext = "pif";
174
175 long nmg = project_count_micrographs(project);
176 long nrec = project_count_reconstructions(project);
177
178 long multi_img(0);
179
180 Vector3<long> size;
181 if ( project->select && rec ) size = rec->box_size;
182 else if ( field && field->mg ) size = field->mg->box_size;
183 if ( size.volume() < 1 ) {
184 cerr << "Error in project_extract_particles: Box size = " << size << endl;
185 return -1;
186 }
187
188 if ( verbose ) {
189 cout << "Extracting particles:" << endl;
190 cout << "Particle size: " << size << endl;
191 cout << "Particle scale: " << scale << endl;
192 if ( mask_width )
193 cout << "Filament mask width: " << mask_width << endl;
194 if ( back_flag ) cout << "With background correction" << endl;
195 if ( norm_flag ) cout << "With normalization" << endl;
196 if ( partbase.length() )
197 cout << "Particle base name: " << partbase << endl;
198 if ( partext.length() )
199 cout << "Particle extension: " << partext << endl;
200 if ( partpath.length() )
201 cout << "Particle path: " << partpath << endl;
202 cout << endl;
203 }
204
205 if ( project->select < 1 ) {
206 for ( field = project->field; field; field = field->next ) {
207 for ( mg=field->mg; mg; mg=mg->next, i++ ) {
208 if ( mg->next ) {
209 if ( mg->fmg == mg->next->fmg ) multi_img = 1;
210 else multi_img = 0;
211 }
212 // cout << mg->fmg << endl;
213 npart = particle_count(mg->part);
214 if ( npart > 0 ) {
215 if ( partbase.length() ) {
216 if ( nmg == 1 )
217 filename = partbase;
218 else
219 filename = partbase + Bstring(i, "_%03d");
220 } else {
221 if ( mg->fpart.length() < 1 ) mg->fpart = mg->fmg;
222 if ( mg->fmg.length() < 1 ) mg->fpart = mg->ffil;
223 filename = mg->fpart.pre_rev('.');
224 if ( mg->fmg == mg->fpart ) {
225 if ( multi_img ) filename = filename + Bstring(mg->img_num+1, "_part%03d");
226 else filename = filename + "_part";
227 }
228 if ( mg->ffil == mg->fpart ) {
229 filename = filename + "_fil";
230 }
231 }
232 if ( filename.length() < 1 )
233 cerr << "Error in project_extract_particles: No particle file name!" << endl;
234 filename = filename + "." + partext;
235 if ( partpath.length() > 1 ) {
236 if ( filename.contains("/") ) filename = filename.post_rev('/');
237 filename = partpath + filename;
238 }
239 if ( split ) {
240 particle_setup_filenames(mg->part, filename, partpath);
241 mg->fpart = 0;
242 } else {
243 mg->fpart = filename;
244 if ( partpath.length() > 1 ) mkdir(partpath.c_str(), (mode_t)0755);
245 // cout << mg->fmg << " ---> " << mg->fpart << endl;
246 }
247 if ( mg->fmg.length() ) p = read_img(mg->fmg, 1, mg->img_num);
248 else if ( mg->ffil.length() ) p = read_img(mg->ffil, 1, 0);
249 if ( !p ) {
250 error_show(mg->fmg.c_str() , __FILE__, __LINE__);
251 return -1;
252 }
253 if ( fill_type == FILL_AVERAGE ) fill = p->average();
254 if ( fill_type == FILL_BACKGROUND ) {
255 if ( fabs(p->background(long(0))) < 1e-6 )
256 p->calculate_background();
257 fill = p->background(long(0));
258 }
259 micrograph_extract_particles(mg, p, scale, back_flag, norm_flag, fill, mask_width);
260 delete p;
261 }
262 }
263 }
264 } else {
265 for ( rec=project->rec; rec; rec=rec->next, i++ ) {
266 npart = particle_count(rec->part);
267 if ( npart > 0 ) {
268 if ( partbase.length() ) {
269 if ( nrec == 1 )
270 filename = partbase;
271 else
272 filename = partbase + Bstring(i, "_%03d");
273 } else {
274 if ( rec->fpart.length() < 1 ) rec->fpart = rec->frec;
275 if ( rec->frec.length() < 1 ) rec->fpart = rec->ffil;
276 filename = rec->fpart.pre_rev('.');
277 if ( rec->frec == rec->fpart ) {
278 // if ( rec->img_num ) filename = filename + Bstring(rec->img_num, "_part%03d");
279 // else filename = filename + "_part";
280 filename = filename + "_part";
281 }
282 if ( rec->ffil == rec->fpart ) {
283 filename = filename + "_fil";
284 }
285 }
286 if ( filename.length() < 1 )
287 cerr << "Error in project_extract_particles: No particle file name!" << endl;
288 filename = filename + "." + partext;
289 if ( partpath.length() > 1 ) {
290 if ( filename.contains("/") ) filename = filename.post_rev('/');
291 filename = partpath + filename;
292 }
293 if ( split ) {
294 particle_setup_filenames(rec->part, filename, partpath);
295 rec->fpart = 0;
296 } else {
297 rec->fpart = filename;
298 if ( partpath.length() > 1 ) mkdir(partpath.c_str(), (mode_t)0755);
299 }
300 if ( rec->frec.length() ) p = read_img(rec->frec, 1, 0);
301 else if ( rec->ffil.length() ) p = read_img(rec->ffil, 1, 0);
302 if ( !p ) {
303 error_show(rec->frec.c_str() , __FILE__, __LINE__);
304 return -1;
305 }
306 if ( fill_type == FILL_AVERAGE ) fill = p->average();
307 if ( fill_type == FILL_BACKGROUND ) {
308 if ( fabs(p->background(long(0))) < 1e-6 )
309 p->calculate_background();
310 fill = p->background(long(0));
311 }
312 reconstruction_extract_particles(rec, p, scale, back_flag, norm_flag, fill, mask_width);
313 delete p;
314 }
315 }
316 }
317
318 return npart;
319 }
320
332 long micrograph_extract_particles(Bmicrograph* mg, Bimage* p, double scale,
333 int back_flag, int norm_flag, double fill, int mask_width)
334 {
335 long npart = particle_count(mg->part);
336
337 if ( npart < 1 ) return 0;
338
339 if ( mg->pixel_size > 0 ) p->sampling(mg->pixel_size, mg->pixel_size, 1);
340
341 Bimage* ppart = particle_extract(mg->part, mg->bad, p, mg->box_size,
342 scale, mg->bad_radius, back_flag, norm_flag, fill, mask_width);
343
344 if ( ppart ) {
345 write_img(mg->fpart, ppart, 0);
346 delete ppart;
347 }
348
349 return npart;
350 }
351
363 long reconstruction_extract_particles(Breconstruction* rec, Bimage* p, double scale,
364 int back_flag, int norm_flag, double fill, int mask_width)
365 {
366 long npart = particle_count(rec->part);
367
368 if ( npart < 1 ) return 0;
369
370 if ( rec->voxel_size > 0 ) p->sampling(rec->voxel_size, rec->voxel_size, rec->voxel_size);
371
372 Bimage* ppart = particle_extract(rec->part, rec->bad, p, rec->box_size,
373 scale, rec->bad_radius, back_flag, norm_flag, fill, mask_width);
374
375 if ( ppart ) {
376 write_img(rec->fpart, ppart, 0);
377 delete ppart;
378 }
379
380 return npart;
381 }
382
403 Bimage* particle_extract(Bparticle* particles, Bbadarea* bad_areas, Bimage* p,
404 Vector3<long> size, double scale, double bad_radius,
405 int back_flag, int norm_flag, double fill, int mask_width)
406 {
407 int split(0);
408 if ( particles->fpart.length() ) split = 1; // Flag to write separate particle images
409
410 if ( scale < 0.1 ) scale = 1;
411
412 // if ( mask_width < 1 ) mask_width = (p->sizeX() > p->sizeY())? p->sizeX(): p->sizeY();
413
414 long id, i, j, k, c, n, x, y, z;
415 long oldx, oldy, oldz, oldn(0);
416 double d(0), dh(0), halfwidth(mask_width/2.0), ori_tol;
417 double iscale(1/scale);
418 Bparticle* part = particles;
419 Bbadarea* bad;
420 Bimage* pmask = NULL;
421 Bimage* ppart = NULL;
422 Bimage* partmask = NULL;
423 Vector3<long> box, radius;
424 Vector3<double> u, v;
425 Euler euler;
426
427 long npart = particle_count(particles);
428
429 if ( npart < 1 ) return NULL;
430
431 double pixel_size(0);
432
433 if ( part->mg ) pixel_size = part->mg->pixel_size*iscale;
434 else if ( part->rec ) pixel_size = part->rec->voxel_size*iscale;
435 if ( pixel_size < 0.01 ) {
436 cerr << "Error: Pixel size is too small! " << pixel_size << endl;
437 return NULL;
438 }
439
440 box = size; // Box size
441 box = box.min(p->size()*scale);
442 box = box.max(1);
443 radius = box/2;
444 ori_tol = radius.length()/4;
445 if ( ori_tol > 2 ) ori_tol = 2;
446
447 if ( box.volume() < 1 ) {
448 cerr << "Error: Particle box size is zero!" << endl;
449 return NULL;
450 }
451
452 if ( verbose )
453 cout << "Extracting " << npart << " particles from " << p->file_name() << endl;
454
455 if ( verbose & VERB_PROCESS ) {
456 cout << "Number of particles: " << npart << endl;
457 cout << "Particle box size: " << box << endl;
458 cout << "Particle scale: " << scale << endl;
459 cout << "Particle radii: " << radius << endl;
460 cout << "Bad region radius: " << bad_radius << endl;
461 cout << "Mask width: " << mask_width << endl;
462 cout << "Fill value: " << fill << endl;
463 if ( back_flag ) cout << "Background corrected" << endl;
464 if ( norm_flag ) cout << "Normalized" << endl;
465 cout << endl;
466 }
467
468 if ( bad_areas && bad_radius > 1 ) {
469 pmask = new Bimage(UCharacter, p->compound_type(), p->size(), p->images());
470 for ( bad = bad_areas; bad; bad = bad->next )
471 pmask->sphere(bad->loc, bad_radius, 0, FILL_USER, 1);
472 }
473
474 if ( split ) {
475 partmask = new Bimage(UCharacter, TSimple, box, 1);
476 } else {
477 ppart = new Bimage(p->data_type(), p->compound_type(), box, npart);
478 ppart->fill(fill);
479 partmask = new Bimage(UCharacter, TSimple, box, npart);
480 }
481
482 for ( id=1, i=n=0, part = particles; part; part = part->next, n++, id++ ) {
483 if ( split ) {
484 i = n = 0;
485 ppart = new Bimage(p->data_type(), p->compound_type(), box, 1);
486 ppart->fill(fill);
487 }
488 // cout << "extracting " << id << endl;
489 part->id = id;
490 if ( part->ori.distance(radius) > ori_tol ) part->ori = radius;
491 part->pixel_size = pixel_size;
492 if ( box[2] == 1 ) ppart->sampling(pixel_size, pixel_size, 1);
493 else ppart->sampling(pixel_size, pixel_size, pixel_size);
494 ppart->origin(n, part->ori);
495 ppart->image[n].view(part->view);
496 euler = Euler(part->view);
497 u[0] = cos(euler.psi());
498 u[1] = -sin(euler.psi());
499 for ( z=0; z<ppart->sizeZ(); z++ ) {
500 oldz = (z - radius[2])*iscale + (long) part->loc[2];
501 v[2] = z - ppart->image[n].origin()[2];
502 for ( y=0; y<ppart->sizeY(); y++ ) {
503 oldy = (y - radius[1])*iscale + (long) part->loc[1];
504 v[1] = y - ppart->image[n].origin()[1];
505 for ( x=0; x<ppart->sizeX(); x++, i++ ) {
506 oldx = (x - radius[0])*iscale + (long) part->loc[0];
507 v[0] = x - ppart->image[n].origin()[0];
508 if ( oldx >= 0 && oldx < p->sizeX() && oldy >= 0 && oldy < p->sizeY() && oldz >= 0 && oldz < p->sizeZ()) {
509 j = (((oldn*p->sizeZ() + oldz)*p->sizeY() + oldy)*p->sizeX() + oldx)*p->channels();
510 if ( halfwidth > 0 ) dh = (u.cross(v)).length() - halfwidth;
511 if ( back_flag ) d = (v/ppart->size()).length() - 0.5;
512 // cout << "d=" << d << endl;
513 if ( ( pmask && (*pmask)[j] > 0 ) || ( d > 0 ) || ( dh > 0 ) ) {
514 partmask->set(i, 0);
515 if ( back_flag ) for ( c=0, k=i*p->channels(); c<p->channels(); c++ )
516 // ppart->set(k++, (*p)[j++]);
517 ppart->set(k++, p->average(c, oldx, oldy, oldz, oldn, iscale));
518 } else {
519 partmask->set(i, 1);
520 for ( c=0, k=i*p->channels(); c<p->channels(); c++ )
521 // ppart->set(k++, (*p)[j++]);
522 ppart->set(k++, p->average(c, oldx, oldy, oldz, oldn, iscale));
523 }
524 }
525 }
526 }
527 }
528 if ( split ) {
529 if ( back_flag ) ppart->correct_background(partmask, 1); // The mask is 1 for the background
530 else ppart->calculate_background();
531 ppart->statistics();
532 if ( ppart->standard_deviation() > 0 ) {
533 if ( norm_flag )
534 ppart->normalize(ppart->average(), ppart->standard_deviation(), 0);
535 } else {
536 part->sel = 0;
537 }
538 write_img(part->fpart, ppart, 0);
539 delete ppart;
540 ppart = NULL;
541 }
542 }
543
544 delete pmask;
545
546 // cout << "pixel size = " << ppart->sampling() << endl;
547
548 // write_img("part.mrc", ppart);
549 // write_img("mask.mrc", partmask);
550
551 if ( !split ) {
552 if ( back_flag ) ppart->correct_background(partmask, 1);
553 else ppart->calculate_background();
554 ppart->statistics();
555 if ( norm_flag ) ppart->normalize(ppart->average(), ppart->standard_deviation(), 0);
556 for ( n=0, part = particles; part; part = part->next, n++ ) {
557 if ( ppart->image[n].standard_deviation() <= 0 ) part->sel = 0;
558 }
559 }
560
561 delete partmask;
562
563 return ppart;
564 }
565
573 Bimage* micrograph_extract_gold(Bmicrograph* mg, Bimage* p, double radius)
574 {
575 if ( radius < 1 ) radius = mg->mark_radius;
576
577 Bimage* pmark = marker_extract_gold(mg->mark, p, mg->img_num, radius);
578
579 if ( mg->pixel_size > 0 ) pmark->sampling(mg->pixel_size, mg->pixel_size, 1);
580
581 return pmark;
582 }
583
591 Bimage* reconstruction_extract_gold(Breconstruction* rec, Bimage* p, double radius)
592 {
593 if ( radius < 1 ) radius = rec->mark_radius;
594
595 Bimage* pmark = marker_extract_gold(rec->mark, p, 0, radius);
596
597 if ( rec->voxel_size > 0 ) pmark->sampling(rec->voxel_size, rec->voxel_size, 1);
598
599 return pmark;
600 }
601
610 Bimage* marker_extract_gold(Bmarker* marker_list, Bimage* p, int img_num, double radius)
611 {
612 long i, j, c, n, x, y, z;
613 long oldx, oldy, oldz;
614 Bmarker* mark;
615 long nmark;
616 Vector3<long> box, iradius;
617
618 for ( nmark=0, mark=marker_list; mark; mark=mark->next ) nmark++;
619
620 if ( nmark < 1 ) return NULL;
621
622 iradius[0] = iradius[1] = iradius[2] = (int)(2*radius); // Half box size
623 box[0] = box[1] = box[2] = (int)(4*radius); // Box size
624 if ( p->sizeZ() < 2 ) {
625 iradius[2] = 0;
626 box[2] = 1;
627 }
628
629 if ( verbose & VERB_PROCESS )
630 cout << "Extracting " << nmark << " markers from image " << p->file_name()
631 << " (" << img_num << ") with box size " << box << endl;
632
633 Bimage* pmark = new Bimage(p->data_type(), p->compound_type(), box[0], box[1], box[2], nmark);
634 pmark->sampling(p->sampling());
635
636 for ( n=0, mark=marker_list; mark && n<pmark->images(); mark=mark->next, n++ ) {
637 pmark->origin(n, iradius); // Set the origin to the nominal center
638 for ( z=0; z<pmark->sizeZ(); z++ ) {
639 oldz = z - iradius[2] + (int) mark->loc[2];
640 for ( y=0; y<pmark->sizeY(); y++ ) {
641 oldy = y - iradius[1] + (int) mark->loc[1];
642 for ( x=0; x<pmark->sizeX(); x++ ) {
643 oldx = x - iradius[0] + (int) mark->loc[0];
644 if ( oldx >= 0 && oldx < p->sizeX() && oldy >= 0 && oldy < p->sizeY() && oldz >= 0 && oldz < p->sizeZ()) {
645 j = (((img_num*p->sizeZ() + oldz)*p->sizeY() + oldy)*p->sizeX() + oldx)*p->channels();
646 i = (((n*pmark->sizeZ() + z)*pmark->sizeY() + y)*pmark->sizeX() + x)*pmark->channels();
647 for ( c=0; c<p->channels(); c++, i++, j++ ) pmark->set(i, (*p)[j]);
648 }
649 }
650 }
651 }
652 }
653
654 pmark->statistics();
655
656 pmark->correct_background();
657
658 pmark->normalize(pmark->average(), pmark->standard_deviation(), 0);
659
660 return pmark;
661 }
662
674 long project_extract_filaments(Bproject* project, int filament_width, int axis,
675 Bstring& base, Bstring& path, Bstring& ext, int split)
676 {
677 long i(1), nfil(0);
678 Bstring filename;
679 Bfield* field;
680 Bmicrograph* mg;
681 Breconstruction* rec;
682 Bimage* p;
683
684 if ( path.length() && access(path.c_str(), F_OK) ) {
685 cerr << "Error: The directory " << path << " must exist to extract filaments!" << endl;
686 return -1;
687 }
688
689 if ( !path.empty() ) if ( path[-1] != '/' ) path += "/";
690
691 if ( ext.length() < 1 ) ext = "pif";
692
693 long nmg = project_count_micrographs(project);
694 long nrec = project_count_reconstructions(project);
695
696 if ( project->select < 1 ) {
697 if ( verbose )
698 cout << "Extracting filaments from micrographs" << endl << endl;
699 for ( field = project->field; field; field = field->next ) {
700 for ( mg = field->mg; mg; mg = mg->next, i++ ) {
701 nfil = filament_count(mg->fil);
702 if ( nfil > 0 ) {
703 if ( base.length() ) {
704 if ( nmg == 1 )
705 filename = base;
706 else
707 filename = base + Bstring(i, "_%03d");
708 } else {
709 if ( mg->ffil.length() < 1 ) mg->ffil = mg->fmg;
710 filename = mg->ffil.pre_rev('.');
711 if ( mg->fmg == mg->ffil )
712 filename = filename + Bstring(mg->img_num, "_fil%03d");
713 }
714 filename = filename + "." + ext;
715 if ( filename.length() < 1 )
716 cerr << "Error in project_extract_filaments: No filament file name!" << endl;
717 if ( split ) {
718 filament_setup_filenames(mg->fil, filename, path);
719 mg->ffil = 0;
720 } else {
721 if ( path.length() ) {
722 if ( filename.contains("/") ) filename = filename.post_rev('/');
723 filename = path + "/" + filename;
724 }
725 mg->ffil = filename;
726 }
727 p = read_img(mg->fmg, 1, mg->img_num);
728 if ( !p ) return -1;
729 micrograph_extract_filaments(mg, p, filament_width, axis);
730 delete p;
731 }
732 }
733 }
734 } else {
735 if ( verbose )
736 cout << "Extracting filaments from reconstructions" << endl << endl;
737 for ( rec = project->rec; rec; rec = rec->next, i++ ) {
738 nfil = filament_count(rec->fil);
739 if ( nfil > 0 ) {
740 if ( base.length() ) {
741 if ( nrec == 1 )
742 filename = base;
743 else
744 filename = base + Bstring(i, "_%03d");
745 } else {
746 if ( rec->ffil.length() < 1 ) rec->ffil = rec->frec;
747 filename = rec->ffil.pre_rev('.');
748 if ( rec->frec == rec->ffil )
749 filename = filename + "_fil.";
750 }
751 filename = filename + "." + ext;
752 if ( filename.length() < 1 )
753 cerr << "Error in project_extract_filaments: No filament file name!" << endl;
754 if ( split ) {
755 filament_setup_filenames(rec->fil, filename, path);
756 rec->ffil = 0;
757 } else {
758 if ( path.length() ) {
759 if ( filename.contains("/") ) filename = filename.post_rev('/');
760 filename = path + "/" + filename;
761 }
762 rec->ffil = filename;
763 }
764 p = read_img(rec->frec, 1, 0);
765 if ( !p ) return -1;
766 reconstruction_extract_filaments(rec, p, filament_width, axis);
767 delete p;
768 }
769 }
770 }
771
772 return nfil;
773 }
774
783 long micrograph_extract_filaments(Bmicrograph* mg, Bimage* p, double width, int axis)
784 {
785 if ( width < 1 ) width = mg->filament_width;
786
787 long nfil = count_list((char *) mg->fil);
788
789 if ( mg->pixel_size > 0 ) p->sampling(mg->pixel_size, mg->pixel_size, 1);
790
791 Bimage* pfil = filament_extract(mg->fil, p, width, axis);
792
793 if ( pfil ) {
794 write_img(mg->ffil, pfil, 0);
795 delete pfil;
796 }
797
798 return nfil;
799 }
800
809 long reconstruction_extract_filaments(Breconstruction* rec, Bimage* p, double width, int axis)
810 {
811 if ( width < 1 ) width = rec->filament_width;
812
813 long nfil = count_list((char *) rec->fil);
814
815 if ( rec->voxel_size > 0 ) p->sampling(rec->voxel_size, rec->voxel_size, rec->voxel_size);
816
817 Bimage* pfil = filament_extract(rec->fil, p, width, axis);
818
819 if ( pfil ) {
820 write_img(rec->ffil, pfil, 0);
821 delete pfil;
822 }
823
824 return nfil;
825 }
826
842 Bimage* filament_extract(Bfilament* filaments, Bimage* p, double width, int axis)
843 {
844 if ( axis < 1 || axis > 3 ) { // Default axis selection
845 if ( p->sizeZ() > 1 ) axis = 3;
846 else axis = 1;
847 }
848
849 int split(0);
850 if ( filaments->ffil.length() ) split = 1;
851
852 long n;
853 long nfil(1), nspline;
854 double length, maxlen(0);
855 Bfilament* fil;
856 Vector3<double>* spline;
857 Vector3<long> size((int)width, (int)width, (int)width);
858 Bimage* pfil = NULL;
859 Bimage* pone = NULL;
860
861 if ( p->sizeX() < width ) size[0] = p->sizeX();
862 if ( p->sizeY() < width ) size[1] = p->sizeY();
863 if ( p->sizeZ() < width ) size[2] = p->sizeZ();
864
865 if ( !split ) {
866 for ( nfil=0, fil=filaments; fil; fil=fil->next ) {
867 length = filament_length(fil) + 1;
868 if ( maxlen < length ) maxlen = length;
869 nfil++;
870 }
871 size[axis-1] = (int) maxlen;
872 pfil = new Bimage(Float, p->compound_type(), size[0], size[1], size[2], nfil);
873 pfil->sampling(p->sampling());
874 pfil->label(p->label());
875 }
876
877 if ( verbose & VERB_DEBUG ) {
878 cout << "DEBUG filament_extract: size=" << size << endl;
879 cout << "DEBUG filament_extract: axis=" << axis << " split=" << split << endl;
880 }
881
882 for ( n=0, fil=filaments; fil; fil=fil->next, n++ ) {
883 spline = vector3_spline_from_nodes(fil->node, nspline);
884 // pone = img_extract_filament(p, 0, width, axis, nspline, spline);
885 pone = p->extract_filament(0, width, axis, nspline, spline);
886 pone->calculate_background();
887 if ( split ) {
888 if ( fil->ffil.length() ) write_img(fil->ffil, pone, 0);
889 else cerr << "Error: No filename for filament " << fil->id << endl;
890 } else {
891 pfil->replace(n, pone, pone->background(long(0)));
892 }
893 delete pone;
894 delete [] spline;
895 }
896
897 return pfil;
898 }
899
914 int project_filaments_to_particles(Bproject* project, Vector3<long> box_size,
915 double boxing_interval, double rise, double angle)
916 {
917 int nfil(0);
918 Bfield* field;
919 Bmicrograph* mg;
920 Breconstruction* rec;
921
922 if ( project->select < 1 ) {
923 for ( field=project->field; field; field=field->next )
924 for ( mg=field->mg; mg; mg=mg->next )
925 nfil += micrograph_filaments_to_particles(mg, box_size, boxing_interval, rise, angle);
926 } else {
927 for ( rec=project->rec; rec; rec=rec->next )
928 nfil += reconstruction_filaments_to_particles(rec, box_size, boxing_interval, rise, angle);
929 }
930
931 return nfil;
932 }
933
948 int micrograph_filaments_to_particles(Bmicrograph* mg, Vector3<long> box_size,
949 double boxing_interval, double rise, double angle)
950 {
951 if ( box_size[0] < 1 ) box_size[0] = 40;
952 if ( box_size[1] < 1 ) box_size[1] = box_size[0];
953 box_size[2] = 1;
954
955 mg->box_size = box_size;
956 if ( boxing_interval < 1 ) boxing_interval = box_size[0]/2;
957
958 if ( verbose & VERB_DEBUG )
959 cout << "DEBUG micrograph_filaments_to_particles: box_size=" << mg->box_size << endl;
960
961 particle_kill(mg->part);
962
963 mg->part = filaments_to_particles(mg->fil, mg->pixel_size, mg->box_size, boxing_interval, rise, angle);
964
965 mg_part_links(mg);
966
967 return filament_count(mg->fil);
968 }
969
984 int reconstruction_filaments_to_particles(Breconstruction* rec, Vector3<long> box_size,
985 double boxing_interval, double rise, double angle)
986 {
987 if ( box_size[0] < 1 ) box_size[0] = 40;
988 if ( box_size[1] < 1 ) box_size[1] = box_size[0];
989 if ( box_size[2] < 1 ) box_size[2] = box_size[0];
990
991 rec->box_size = box_size;
992 if ( boxing_interval < 1 ) boxing_interval = box_size[0]/2;
993
994 if ( verbose & VERB_DEBUG )
995 cout << "DEBUG micrograph_filaments_to_particles: box_size=" << rec->box_size << endl;
996
997 particle_kill(rec->part);
998
999 rec->part = filaments_to_particles(rec->fil, rec->voxel_size, rec->box_size, boxing_interval, rise, angle);
1000
1001 rec_part_links(rec);
1002
1003 return filament_count(rec->fil);
1004 }
1005
1021 Bparticle* filaments_to_particles(Bfilament* filaments, double pixel_size, Vector3<long> box_size,
1022 double boxing_interval, double rise, double angle)
1023 {
1024 long i, n(1), nspline, it, nfil(0);
1025 Bparticle* part_list = NULL;
1026 Bparticle* part = NULL;
1027 Bfilament* fil;
1028 Vector3<double>* spline;
1029 Vector3<double> dir;
1030
1031 double bi, dr = rise/pixel_size, phi(0), st, t, od(0);
1032
1033 if ( verbose & VERB_FULL ) {
1034 cout << "Converting filaments to particles:" << endl;
1035 cout << "Box size: " << box_size << endl;
1036 cout << "Boxing interval: " << boxing_interval << endl;
1037 cout << "Helical rise and angle: " << rise << " A " << angle << " degrees" << endl << endl;
1038 }
1039
1040 for ( fil=filaments; fil; fil=fil->next ) {
1041 nfil++;
1042 spline = vector3_spline_from_nodes(fil->node, nspline);
1043 for ( bi=0; bi<nspline; bi += boxing_interval, n++ ) {
1044 i = (int) (bi + 0.5);
1045 part = particle_add(&part, n);
1046 if ( !part_list ) part_list = part;
1047 part->group = fil->id;
1048 part->loc = spline[i];
1049 part->ori = box_size/2;
1050 if ( i == 0 ) dir = spline[1] - spline[0];
1051 else dir = spline[i] - spline[i-1];
1052 st = sqrt(1 - dir[2]*dir[2]);
1053 if ( angle ) {
1054 t = i/dr;
1055 it = (int) (t + 0.5);
1056 phi = angle * it;
1057 od = (t - it)*dr;
1058 part->ori -= dir*od;
1059 }
1060 part->view = View(cos(phi)*st, sin(phi)*st, dir[2], angle_set_negPI_to_PI(phi - atan2(dir[1],dir[0])));
1061 // if ( spline[i][2] < 1 ) part->ori[2] = 0;
1062 part->sel = nfil;
1063 }
1064 delete[] spline;
1065 }
1066
1067 if ( verbose & VERB_DEBUG )
1068 cout << "DEBUG filaments_to_particles: npart=" << n << endl;
1069
1070 return part_list;
1071 }
1072
1083 int project_mask_filament_particles(Bproject* project, int mask_width)
1084 {
1085 int npart(0);
1086 Bfield* field;
1087 Bmicrograph* mg;
1088 Breconstruction* rec;
1089
1090 if ( project->select < 1 ) {
1091 for ( field=project->field; field; field=field->next )
1092 for ( mg=field->mg; mg; mg=mg->next )
1093 npart += mask_filament_particles(mg->fpart, mg->part, mask_width);
1094 } else {
1095 for ( rec=project->rec; rec; rec=rec->next )
1096 npart += mask_filament_particles(rec->fpart, rec->part, mask_width);
1097 }
1098
1099 return npart;
1100 }
1101
1115 int project_rotate_mask_filament_particles(Bproject* project,
1116 int rotation_axis, int back_flag, int mask_width)
1117 {
1118 if ( project->select ) return 0; // No 3D yet!
1119
1120 if ( rotation_axis < 1 || rotation_axis > 3 ) return 0;
1121
1122 if ( project->select < 1 && rotation_axis > 2 ) return 0;
1123
1124 int npart(0);
1125 Bfield* field;
1126 Bmicrograph* mg;
1127 Breconstruction* rec;
1128
1129 if ( verbose ) {
1130 cout << "Rotating and masking filament particles:" << endl;
1131 cout << "Rotation axis: " << (char) (119+rotation_axis) << endl;
1132 cout << "Mask width: " << mask_width << endl;
1133 if ( back_flag ) cout << "With background correction" << endl;
1134 cout << endl;
1135 }
1136
1137 if ( project->select < 1 ) {
1138 for ( field=project->field; field; field=field->next )
1139 for ( mg=field->mg; mg; mg=mg->next )
1140 npart += rotate_mask_filament_particles(mg->fpart, mg->part,
1141 rotation_axis, back_flag, mask_width);
1142 } else {
1143 for ( rec=project->rec; rec; rec=rec->next )
1144 npart += rotate_mask_filament_particles(rec->fpart, rec->part,
1145 rotation_axis, back_flag, mask_width);
1146 }
1147
1148 return npart;
1149 }
1150
1151 /*
1152 @brief Masks particles extracted from filaments.
1153 @param &filename particle file name.
1154 @param *partlist particle parameters.
1155 @param mask_width width of mask to apply.
1156 @return int number of particles masked.
1157
1158 The orientation of the filament is inferred from the view angle and
1159 the adjacent regions are set to the background.
1160
1161 **/
1162 int mask_filament_particles(Bstring& filename, Bparticle* partlist, int mask_width)
1163 {
1164 int npart(0);
1165 long i, n, x, y, z;
1166 double d, halfwidth = mask_width/2.0;
1167 Vector3<double> u, v;
1168 Euler euler;
1169 Bparticle* part;
1170
1171 Bimage* p = read_img(filename, 1, -1);
1172
1173 long imagesize = p->sizeX()*p->sizeY()*p->sizeZ()*p->channels();
1174
1175 for ( n=0, part = partlist; part; part = part->next, n++ ) {
1176 euler = Euler(part->view);
1177 u[0] = cos(euler.psi());
1178 u[1] = -sin(euler.psi());
1179 for ( i=n*imagesize, z=0; z<p->sizeZ(); z++ ) {
1180 v[2] = z - p->image[n].origin()[2];
1181 for ( y=0; y<p->sizeY(); y++ ) {
1182 v[1] = y - p->image[n].origin()[1];
1183 for ( x=0; x<p->sizeX(); x++, i++ ) {
1184 v[0] = x - p->image[n].origin()[0];
1185 d = (u.cross(v)).length();
1186 if ( d > halfwidth ) p->set(i, p->background(n));
1187 }
1188 }
1189 }
1190 npart++;
1191 }
1192
1193 write_img(filename, p, 0);
1194
1195 delete p;
1196
1197 return npart;
1198 }
1199
1200 /*
1201 @brief Rotates and masks particles extracted from filaments.
1202 @param &filename particle file name.
1203 @param *partlist particle parameters.
1204 @param rotation_axis axis to rotate to: 1=x, 2=y, 3=z.
1205 @param back_flag background correction flag.
1206 @param mask_width width of mask to apply.
1207 @return int number of particles masked.
1208
1209 The orientation of the filament is inferred from the view angle and
1210 the particle is rotated to orient the filament axis along a cartesian axis.
1211 The mask is applied and adjacent regions are set to the background.
1212 **/
1213 int rotate_mask_filament_particles(Bstring& filename, Bparticle* partlist,
1214 int rotation_axis, int back_flag, int mask_width)
1215 {
1216 int npart(0);
1217 long i, j, n, x, y, z;
1218 double d(0), dx(0), dy(0), dz(0), halfwidth;
1219 Euler euler;
1220 Bparticle* part;
1221 Bimage* pex;
1222 Bimage* p = read_img(filename, 1, -1);
1223
1224 if ( !p ) {
1225 error_show("Error in rotate_mask_filament_particles: No image!", __FILE__, __LINE__);
1226 return -1;
1227 }
1228
1229 p->change_type(Float);
1230
1231 if ( mask_width < 1 ) mask_width = (p->sizeX() > p->sizeY())? p->sizeX(): p->sizeY();
1232 halfwidth = mask_width/2.0;
1233
1234 long imagesize = p->sizeX()*p->sizeY()*p->sizeZ()*p->channels();
1235
1236 for ( n=0, part = partlist; part; part = part->next, n++ ) {
1237 pex = p->extract(n);
1238 pex->image[0] = p->image[n];
1239 euler = Euler(part->view);
1240 euler[1] = euler[2] = 0;
1241 if ( rotation_axis == 2 ) euler[0] += M_PI_2;
1242 pex->rotate(euler.matrix());
1243 // img_rotate(pex, euler);
1244 // pex->rotate(euler.view());
1245 for ( i=n*imagesize, j=0, z=0; z<p->sizeZ(); z++ ) {
1246 if ( p->sizeZ() > 1 ) {
1247 dz = fabs(z - p->image[n].origin()[2]);
1248 dz *= dz;
1249 }
1250 for ( y=0; y<p->sizeY(); y++ ) {
1251 dy = fabs(y - p->image[n].origin()[1]);
1252 if ( p->sizeZ() > 1 ) dy *= dy;
1253 for ( x=0; x<p->sizeX(); x++, i++, j++ ) {
1254 dx = fabs(x - p->image[n].origin()[0]);
1255 if ( p->sizeZ() < 2 ) {
1256 if ( rotation_axis == 2 ) d = dx;
1257 else d = dy;
1258 } else {
1259 dx *= dx;
1260 d = sqrt(dx + dy + dz);
1261 }
1262 if ( d > halfwidth ) p->set(i, p->background(n));
1263 else p->set(i, (*pex)[j]);
1264 }
1265 }
1266 }
1267 part->view[3] -= euler.psi();
1268 delete pex;
1269 npart++;
1270 }
1271
1272 if ( back_flag )
1273 p->correct_background();
1274
1275 write_img(filename, p, 0);
1276
1277 delete p;
1278
1279 return npart;
1280 }
1281
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1743
Breconstruction::fil
Bfilament * fil
Definition: mg_processing.h:305
Bparticle::id
int id
Definition: mg_processing.h:92
Euler::matrix
Matrix3 matrix()
Definition: Euler.h:67
M_PI_2
#define M_PI_2
Definition: utilities.h:62
Bimage::replace
int replace(Bimage *img)
Replaces the data with that from the given image.
Definition: Bimage.cpp:2828
filament_count
long filament_count(Bfilament *fil)
Counts the number of filaments in a linked list of filaments.
Definition: mg_processing.cpp:1187
Bparticle::pixel_size
double pixel_size
Definition: mg_processing.h:98
Bproject::rec
Breconstruction * rec
Definition: mg_processing.h:344
FILL_BACKGROUND
#define FILL_BACKGROUND
Definition: utilities.h:174
Bsub_image::view
void view(double x, double y, double z, double a)
Definition: Bimage.h:143
Bparticle::rec
Breconstruction * rec
Definition: mg_processing.h:105
Euler
Definition: Euler.h:28
Bparticle::view
View view
Definition: mg_processing.h:101
Bimage::sampling
Vector3< double > sampling()
Definition: Bimage.h:505
Vector3::length
double length()
Definition: Vector3.h:222
Breconstruction::part
Bparticle * part
Definition: mg_processing.h:304
Breconstruction::mark
Bmarker * mark
Definition: mg_processing.h:307
spline.h
Header file for spline interpolation.
Bimage::normalize
int normalize(long imgnum, double average, double stdev, int norm_type, long bins)
Normalizes a sub-image to a desired average and standard deviation.
Definition: Bimage_rescale.cpp:481
Breconstruction::fpart
Bstring fpart
Definition: mg_processing.h:288
Bbadarea
Definition: mg_processing.h:142
Bmicrograph::img_num
int img_num
Definition: mg_processing.h:211
reconstruction_filaments_to_particles
int reconstruction_filaments_to_particles(Breconstruction *rec, Vector3< long > box_size, double boxing_interval, double rise, double angle)
Converts filaments to sets of particles.
Definition: mg_extract.cpp:984
Breconstruction::filament_width
double filament_width
Definition: mg_processing.h:297
Bfilnode
Definition: mg_processing.h:115
utilities.h
Header file for general utilities.
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:112
Bmicrograph::filament_width
double filament_width
Definition: mg_processing.h:231
Breconstruction
Definition: mg_processing.h:280
angle_set_negPI_to_PI
double angle_set_negPI_to_PI(double angle)
Returns an angle between -PI and PI.
Definition: utilities.cpp:594
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:351
Bbadarea::loc
Vector3< double > loc
Definition: mg_processing.h:145
project_filaments_to_particles
int project_filaments_to_particles(Bproject *project, Vector3< long > box_size, double boxing_interval, double rise, double angle)
Converts filaments to sets of particles.
Definition: mg_extract.cpp:914
Bmarker
Definition: marker.h:21
FILL_AVERAGE
#define FILL_AVERAGE
Definition: utilities.h:173
particle_add
Bparticle * particle_add(Bparticle **part, int pid)
Adds a particle parameter structure to a linked list.
Definition: mg_processing.cpp:527
Bstring::length
long length() const
Definition: Bstring.cpp:263
Bmicrograph::pixel_size
double pixel_size
Definition: mg_processing.h:214
project
Bproject * project
Definition: bshow.cpp:31
count_list
long count_list(char *list)
Counts the number of items in a linked list.
Definition: linked_list.cpp:235
Bstring::truncate
Bstring truncate(const long n)
Definition: Bstring.cpp:495
particle_kill
int particle_kill(Bparticle *part)
Frees a list of particles.
Definition: mg_processing.cpp:1323
particle_count
long particle_count(Bparticle *part)
Counts the number of particles in a linked list.
Definition: mg_processing.cpp:1151
marker_list
Tcl_Obj * marker_list(Bproject *project)
Definition: tcltk_bmarker.cpp:535
Bstring::remove
Bstring remove(const char c)
Definition: Bstring.cpp:465
VERB_PROCESS
#define VERB_PROCESS
Definition: utilities.h:107
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:230
project_count_micrographs
long project_count_micrographs(Bproject *project)
Counts all the micrographs in the project structure.
Definition: mg_processing.cpp:746
Bmicrograph::fil
Bfilament * fil
Definition: mg_processing.h:240
filament_setup_filenames
int filament_setup_filenames(Bfilament *fil, Bstring filename, Bstring filpath)
Sets up individual filament file names for extraction.
Definition: mg_extract.cpp:85
project_extract_particles
long project_extract_particles(Bproject *project, double scale, int back_flag, int norm_flag, int fill_type, double fill, int mask_width, int split, Bstring &partbase, Bstring &partpath, Bstring &partext)
Extracts particle images from micrographs defined in a project.
Definition: mg_extract.cpp:160
Vector3::distance
double distance(const Vector3 &v)
Definition: Vector3.h:227
Breconstruction::box_size
Vector3< long > box_size
Definition: mg_processing.h:296
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:76
Bmicrograph::ffil
Bstring ffil
Definition: mg_processing.h:208
Bfield::next
Bfield * next
Definition: mg_processing.h:258
Bimage::extract_filament
Bimage * extract_filament(long img_num, double width, int axis, long nspline, Vector3< double > *spline)
Extracts a filament defined by a series of coordinates.
Definition: Bimage_extract.cpp:1132
Bmicrograph::part
Bparticle * part
Definition: mg_processing.h:239
TSimple
Definition: Bimage.h:58
Bfilament::id
int id
Definition: mg_processing.h:131
Breconstruction::mark_radius
double mark_radius
Definition: mg_processing.h:301
Bfilament::node
Bfilnode * node
Definition: mg_processing.h:132
Float
Definition: utilities.h:157
Vector3::max
Type max()
Definition: Vector3.h:175
particle_extract
Bimage * particle_extract(Bparticle *particles, Bbadarea *bad_areas, Bimage *p, Vector3< long > size, double scale, double bad_radius, int back_flag, int norm_flag, double fill, int mask_width)
Extracts particle images from an image.
Definition: mg_extract.cpp:403
Bimage
General image parameter class.
Definition: Bimage.h:163
Bmicrograph::fpart
Bstring fpart
Definition: mg_processing.h:207
project_mask_filament_particles
int project_mask_filament_particles(Bproject *project, int mask_width)
Masks particles extracted from filaments.
Definition: mg_extract.cpp:1083
Bfilament::next
Bfilament * next
Definition: mg_processing.h:129
mg_part_links
int mg_part_links(Bmicrograph *mg)
Sets the links from particles to micrographs.
Definition: mg_processing.cpp:555
verbose
int verbose
Bstring::contains
bool contains(const Bstring &s)
Definition: Bstring.cpp:584
Bparticle::sel
long sel
Definition: mg_processing.h:103
Bfield
Definition: mg_processing.h:257
linked_list.h
Header file for generalized linked list functions.
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
Bparticle::mg
Bmicrograph * mg
Definition: mg_processing.h:104
base
string base(string &filename)
Definition: string_util.cpp:28
Bimage::correct_background
int correct_background(long nn, int flag)
Corrects the background for one sub-image.
Definition: Bimage_background.cpp:202
Euler::psi
double psi()
Definition: Euler.h:56
project_extract_filaments
long project_extract_filaments(Bproject *project, int filament_width, int axis, Bstring &base, Bstring &path, Bstring &ext, int split)
Extracts filament images from micrographs defined in a project.
Definition: mg_extract.cpp:674
Bbadarea::next
Bbadarea * next
Definition: mg_processing.h:143
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bmicrograph::mark_radius
double mark_radius
Definition: mg_processing.h:235
Bimage::sphere
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.
Definition: Bimage_edit.cpp:438
Bimage::label
void label(string s)
Definition: Bimage.h:235
Bproject::field
Bfield * field
Definition: mg_processing.h:343
length
double length(vector< T > v)
Definition: Vector3.h:528
filaments_to_particles
Bparticle * filaments_to_particles(Bfilament *filaments, double pixel_size, Vector3< long > box_size, double boxing_interval, double rise, double angle)
Converts filaments to sets of particles.
Definition: mg_extract.cpp:1021
Bmicrograph
Definition: mg_processing.h:200
vector3_spline_from_nodes
Vector3< double > * vector3_spline_from_nodes(Bfilnode *fnode, long &nspline)
Calculates a spline curve from a set of filament nodes.
Definition: mg_extract.cpp:127
particle_setup_filenames
int particle_setup_filenames(Bparticle *part, Bstring filename, Bstring partpath)
Sets up individual particle file names for extraction.
Definition: mg_extract.cpp:35
mg_extract.h
Header file for functions to extract particles from micrographs.
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:280
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:373
Bparticle::group
int group
Definition: mg_processing.h:93
Bimage::calculate_background
int calculate_background(long nn, int flag)
Calculates the background for one sub-image.
Definition: Bimage_background.cpp:27
FILL_USER
#define FILL_USER
Definition: utilities.h:172
Bparticle::fpart
Bstring fpart
Definition: mg_processing.h:91
project_rotate_mask_filament_particles
int project_rotate_mask_filament_particles(Bproject *project, int rotation_axis, int back_flag, int mask_width)
Rotates and masks particles extracted from filaments.
Definition: mg_extract.cpp:1115
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:127
Bparticle::ori
Vector3< double > ori
Definition: mg_processing.h:100
Bimage::channels
long channels()
Definition: Bimage.h:371
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
filament_length
double filament_length(Bfilament *fil)
Calculates the length of a filament.
Definition: mg_processing.cpp:681
Bmicrograph::mark
Bmarker * mark
Definition: mg_processing.h:242
Bmarker::next
Bmarker * next
Definition: marker.h:22
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:537
Bfield::mg
Bmicrograph * mg
Definition: mg_processing.h:264
Bstring::post_rev
Bstring post_rev(char c)
Definition: Bstring.cpp:428
Bimage::set
void set(long j, double v)
Sets a single value at the given index.
Definition: Bimage.cpp:1096
vector3_catmull_rom_spline
Vector3< double > * vector3_catmull_rom_spline(long ncoord, Vector3< double > *coords, long &nspline)
Calculates a 2D/3D spline curve using the Catmull-Rom algorithm.
Definition: spline.cpp:33
micrograph_extract_gold
Bimage * micrograph_extract_gold(Bmicrograph *mg, Bimage *p, double radius)
Extracts gold particle images from a micrograph.
Definition: mg_extract.cpp:573
filament_extract
Bimage * filament_extract(Bfilament *filaments, Bimage *p, double width, int axis)
Extracts filament images from a micrograph.
Definition: mg_extract.cpp:842
marker_extract_gold
Bimage * marker_extract_gold(Bmarker *marker_list, Bimage *p, int img_num, double radius)
Extracts gold particle images from an image.
Definition: mg_extract.cpp:610
Bparticle
Definition: mg_processing.h:89
UCharacter
Definition: utilities.h:149
Bstring
Definition: Bstring.h:29
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:377
micrograph_extract_filaments
long micrograph_extract_filaments(Bmicrograph *mg, Bimage *p, double width, int axis)
Extracts filament images from a micrograph.
Definition: mg_extract.cpp:783
Bproject::select
int select
Definition: mg_processing.h:339
Breconstruction::bad_radius
double bad_radius
Definition: mg_processing.h:299
project_count_reconstructions
long project_count_reconstructions(Bproject *project)
Counts all the reconstructions in the project structure.
Definition: mg_processing.cpp:780
Bstring::count
long count(const char c)
Definition: Bstring.cpp:269
Bmicrograph::box_size
Vector3< long > box_size
Definition: mg_processing.h:230
Bfilament::ffil
Bstring ffil
Definition: mg_processing.h:130
reconstruction_extract_filaments
long reconstruction_extract_filaments(Breconstruction *rec, Bimage *p, double width, int axis)
Extracts filament images from a micrograph.
Definition: mg_extract.cpp:809
Breconstruction::ffil
Bstring ffil
Definition: mg_processing.h:289
micrograph_extract_particles
long micrograph_extract_particles(Bmicrograph *mg, Bimage *p, double scale, int back_flag, int norm_flag, double fill, int mask_width)
Extracts particle images from a micrograph.
Definition: mg_extract.cpp:332
Breconstruction::bad
Bbadarea * bad
Definition: mg_processing.h:306
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:379
Vector3< double >
Bmicrograph::fmg
Bstring fmg
Definition: mg_processing.h:205
Bparticle::loc
Vector3< double > loc
Definition: mg_processing.h:99
Bfilnode::next
Bfilnode * next
Definition: mg_processing.h:116
View
Definition: View.h:26
Bmicrograph::bad
Bbadarea * bad
Definition: mg_processing.h:241
reconstruction_extract_gold
Bimage * reconstruction_extract_gold(Breconstruction *rec, Bimage *p, double radius)
Extracts gold particle images from a reconstruction.
Definition: mg_extract.cpp:591
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:253
Vector3::min
Type min()
Definition: Vector3.h:169
Bmarker::loc
Vector3< float > loc
Definition: marker.h:25
Bimage::average
double average(long cc, double xf, double yf, double zf, long nn, double iscale)
Averages in 3D when scaling is less than 1.
Definition: Bimage.cpp:1349
Breconstruction::frec
Bstring frec
Definition: mg_processing.h:287
Breconstruction::voxel_size
double voxel_size
Definition: mg_processing.h:292
mask_filament_particles
int mask_filament_particles(Bstring &filename, Bparticle *partlist, int mask_width)
Definition: mg_extract.cpp:1162
Bimage::images
long images()
Definition: Bimage.h:491
rotate_mask_filament_particles
int rotate_mask_filament_particles(Bstring &filename, Bparticle *partlist, int rotation_axis, int back_flag, int mask_width)
Definition: mg_extract.cpp:1213
Bimage::fill
void fill(double v)
Definition: Bimage.h:698
Bmicrograph::bad_radius
double bad_radius
Definition: mg_processing.h:233
Bstring::pre_rev
Bstring pre_rev(char c)
Definition: Bstring.cpp:413
reconstruction_extract_particles
long reconstruction_extract_particles(Breconstruction *rec, Bimage *p, double scale, int back_flag, int norm_flag, double fill, int mask_width)
Extracts particle images from a reconstruction.
Definition: mg_extract.cpp:363
split
vector< string > split(const string &s)
Splits a string on whitespace.
Definition: string_util.cpp:92
rec_part_links
int rec_part_links(Breconstruction *rec)
Sets the links from particles to reconstructions.
Definition: mg_processing.cpp:571
Bstring::empty
bool empty()
Definition: Bstring.h:71
micrograph_filaments_to_particles
int micrograph_filaments_to_particles(Bmicrograph *mg, Vector3< long > box_size, double boxing_interval, double rise, double angle)
Converts filaments to sets of particles.
Definition: mg_extract.cpp:948
Vector3::volume
double volume()
Definition: Vector3.h:235
Bparticle::next
Bparticle * next
Definition: mg_processing.h:90
VERB_FULL
#define VERB_FULL
Definition: utilities.h:109
Bimage::background
double background(long nn)
Definition: Bimage.h:542
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:378
Bimage::data_type
DataType data_type()
Definition: Bimage.h:349
Bfilnode::loc
Vector3< double > loc
Definition: mg_processing.h:118
Bsub_image::standard_deviation
double standard_deviation()
Definition: Bimage.h:116
Breconstruction::next
Breconstruction * next
Definition: mg_processing.h:281
error_show
int error_show(string message, string file, int line)
Displays the error with file and line reference.
Definition: utilities.cpp:755
Bproject
Definition: mg_processing.h:333
Bimage::image
Bsub_image * image
Definition: Bimage.h:188
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:563
Bfilament
Definition: mg_processing.h:128
Bmicrograph::next
Bmicrograph * next
Definition: mg_processing.h:201