Bsoft  2.1.0
Bernard's software package
tcltk_bimage.cpp
Go to the documentation of this file.
1 
9 // Tk must be included before anything else to remedy symbol conflicts
10 #include <tk.h>
11 
12 //#include "tcltk_bimage.h"
13 #include "rwimg.h"
14 #include "mg_ctf.h"
15 #include "Vector3.h"
16 #include "Euler.h"
17 #include "linked_list.h"
18 #include "timer.h"
19 #include "utilities.h"
20 
21 // Declaration of global variables
22 extern int verbose; // Level of output to the screen
23 extern string command; // Command line
24 extern Bimage* imglist;
25 extern Bimage* imgtemp;
26 
27 struct Bmontage {
28  int ncol, nrow;
29  int first, skip, pad, flip;
30  double fill;
31 } mont = {0,0,0,0,0,0,0};
32 
33 // Internal function prototypes
34 int do_show(Bimage* p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
35 int do_magnify(Bimage* p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
36 int do_template(Bimage* p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[]);
38 Tcl_Obj* do_delete(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
39 Tcl_Obj* do_get(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
40 Tcl_Obj* do_line(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
41 int do_set(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
42 int do_switch(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
43 int do_fix_type(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
44 Tcl_Obj* do_stats(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
45 int do_center(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
46 int do_zero_origin(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
47 int do_extract(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
48 int do_crop(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
49 int do_pad(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
50 int do_invert(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
51 int do_truncate(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
52 int do_rescale(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
53 int do_reslice(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
54 int do_rotate(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
55 int do_bin(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
56 int do_average(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
57 int do_variance(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
58 int do_normalize(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
59 int do_gaussian(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
60 Tcl_Obj* do_histogram(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
61 Tcl_Obj* do_radial_average(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
62 int do_diffraction_origin(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
63 int do_fft(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
64 Bimage* do_powerspec(Bimage* p, int objc, Tcl_Obj *CONST objv[]);
65 
66 /************************************************************************
67 @brief Implements the "Bimage" command in Tcl/Tk to access image files through Bsoft.
68 @param *interp a Tcl interpreter within Tcl.
69 @param objc number of arguments passed (+1).
70 @param *objv[] arguments passed as Tcl objects.
71 @return int Tcl result.
72 
73  Bimage command syntax:
74  Bimage <action> <tcl_object> <arguments>.
75  where:
76  action "exists", "open", "save", "show", "magnify", "kill", "get", "set", "reslice",
77  "stats", "montage", "center", "zero_origin", "histogram", "powerspec", "findgold",
78  "rps", "ctf", "ctf_fit", "pick", "extract_particles", "extract_filament", "refine"
79  tcl_object a photo object "theimg" generated by "image create photo theimg"
80  arguments action-specific arguments:
81  "open" <file_name> <image_number>
82  "close" <file_name>
83  "save" <file_name>
84  "show" <image_number> <slice_number> <mode>
85  "magnify" <x> <y> <z> <scale> <size_x> <size_y> <size_z>
86  "statistics"
87  "get" <property> [arguments]
88  "set" <property> <value>
89  "fixtype"
90  "stats" <image_number> <selection_type> <polygon>
91  "extract" <file_name> <image_number> <start> <end>
92  "crop" <image_number> <start> <end>
93  "pad" <xm> <ym> <zm> <xp> <yp> <zp> <filletype> <fill>
94  "center"
95  "zero_origin"
96  "invert"
97  "truncate" <minimum> <maximum>
98  "rescale" <average> <standard_deviation>
99  "reslice" <order>
100  "rotate" <psi> <theta> <phi>
101  "bin" <bin_x> <bin_y> <bin_z>
102  "average" <k_x> <k_y> <k_z>
103  "normalize" <k_x> <k_y> <k_z>
104  "montage" <first> <columns> <rows> <skip> <pad> <fill>
105  "histogram" <bins>
106  "radial" <origin_x> <origin_y> <origin_z> <angle>
107  "diffori" <origin_x> <origin_y> <origin_z>
108  "fft" <direction>
109  "powerspec" <log_flag> <avg_flag> <tile.x> <tile.y> <tile.z> <tilt_axis> <tilt_angle>
110  "rps" <defocus_average> <defocus_deviation> <astigmatism_angle>
111  "ctf_fit" <defocus_average> <defocus_deviation> <astigmatism_angle>
112  <voltage> <Cs> <amplitude_factor>
113  "pick" <particle_diameter> <gaussian_edge> <cc_threshold>
114  "read_model" <file_name>
115  "write_model" <file_name> <coordinates> <links>
116  "extract_panels" <file_name> <coordinates>
117  where:
118  property "info"
119  "filename <string>"
120  "label <string>"
121  "nimages <number>"
122  "channels <number>"
123  "nslices <number>"
124  "width <pixels>"
125  "height <pixels>"
126  "size <x> <y> <z>"
127  "center"
128  "origin <x> <y> <z> <img_num>"
129  "min <value>"
130  "max <value>"
131  "show_min <value>"
132  "show_max <value>"
133  "average"
134  "standard_deviation"
135  "background"
136  "datatype <string>"
137  "pixel_size <angstrom>"
138  "pixel <x> <y>"
139  Return values:
140  Each action may have a return value:
141  "open" number of images
142  "get" return value based on property
143  "set" modify image property
144  "histogram" array of integer values
145  "rps" array of values for radial average
146  "ctf_fit" baseline and envelope equations, defocus average
147  and deviation and astigmatism angle
148  "pick" array of particle coordinates (each x y)
149  "extract_filament" (none)
150  "extract_panels" (none)
151  Note: For the rps and ctf actions, the pixel size, voltage, Cs and amplitude
152  factor must be set in the image structure.
153 
154 **/
155 int image_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
156 {
157 // verbose = VERB_DEBUG;
158 
159  Tcl_ResetResult(interp);
160 
161  int img_num(0);
162 
163  if ( objc < 3 ) {
164  Tcl_AppendResult(interp, "wrong # args", (char *)NULL);
165  return TCL_ERROR;
166  }
167 
168  Bstring action = Tcl_GetStringFromObj(objv[1], NULL);
169  if ( verbose & VERB_DEBUG )
170  cout << "DEBUG BimageCmd: Action: " << action << " (" << action.length() << ")" << endl;
171 
172  /* Name of object in Tcl/Tk script */
173  Bstring photoName = Tcl_GetStringFromObj(objv[2], NULL);
174  if ( verbose & VERB_DEBUG )
175  cout << "DEBUG BimageCmd: Image object name: " << photoName << "(" << photoName.length() << ")" << endl;
176 
177  Tcl_Obj* returnObj = Tcl_NewObj();
178 
179  char string[4] = " ";
180  Tcl_SetStringObj(returnObj, string, 1);
181 
182  int tmp(0);
183  Bstring file_name, item, id;
184  Bimage* p = NULL;
185  Bimage* ptemp = NULL;
186  Bimage* pnew = NULL;
187 
188  for ( p = imglist; p; p = p->next )
189  if ( p->identifier() == photoName ) break;
190 
191  if ( !p && imgtemp && imgtemp->identifier() == photoName ) {
192  p = imgtemp;
193  tmp = 1;
194  } else if ( photoName == "thetemp" ) tmp = 1;
195 
196 /*
197  if ( imglist && !p ) {
198  cerr << "Error: image id \"" << photoName << "\" not recognised!" << endl;
199  cerr << "Possible id's: ";
200  for ( p = imglist; p; p = p->next )
201  cerr << p->identifier() << " ";
202  cerr << endl;
203  bexit(-1);
204  }
205 */
206  if ( action == "exists" ) {
207  if ( p ) Tcl_SetIntObj(returnObj, 1);
208  else Tcl_SetIntObj(returnObj, 0);
209  } else if ( action == "open" ) {
210 
211  if ( objc < 4 ) {
212  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
213  return TCL_ERROR;
214  }
215 
216  // Image file name
217  file_name = Tcl_GetStringFromObj(objv[3], NULL);
218  if ( verbose & VERB_DEBUG )
219  cout << "DEBUG BimageCmd: File name: " << file_name << "(" << file_name.length() << ")" << endl;
220 
221  // Sub-image number
222  img_num = -1;
223  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &img_num);
224  if ( verbose & VERB_DEBUG )
225  cout << "DEBUG BimageCmd: Image number: " << img_num << endl;
226 
227  // First check of the image is readable
228  ptemp = read_img(file_name, 0, img_num);
229  if ( !ptemp ) {
230  Tcl_AppendResult(interp, "File not read!", (char *)NULL);
231  return TCL_ERROR;
232  }
233 
234  delete ptemp;
235 
236  if ( verbose & VERB_DEBUG )
237  cout << "DEBUG BimageCmd: list: " << imglist << " pointer: " << p << endl;
238 
239  if ( p ) {
240  if ( p == imgtemp ) {
241  tmp = 1;
242  } else if ( p == imglist ) {
243  if ( p->next ) imglist = p->next;
244  else imglist = NULL;
245  } else {
246  for ( ptemp = imglist; ptemp; ptemp = ptemp->next ) {
247  if ( ptemp->next == p ) {
248  ptemp->next = p->next;
249  break;
250  }
251  }
252  }
253  delete p; // Clear the image pointer if it has been allocated
254  p = NULL;
255  }
256 
257  pnew = read_img(file_name, 1, img_num);
258  if ( verbose & VERB_DEBUG )
259  cout << "DEBUG BimageCmd: Image pointer: " << pnew << endl;
260 
261  Tcl_SetIntObj(returnObj, -1);
262 
263  if ( !pnew ) {
264  Tcl_AppendResult(interp, "File not read!", (char *)NULL);
265  return TCL_ERROR;
266  }
267 
268  if ( pnew->standard_deviation() <= 0 )
269  pnew->statistics();
270 
271  if ( tmp ) {
272  imgtemp = pnew;
273 // cout << "imgtemp=" << imgtemp->file_name() << endl;
274  } else if ( imglist ) {
275  for ( p = imglist; p->next; p = p->next ) ;
276  p->next = pnew;
277  } else {
278  imglist = pnew;
279  }
280 
281  pnew->identifier(photoName);
282 
283  Tcl_SetIntObj(returnObj, pnew->images());
284 
285  } else if ( action == "close" ) {
286 
287  if ( objc < 4 ) {
288  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
289  return TCL_ERROR;
290  }
291 
292  // Image file name
293  file_name = Tcl_GetStringFromObj(objv[3], NULL);
294  if ( verbose & VERB_DEBUG )
295  cout << "DEBUG BimageCmd: File name: " << file_name << "(" << file_name.length() << ")" << endl;
296 
297  if ( p == imglist ) {
298  if ( p->next ) imglist = p->next;
299  else imglist = NULL;
300  } else {
301  for ( ptemp = imglist; ptemp; ptemp = ptemp->next ) {
302  if ( ptemp->next == p ) {
303  ptemp->next = p->next;
304  break;
305  }
306  }
307  }
308 
309  if ( verbose & VERB_DEBUG )
310  cout << "DEBUG BimageCmd: Deleting: " << p->file_name() << endl;
311  delete p;
312  p = NULL;
313 
314  } else if ( action == "kill" ) {
315  for ( p = imglist; p; ) {
316  imglist = imglist->next;
317  delete p;
318  p = imglist;
319  }
320  } else if ( action == "save" ) {
321  if ( objc < 4 ) {
322  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
323  return TCL_ERROR;
324  }
325 
326  /* Image file name */
327  file_name = Tcl_GetStringFromObj(objv[3], NULL);
328  if ( verbose & VERB_DEBUG )
329  cout << "DEBUG BimageCmd: File name: " << file_name << "(" << file_name.length() << ")" << endl;
330 
331  if ( !p ) {
332  Tcl_AppendResult(interp, "No file in memory!", (char *)NULL);
333  return TCL_ERROR;
334  }
335 
336  command = "Written from bshow";
337  write_img(file_name, p, 0);
338 
339  } else if ( action == "save_montage" ) {
340  if ( objc < 4 ) {
341  Tcl_AppendResult(interp, "No file name given!", (char *)NULL);
342  return TCL_ERROR;
343  }
344 
345  /* Image file name */
346  file_name = Tcl_GetStringFromObj(objv[3], NULL);
347  if ( verbose & VERB_DEBUG )
348  cout << "DEBUG BimageCmd: File name: " << file_name << "(" << file_name.length() << ")" << endl;
349 
350  if ( !p ) {
351  Tcl_AppendResult(interp, "No file in memory!", (char *)NULL);
352  return TCL_ERROR;
353  }
354 
355  pnew = do_montage(p);
356 
357  command = "Written from bshow";
358  write_img(file_name, pnew, 0);
359 
360  delete pnew;
361 
362  } else if ( action == "show" ) {
363  if ( p ) do_show(p, interp, objc, objv);
364  } else if ( action == "template" ) {
365 // if ( imgtemp ) do_show(imgtemp, interp, objc, objv);
366  if ( imgtemp ) do_template(imgtemp, interp, objc, objv);
367  } else if ( action == "magnify" ) {
368  p = imglist;
369  do_magnify(p, interp, objc, objv);
370  } else if ( action == "montage" ) {
371  pnew = do_montage(p);
372  if ( pnew ) {
373  pnew->identifier(p->identifier());
374  replace_item((char**) &imglist, (char *)p, (char *)pnew);
375  }
376  } else if ( action == "delete" ) {
377  do_delete(p, objc, objv);
378  } else if ( action == "statistics" ) {
379  p->statistics();
380  } else if ( action == "get" ) {
381  returnObj = do_get(p, objc, objv);
382  } else if ( action == "set" ) {
383  do_set(p, objc, objv);
384  } else if ( action == "switch" ) {
385  do_switch(p, objc, objv);
386  } else if ( action == "fixtype" ) {
387  do_fix_type(p, objc, objv);
388  } else if ( action == "stats" ) {
389  returnObj = do_stats(p, objc, objv);
390  } else if ( action == "center" ) {
391  do_center(p, objc, objv);
392  } else if ( action == "zero_origin" ) {
393  do_zero_origin(p, objc, objv);
394  } else if ( action == "extract" ) {
395  do_extract(p, objc, objv);
396  } else if ( action == "crop" ) {
397  do_crop(p, objc, objv);
398  } else if ( action == "pad" ) {
399  do_pad(p, objc, objv);
400  } else if ( action == "invert" ) {
401  do_invert(p, objc, objv);
402  } else if ( action == "truncate" ) {
403  do_truncate(p, objc, objv);
404  } else if ( action == "rescale" ) {
405  do_rescale(p, objc, objv);
406  } else if ( action == "reslice" ) {
407  do_reslice(p, objc, objv);
408  } else if ( action == "rotate" ) {
409  do_rotate(p, objc, objv);
410  } else if ( action == "bin" ) {
411  do_bin(p, objc, objv);
412  } else if ( action == "average" ) {
413  do_average(p, objc, objv);
414  } else if ( action == "variance" ) {
415  do_variance(p, objc, objv);
416  } else if ( action == "normalize" ) {
417  do_normalize(p, objc, objv);
418  } else if ( action == "gaussian" ) {
419  do_gaussian(p, objc, objv);
420  } else if ( action == "histogram" ) {
421  returnObj = do_histogram(p, objc, objv);
422  } else if ( action == "radial" ) {
423  returnObj = do_radial_average(p, objc, objv);
424  } else if ( action == "fft" ) {
425  do_fft(p, objc, objv);
426  } else if ( action == "powerspec" ) {
427  pnew = do_powerspec(p, objc, objv);
428  if ( pnew ) {
429  pnew->identifier(p->identifier());
430  replace_item((char**) &imglist, (char *)p, (char *)pnew);
431  }
432  } else if ( action == "diffori" ) {
433  do_diffraction_origin(p, objc, objv);
434  } else {
435  cerr << "Error: Action " << action << " not recognized!" << endl;
436  }
437 
438  Tcl_SetObjResult(interp, returnObj);
439 // Tcl_SetResult(interp, returnObj);
440 
441  return TCL_OK;
442 }
443 
444 int image_render(Bimage* p, long i, Tcl_Interp *interp, Bstring& photoName)
445 {
446  Tk_PhotoHandle photoHandle = Tk_FindPhoto(interp, photoName.c_str());
447  Tk_PhotoImageBlock block;
448 
449  if ( verbose & VERB_DEBUG )
450  cout << "DEBUG image_render: photoName = " << photoName << endl;
451 
452 #ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE
453  Tk_PhotoSetSize(photoHandle, p->sizeX(), p->sizeY());
454 #else
455  Tk_PhotoSetSize(interp, photoHandle, p->sizeX(), p->sizeY());
456 #endif
457 
458  unsigned long imgsize = p->sizeX()*p->sizeY()*p->channels();
459 
460  // Pointer to the data
461  block.pixelPtr = (unsigned char *) (p->data_pointer() + i*imgsize);
462 
463  // the dimensions of the data
464  block.width = p->sizeX();
465  block.height = p->sizeY();
466 
467  if ( verbose & VERB_DEBUG )
468  cout << "DEBUG image_render: width = " << block.width << " height = " << block.height << endl;
469 
470  // number of bytes between adjacent scanlines
471  block.pitch = p->sizeX()*p->channels();
472 
473  // number of bytes of one pixel
474  block.pixelSize = p->channels();
475 
476  if ( verbose & VERB_DEBUG )
477  cout << "DEBUG image_render: pixelSize = " << block.pixelSize << " pitch = " << block.pitch << endl;
478 
479  // byte offsets for grayscale are all zero.
480  block.offset[0] = block.offset[1] = block.offset[2] = 0;
481 
482  // byte offsets to each of three color bands (r, g, b).
483  if ( p->channels() >= 3 ) {
484  block.offset[1] = 1;
485  block.offset[2] = 2;
486  }
487 
488  // offset for the alpha channel
489  if ( sizeof(block.offset) > 12 ) {
490  block.offset[3] = 0;
491  if ( p->channels() == 4 ) block.offset[3] = 3;
492  }
493 
494  if ( verbose & VERB_DEBUG )
495  cout << "DEBUG image_render: offset=" << block.offset[0] <<
496  "," << block.offset[1] << "," << block.offset[2] <<
497  "," << block.offset[3] << endl;
498 
499  // Load the data into the display frame
500 #ifdef TK_PHOTO_COMPOSITE_SET
501 # ifdef USE_PANIC_ON_PHOTO_ALLOC_FAILURE
502  Tk_PhotoPutBlock(photoHandle, &block, 0, 0, p->sizeX(), p->sizeY(), TK_PHOTO_COMPOSITE_SET);
503 // cout << "111" << endl;
504 # else
505  Tk_PhotoPutBlock(interp, photoHandle, &block, 0, 0, p->sizeX(), p->sizeY(), TK_PHOTO_COMPOSITE_SET);
506 // cout << "222" << endl;
507 # endif
508 #else
509  Tk_PhotoPutBlock(photoHandle, &block, 0, 0, p->sizeX(), p->sizeY());
510 // cout << "333" << endl;
511 #endif
512 
513  return 0;
514 }
515 
516 int do_show(Bimage* p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
517 {
518  if ( !p ) return 0;
519 
520  int mode(0);
521  int slice_num(p->show_slice()), img_num(p->show_image());
522  double dscale(p->show_scale());
523  Tk_PhotoHandle photoHandle;
524 
525  // Name of object in Tcl/Tk script
526  Bstring photoName = Tcl_GetStringFromObj(objv[2], NULL);
527 
528  if ( verbose & VERB_DEBUG )
529  cout << "DEBUG do_show: Image pointer: " << p << endl;
530 
531  // Sub-image number
532  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &img_num);
533  if ( verbose & VERB_DEBUG )
534  cout << "DEBUG do_show: Image number: " << img_num << endl;
535 
536  if ( img_num < 0 || img_num >= (long)p->images() ) img_num = 0;
537 
538  // Slice number
539  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &slice_num);
540  if ( verbose & VERB_DEBUG )
541  cout << "DEBUG do_show: Slice number: " << slice_num << endl;
542 
543  if ( slice_num < 0 || slice_num >= (long)p->sizeZ() ) slice_num = 0;
544 
545  // Scale
546  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &dscale);
547  if ( verbose & VERB_DEBUG )
548  cout << "DEBUG do_show: Scale: " << dscale << endl;
549 
550  if ( dscale < 0.1 ) dscale = 0.1;
551  if ( dscale > 10 ) dscale = 10;
552 
553  // Mode
554  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &mode);
555  if ( verbose & VERB_DEBUG )
556  cout << "DEBUG do_show: Mode: " << mode << endl;
557 
558  // Handle to object in Tcl/Tk script
559  photoHandle = Tk_FindPhoto(interp, photoName.c_str());
560  if ( photoHandle == NULL ) {
561  Tcl_AppendResult(interp, "can't find photo named \"",
562  photoName.c_str(), "\"", (char *)NULL);
563  return TCL_ERROR;
564  }
565 
566  p->show_image(img_num);
567  p->show_slice(slice_num);
568  p->show_scale(dscale);
569 
570 // verbose = 32;
571  double t = timer_start();
572 
573  Bimage* pshow = NULL;
574 
575  // Extract only the slice to be shown
576  if ( mont.ncol < 1 || mont.nrow < 1 ) {
577  pshow = p->extract_show(mode);
578  } else {
579 // cout << "montaging" << endl;
580  Bimage* pm = do_montage(p);
581 // cout << "extracting" << endl;
582 // verbose = 255;
583  pm->show_scale(dscale);
584  pm->show_image(0);
585  pm->show_slice(0);
586  pm->show_minimum(p->show_minimum());
587  pm->show_maximum(p->show_maximum());
588  pshow = pm->extract_show(mode);
589  delete pm;
590  }
591 
592  if ( verbose & VERB_TIME )
593  cout << "Time to extract: ";
594  timer_report(t);
595 
596  t = timer_start();
597 
598  image_render(pshow, 0, interp, photoName);
599 
600  if ( verbose & VERB_TIME )
601  cout << "Time to render: ";
602  timer_report(t);
603  verbose = 0;
604 
605  delete pshow;
606 
607  return 0;
608 }
609 
610 int do_magnify(Bimage* p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
611 {
612  if ( !p ) return 0;
613 
614  int h, img_num(0);
615  Vector3<int> center, size;
616  double scale(2);
617 
618  Bstring photoName;
619  Bstring baseName = Tcl_GetStringFromObj(objv[2], NULL);
620 
621  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &img_num);
622  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &center[0]);
623  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &center[1]);
624  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &center[2]);
625  if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &scale);
626  if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &size[0]);
627  if ( objc > 9 ) Tcl_GetIntFromObj(NULL, objv[9], &size[1]);
628  if ( objc > 10 ) Tcl_GetIntFromObj(NULL, objv[10], &size[2]);
629 
630  if ( verbose & VERB_DEBUG ) {
631  cout << "DEBUG do_magnify: img=" << img_num << " center=" << center << endl;
632  }
633 
634  Bimage* pmag = p->extract_magnify(img_num, center, size, scale);
635  if ( !pmag ) return 0;
636 // write_img("t.tif", pmag);
637 
638  for ( h=0; h<pmag->images(); h++ ) {
639  photoName = baseName + Bstring(h, "%d");
640  image_render(pmag, h, interp, photoName);
641  }
642 
643  delete pmag;
644 
645  return 0;
646 }
647 
648 int do_template(Bimage* p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
649 {
650  if ( !p ) return 0;
651 
652  int slice_num(p->show_slice());
653  double dscale(p->show_scale());
654 
655  Bstring photoName = Tcl_GetStringFromObj(objv[2], NULL);
656 
657  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &slice_num);
658  if ( slice_num < 0 || slice_num >= p->sizeZ() ) slice_num = p->sizeZ()/2;
659 
660  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &dscale);
661 
662  if ( verbose & VERB_DEBUG )
663  cout << "DEBUG do_template: slice_num=" << slice_num << " dscale=" << dscale << endl;
664 
665  Bimage* pt = p->extract_slice(slice_num);
666  if ( !pt ) return 0;
667 
668 // write_img("pt.pif", pt);
669 
670  if ( verbose & VERB_DEBUG )
671  cout << "DEBUG do_template: slices=" << pt->images() << endl;
672 
673  Bimage* pm = pt->montage(0, pt->images(), 1);
674 
675 // write_img("pm.pif", pm);
676 
677  delete pt;
678 
679  pm->show_image(0);
680  pm->show_slice(0);
681  pm->show_scale(dscale);
682 
683  Bimage* pshow = pm->extract_show(1);
684 
685  delete pm;
686 
687  image_render(pshow, 0, interp, photoName);
688 
689  delete pshow;
690 
691  return 0;
692 }
693 
695 {
696  if ( !p ) return NULL;
697 
698 // cout << "montaging" << endl;
699 
700  Bimage* pp = p;
701  if ( mont.pad ) {
702  Vector3<long> newsize(p->sizeX()+2*mont.pad, p->sizeY()+2*mont.pad, p->sizeZ());
703  Vector3<long> translate(mont.pad, mont.pad, 0);
704  pp = p->resize_copy(newsize, translate, FILL_USER, mont.fill);
705  }
706 
708 
709  if ( pp != p ) delete pp;
710 
711 // cout << "done montaging" << endl;
712 
713  return pm;
714 }
715 
716 Tcl_Obj* do_delete(Bimage* p, int objc, Tcl_Obj *CONST objv[])
717 {
718  Tcl_Obj* returnObj = Tcl_NewObj();
719 
720  if ( !p ) return returnObj;
721 
722  Bstring delist;
723 
724  if ( objc > 3 ) delist = Tcl_GetStringFromObj(objv[3], NULL);
725 
726  p->delete_images(delist);
727 
728  return returnObj;
729 }
730 
731 Tcl_Obj* do_get(Bimage* p, int objc, Tcl_Obj *CONST objv[])
732 {
733  Tcl_Obj* returnObj = Tcl_NewObj();
734 
735  if ( !p ) return returnObj;
736 
737  long i, c;
738  int j(-1), iz(0), n(0);
739  long ix, iy;
740  double x, y;
741  char string[MAXLINELEN] = " ";
742  Bstring datatype_string;
743 
744  Bstring property = Tcl_GetStringFromObj(objv[3], NULL);
745  if ( verbose & VERB_DEBUG )
746  cout << "DEBUG do_get: Property: " << property << " (" << property.length() << ")" << endl;
747 
748  if ( objc > 4 ) {
749  Tcl_GetIntFromObj(NULL, objv[4], &j);
750  if ( j<0 || j>=p->images() ) j = 0;
751  }
752 
753  if ( !p || property.empty() ) {
754  Tcl_SetIntObj(returnObj, 0);
755  } else if ( property == "info" ) {
756  p->information();
758  Tcl_SetIntObj(returnObj, 0);
759  } else if ( property == "filename" ) {
760  Tcl_SetStringObj(returnObj, (char *)p->file_name().c_str(), p->file_name().length());
761  } else if ( property == "label" ) {
762  Tcl_SetStringObj(returnObj, (char *)p->label().c_str(), p->label().length());
763  } else if ( property == "nimages" ) {
764  Tcl_SetIntObj(returnObj, p->images());
765  } else if ( property == "channels" ) {
766  Tcl_SetIntObj(returnObj, p->channels());
767  } else if ( property == "nslices" ) {
768  Tcl_SetIntObj(returnObj, p->sizeZ());
769  } else if ( property == "width" ) {
770  Tcl_SetIntObj(returnObj, p->sizeX());
771  } else if ( property == "height" ) {
772  Tcl_SetIntObj(returnObj, p->sizeY());
773  } else if ( property == "size" ) {
774  snprintf(string, MAXLINELEN, "%ld %ld %ld", p->sizeX(), p->sizeY(), p->sizeZ());
775  Tcl_AppendToObj(returnObj, string, strlen(string));
776  } else if ( property == "center" ) {
777  snprintf(string, MAXLINELEN, "%ld %ld %ld", p->sizeX()/2, p->sizeY()/2, p->sizeZ()/2);
778  Tcl_AppendToObj(returnObj, string, strlen(string));
779  } else if ( property == "origin" ) {
780  if ( j < 0 ) j = 0;
781  snprintf(string, MAXLINELEN, "%g %g %g ", p->image[j].origin()[0], p->image[j].origin()[1], p->image[j].origin()[2]);
782  Tcl_AppendToObj(returnObj, string, strlen(string));
783  } else if ( property == "select" ) {
784  if ( j < 0 ) j = 0;
785  Tcl_SetIntObj(returnObj, p->image[j].select());
786  } else if ( property == "show_image" ) {
787  Tcl_SetIntObj(returnObj, p->show_image());
788  } else if ( property == "show_slice" ) {
789  Tcl_SetIntObj(returnObj, p->show_slice());
790  } else if ( property == "show_scale" ) {
791  Tcl_SetDoubleObj(returnObj, p->show_scale());
792  } else if ( property == "show_min" ) {
793  Tcl_SetDoubleObj(returnObj, p->show_minimum());
794  } else if ( property == "show_max" ) {
795  Tcl_SetDoubleObj(returnObj, p->show_maximum());
796  } else if ( property == "min" ) {
797  if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->minimum());
798  else Tcl_SetDoubleObj(returnObj, p->image[j].minimum());
799  } else if ( property == "max" ) {
800  if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->maximum());
801  else Tcl_SetDoubleObj(returnObj, p->image[j].maximum());
802  } else if ( property == "average" ) {
803  if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->average());
804  else Tcl_SetDoubleObj(returnObj, p->image[j].average());
805  } else if ( property == "standard_deviation" ) {
806  if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->standard_deviation());
807  else Tcl_SetDoubleObj(returnObj, p->image[j].standard_deviation());
808  } else if ( property == "background" ) {
809  if ( j < 0 ) Tcl_SetDoubleObj(returnObj, p->background(long(0)));
810  else Tcl_SetDoubleObj(returnObj, p->image[j].background());
811  } else if ( property == "datatype" ) {
812  datatype_string = p->data_type_string();
813  Tcl_SetStringObj(returnObj, (char *)datatype_string.c_str(), datatype_string.length());
814  } else if ( property == "pixel_size" ) {
815  if ( j < 0 ) {
816  for ( i=0; i<p->images(); ++i ) {
817  snprintf(string, 128, "%g %g %g ", p->image[i].sampling()[0], p->image[i].sampling()[1], p->image[i].sampling()[2]);
818  Tcl_AppendToObj(returnObj, string, strlen(string));
819  }
820  } else {
821  snprintf(string, MAXLINELEN, "%g %g %g ", p->image[j].sampling()[0], p->image[j].sampling()[1], p->image[j].sampling()[2]);
822  Tcl_AppendToObj(returnObj, string, strlen(string));
823  }
824  } else if ( property == "pixel" ) {
825 // cout << p->compound_type() << endl;
826  if ( objc > 4 ) {
827  Tcl_GetDoubleFromObj(NULL, objv[4], &x);
828  ix = (long) x;
829  if ( ix >=0 && ix < p->sizeX() ) {
830  if ( p->compound_type() == TComplex ) {
831  ix -= p->sizeX()/2;
832  if ( ix < 0 ) ix += p->sizeX();
833  }
834  if ( objc > 5 ) {
835  Tcl_GetDoubleFromObj(NULL, objv[5], &y);
836  iy = (long) y;
837  if ( iy >= 0 && iy < p->sizeY() ) {
838  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &iz);
839  if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &n);
840  if ( p->compound_type() == TComplex ) {
841  iy -= p->sizeY()/2;
842  if ( iy < 0 ) iy += p->sizeY();
843  iz -= p->sizeZ()/2;
844  if ( iz < 0 ) iz += p->sizeZ();
845  }
846  i = p->index(0,ix,iy,iz,n);
847  for ( c=0, j=0; c<p->channels(); c++, i++ ) {
848  if ( p->data_type() <= Long )
849  j += snprintf(&string[j], MAXLINELEN, "%.0f ", (*p)[i]);
850  else
851  j += snprintf(&string[j], MAXLINELEN, "%g ", (*p)[i]);
852  }
853  }
854  }
855  }
856  }
857  Tcl_AppendToObj(returnObj, string, strlen(string));
858  } else if ( property == "line" ) {
859  returnObj = do_line(p, objc, objv);
860  } else {
861  cerr << "Error in do_get: Property " << property << " not recognized!" << endl;
862  }
863 
864  return returnObj;
865 }
866 
867 Tcl_Obj* do_line(Bimage* p, int objc, Tcl_Obj *CONST objv[])
868 {
869  Tcl_Obj* returnObj = Tcl_NewObj();
870 
871  if ( !p ) return returnObj;
872 
873  int n(0);
874  long width(1);
875  Vector3<double> start, end;
876 
877  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &start[0]);
878  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &start[1]);
879  if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &start[2]);
880  if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &end[0]);
881  if ( objc > 8 ) Tcl_GetDoubleFromObj(NULL, objv[8], &end[1]);
882  if ( objc > 9 ) Tcl_GetDoubleFromObj(NULL, objv[9], &end[2]);
883  if ( objc > 10 ) Tcl_GetIntFromObj(NULL, objv[10], &n);
884  if ( objc > 11 ) Tcl_GetLongFromObj(NULL, objv[11], &width);
885 
886  char string[128];
887  long i, j, wh(width/2);
888  Vector3<double> vec(end - start), vecp, coor;
889  long len(vec.length() + 1);
890  double value;
891 
892  vec.normalize();
893  vecp = Vector3<double>(vec[1], vec[0], vec[2]);
894 
895  for ( i=0; i<len; i++ ) {
896  coor = start + vec*i;
897  for ( value=0, j=-wh; j<=wh; ++j )
898  value += p->interpolate(coor + vecp*j, n);
899  value /= width;
900  snprintf(string, 128, " %d %g %g %g %g", n, coor[0], coor[1], coor[2], value);
901  Tcl_AppendToObj(returnObj, string, strlen(string));
902  }
903 
904  return returnObj;
905 }
906 
907 
908 int do_set(Bimage* p, int objc, Tcl_Obj *CONST objv[])
909 {
910  if ( !p ) return 0;
911 
912  int i(0), n(1);
913  double ox, oy, oz;
914  double scale(1), smin, smax;
915  char *astring;
916  Vector3<double> sam(1,1,1);
917 
918  Bstring property = Tcl_GetStringFromObj(objv[3], NULL);
919  if ( verbose & VERB_DEBUG )
920  cout << "DEBUG do_set: Property: " << property << " (" << property.length() << ")" << endl;
921 
922  if ( objc < 4 || !p ) return 0;
923 
924  if ( property == "label" ) {
925  astring = Tcl_GetStringFromObj(objv[4], NULL);
926  p->label(astring);
927  } else if ( property == "origin" ) {
928  i = -1;
929  if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &i);
930  if ( verbose & VERB_DEBUG )
931  cout << "DEBUG do_set: setting origin for " << i << endl;
932  if ( i < (int)p->images() ) {
933  if ( objc > 4 ) {
934  Tcl_GetDoubleFromObj(NULL, objv[4], &ox);
935  if ( p->sizeX() < 2 ) ox = 0;
936  }
937  if ( objc > 5 ) {
938  Tcl_GetDoubleFromObj(NULL, objv[5], &oy);
939  if ( p->sizeY() < 2 ) oy = 0;
940  }
941  if ( objc > 6 ) {
942  Tcl_GetDoubleFromObj(NULL, objv[6], &oz);
943  if ( p->sizeZ() < 2 ) oz = 0;
944  }
945  if ( i < 0 ) p->origin(ox, oy, oz);
946  else p->origin(i, ox, oy, oz);
947  if ( verbose & VERB_DEBUG )
948  cout << "DEBUG do_set: origin set: " << p->image->origin() << endl;
949  }
950  } else if ( property == "select" ) {
951  i = -1;
952  n = 1;
953  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &i);
954  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &n);
955  if ( verbose & VERB_DEBUG )
956  cout << "DEBUG do_set: setting selection for " << i << endl;
957  if ( i<0 )
958  for ( i=0; i<p->images(); i++ )
959  p->image[i].select(n);
960  else if ( i < p->images() )
961  p->image[i].select(n);
962  } else if ( property == "show_image" ) {
963  Tcl_GetIntFromObj(NULL, objv[4], &i);
964  p->show_image(i);
965  } else if ( property == "show_slice" ) {
966  Tcl_GetIntFromObj(NULL, objv[4], &i);
967  p->show_slice(i);
968  } else if ( property == "show_scale" ) {
969  Tcl_GetDoubleFromObj(NULL, objv[4], &scale);
970  p->show_scale(scale);
971  } else if ( property == "show_min" ) {
972  Tcl_GetDoubleFromObj(NULL, objv[4], &smin);
973  p->show_minimum(smin);
974  } else if ( property == "show_max" ) {
975  Tcl_GetDoubleFromObj(NULL, objv[4], &smax);
976  p->show_maximum(smax);
977  } else if ( property == "datatype" ) {
978  astring = Tcl_GetStringFromObj(objv[4], NULL);
979  p->change_type(astring);
980  } else if ( property == "pixel_size" ) {
981  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &i);
982  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &sam[0]);
983  if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &sam[1]);
984  if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &sam[2]);
985  if ( i < 0 ) p->sampling(sam);
986  else p->image[i].sampling(sam);
987  } else if ( property == "montage" ) {
988  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &mont.ncol);
989  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &mont.nrow);
990  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &mont.first);
991  if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &mont.skip);
992  if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &mont.pad);
993  if ( objc > 9 ) Tcl_GetDoubleFromObj(NULL, objv[9], &mont.fill);
994  if ( objc > 10 ) Tcl_GetIntFromObj(NULL, objv[10], &mont.flip);
995 // cout << "montage: " << mont.ncol << " x " << mont.nrow << endl;
996  } else {
997  cerr << "Error in do_set: Property " << property << " not recognized!" << endl;
998  }
999 
1000  return 0;
1001 }
1002 
1003 int do_switch(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1004 {
1005  if ( !p ) return -1;
1006 
1007  if ( p->images() > 1 )
1008  p->images_to_slices();
1009  else if ( p->sizeZ() > 1 )
1010  p->slices_to_images();
1011 
1012  p->statistics();
1013 
1014  return 1;
1015 }
1016 
1017 int do_fix_type(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1018 {
1019  if ( !p ) return -1;
1020 
1021  p->fix_type();
1022 
1023  p->statistics();
1024 
1025  return 1;
1026 }
1027 
1028 Tcl_Obj* do_stats(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1029 {
1030  Tcl_Obj* returnObj = Tcl_NewObj();
1031 
1032  if ( !p ) return returnObj;
1033 
1034  if ( objc < 4 ) return returnObj;
1035 
1036  int img_num(-1), type(0), nvert(0), i, k;
1037  double sum(0), avg(0), std(0);
1038  Vector3<double> start, end;
1039 
1040  Tcl_GetIntFromObj(NULL, objv[3], &img_num);
1041 
1042  Tcl_GetIntFromObj(NULL, objv[4], &type);
1043 
1044  if ( type < 1 || type > 3 ) return returnObj;
1045 
1046  Bstring alist = Tcl_GetStringFromObj(objv[5], NULL);
1047  vector<double> v = alist.split_into_doubles(" ");
1048  long n(v.size());
1049  Vector3<double>* poly = NULL;
1050 
1051  switch ( type ) {
1052  case 1:
1053  case 2: if ( n > 5 ) {
1054  start = Vector3<long>((long)v[0], (long)v[1], (long)v[2]);
1055  end = Vector3<long>((long)v[3], (long)v[4], (long)v[5]);
1056  n = p->stats_in_shape(img_num, type, start, end, avg, std);
1057  }
1058  break;
1059  case 3: nvert = n/3;
1060  cout << "Number of vertices = " << nvert << endl;
1061  if ( nvert > 2 ) {
1062  poly = new Vector3<double>[nvert];
1063  for ( i=k=0; i<nvert; i++, k+=3 ) {
1064  poly[i] = Vector3<double>(v[k], v[k+1], v[k+2]);
1065  cout << poly[i][0] << " " << poly[i][1] << " " << poly[i][2] << endl;
1066  }
1067  n = p->stats_in_poly(img_num, nvert, poly, avg, std);
1068  delete[] poly;
1069  }
1070  break;
1071  default:
1072  break;
1073  }
1074 
1075  if ( poly ) delete[] poly;
1076 
1077  sum = n*avg;
1078 
1079  char string[MAXLINELEN];
1080  snprintf(string, MAXLINELEN, "%ld %g %g %g", n, sum, avg, std);
1081  Tcl_AppendToObj(returnObj, string, strlen(string));
1082 
1083  return returnObj;
1084 }
1085 
1086 int do_center(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1087 {
1088  if ( !p ) return 0;
1089 
1090  p->center_wrap();
1091 
1092  return 1;
1093 }
1094 
1095 int do_zero_origin(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1096 {
1097  if ( !p ) return 0;
1098 
1099  p->zero_origin();
1100 
1101  return 1;
1102 }
1103 
1104 int do_extract(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1105 {
1106  if ( !p ) return 0;
1107 
1108  if ( objc < 4 ) return 0;
1109 
1110  int img_num(-1);
1111  Vector3<double> start;
1112  Vector3<long> size(p->size());
1113 
1114  Bstring file_name = Tcl_GetStringFromObj(objv[3], NULL);
1115  Tcl_GetIntFromObj(NULL, objv[4], &img_num);
1116 
1117  if ( objc > 5 ) {
1118  Bstring alist = Tcl_GetStringFromObj(objv[5], NULL);
1119  vector<double> v = alist.split_into_doubles(" ");
1120  if ( v.size() < 6 ) return 0;
1121  if ( v[0] > v[3] ) swap(v[0], v[3]);
1122  if ( v[1] > v[4] ) swap(v[1], v[4]);
1123  if ( v[2] > v[5] ) swap(v[2], v[5]);
1124  start = Vector3<float>(v[0], v[1], v[2]);
1125  size = Vector3<int>((int) (v[3]-v[0]+1), (int) (v[4]-v[1]+1), (int) (v[5]-v[2]+1));
1126  }
1127 
1128  start = start.max(0);
1129  if ( size[0] < 1 || size[0] >= p->sizeX() ) size[0] = p->sizeX();
1130  if ( size[1] < 1 || size[1] >= p->sizeY() ) size[1] = p->sizeY();
1131  if ( size[2] < 1 || size[2] >= p->sizeZ() ) size[2] = p->sizeZ();
1132 
1133  Bimage* pex = p->extract(img_num, start, size);
1134 
1135  Vector3<double> origin(p->image[img_num].origin());
1136 
1137  origin -= start;
1138 
1139  pex->origin(origin);
1140 
1141  write_img(file_name, pex, 0);
1142 
1143  delete pex;
1144 
1145  return 1;
1146 }
1147 
1148 int do_crop(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1149 {
1150  if ( !p ) return 0;
1151 
1152  if ( objc < 4 ) return 0;
1153 
1154 // int img_num(-1);
1155 
1156  Bstring alist = Tcl_GetStringFromObj(objv[4], NULL);
1157  vector<long> v = alist.split_into_integers(" ");
1158 
1159  if ( v.size() < 6 ) return 0;
1160 
1161  Vector3<long> start = Vector3<long>(v[0], v[1], v[2]);
1162  Vector3<long> end = Vector3<long>(v[3], v[4], v[5]);
1163 
1164  if ( start[0] > end[0] ) swap(start[0], end[0]);
1165  if ( start[1] > end[1] ) swap(start[1], end[1]);
1166  if ( start[2] > end[2] ) swap(start[2], end[2]);
1167 
1168  start = start.max(0);
1169  if ( end[0] >= p->sizeX() ) end[0] = p->sizeX() - 1;
1170  if ( end[1] >= p->sizeY() ) end[1] = p->sizeY() - 1;
1171  if ( end[2] >= p->sizeZ() ) end[2] = p->sizeZ() - 1;
1172 
1173  Vector3<long> newsize(1,1,1);
1174 
1175  newsize += end - start;
1176 
1177  Vector3<long> translate = -start;
1178 
1179  return p->resize(newsize, translate, 0, 0);
1180 }
1181 
1182 int do_pad(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1183 {
1184  if ( !p ) return 0;
1185 
1186  if ( objc < 4 ) return 0;
1187 
1188  int filltype(2);
1189  double fill(0);
1190 
1191  Vector3<int> size;
1192  Vector3<int> translate;
1193 
1194  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &translate[0]);
1195  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &translate[1]);
1196  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &translate[2]);
1197  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &size[0]);
1198  if ( objc > 7 ) Tcl_GetIntFromObj(NULL, objv[7], &size[1]);
1199  if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &size[2]);
1200  if ( objc > 9 ) Tcl_GetIntFromObj(NULL, objv[9], &filltype);
1201  if ( objc > 10 ) Tcl_GetDoubleFromObj(NULL, objv[10], &fill);
1202 
1203 // size += translate + p->size();
1204 
1205  return p->resize(size, translate, filltype, fill);
1206 }
1207 
1208 int do_invert(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1209 {
1210  if ( !p ) return 0;
1211 
1212  p->invert();
1213 
1214  return 1;
1215 }
1216 
1217 int do_truncate(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1218 {
1219  if ( !p ) return 0;
1220 
1221  double min, max, tol = 0.001*(p->maximum() - p->minimum());
1222 
1223  if ( objc > 4 ) {
1224  Tcl_GetDoubleFromObj(NULL, objv[3], &min);
1225  Tcl_GetDoubleFromObj(NULL, objv[4], &max);
1226  if ( fabs(min - p->minimum()) > tol || fabs(max - p->maximum()) > tol ) {
1227  p->truncate_to_min_max(min, max);
1228  }
1229  }
1230 
1231  return 0;
1232 }
1233 
1234 int do_rescale(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1235 {
1236  if ( !p ) return 0;
1237 
1238  double avg, std, tol = 0.001*(p->maximum() - p->minimum());
1239 
1240  if ( objc > 4 ) {
1241  Tcl_GetDoubleFromObj(NULL, objv[3], &avg);
1242  Tcl_GetDoubleFromObj(NULL, objv[4], &std);
1243  if ( ( std > 0 ) && ( fabs(avg - p->average()) > tol || fabs(std - p->standard_deviation()) > tol ) ) {
1244 // img_rescale_to_avg_std(p, avg, std);
1245  p->rescale_to_avg_std(avg, std);
1246  }
1247  }
1248 
1249  return 0;
1250 }
1251 
1252 int do_reslice(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1253 {
1254  if ( !p ) return 0;
1255 
1256  Bstring order;
1257 
1258  if ( objc > 3 ) {
1259  order = Tcl_GetStringFromObj(objv[3], NULL);
1260  p->reslice(order);
1261  }
1262 
1263  return 0;
1264 }
1265 
1266 int do_rotate(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1267 {
1268  if ( !p ) return 0;
1269 
1270  Euler euler;
1271 
1272  if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &euler[0]);
1273  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &euler[1]);
1274  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &euler[2]);
1275 
1276  euler[0] *= M_PI/180.0;
1277  euler[1] *= M_PI/180.0;
1278  euler[2] *= M_PI/180.0;
1279 
1280  if ( euler.psi() || euler.theta() || euler.phi() )
1281 // img_rotate(p, euler);
1282 // p->rotate(euler.view());
1283  p->rotate(euler.matrix());
1284 
1285  return 0;
1286 }
1287 
1288 int do_bin(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1289 {
1290  if ( !p ) return 0;
1291 
1292  Vector3<int> bin(1,1,1);
1293 
1294  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &bin[0]);
1295  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &bin[1]);
1296  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &bin[2]);
1297 
1298  if ( bin[0]*bin[1]*bin[2] > 1 ) p->bin(bin);
1299 
1300  return 0;
1301 }
1302 
1303 int do_average(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1304 {
1305  if ( !p ) return 0;
1306 
1307  Vector3<int> k(1,1,1);
1308 
1309  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k[0]);
1310  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &k[1]);
1311  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &k[2]);
1312 
1313  if ( k.volume() > 1 ) p->filter_average(k);
1314 
1315  return 0;
1316 }
1317 
1318 int do_variance(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1319 {
1320  if ( !p ) return 0;
1321 
1322  int k(1);
1323 
1324  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k);
1325 
1326  if ( k > 1 ) p->variance(k);
1327 
1328  return 0;
1329 }
1330 
1331 int do_normalize(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1332 {
1333  if ( !p ) return 0;
1334 
1335  Vector3<int> k(1,1,1);
1336 
1337  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k[0]);
1338  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &k[1]);
1339  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &k[2]);
1340 
1341  if ( k.volume() > 1 ) p->normalize_local(k);
1342 
1343  return 0;
1344 }
1345 
1346 int do_gaussian(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1347 {
1348  if ( !p ) return 0;
1349 
1350  int k(3);
1351  double sigma(1);
1352 
1353  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &k);
1354  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &sigma);
1355 
1356  if ( k > 3 ) p->filter_gaussian(k, sigma);
1357 
1358  return 0;
1359 }
1360 
1361 Tcl_Obj* do_histogram(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1362 {
1363  Tcl_Obj* returnObj = Tcl_NewObj();
1364 
1365  if ( !p ) return returnObj;
1366 
1367  int i, bins(200);
1368 
1369  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &bins);
1370 
1371  double scale, offset;
1372  vector<long> hist = p->histogram(bins, scale, offset);
1373  char string[128];
1374  for ( i=0; i<bins*p->channels(); i++ ) {
1375  snprintf(string, 128, "%ld ", hist[i]);
1376  Tcl_AppendToObj(returnObj, string, strlen(string));
1377  }
1378 
1379 // delete[] hist;
1380 
1381  return returnObj;
1382 }
1383 
1384 Tcl_Obj* do_radial_average(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1385 {
1386  int wrap(0);
1387  double ox(0), oy(0), oz(0), angle(0);
1388  char* maskname = NULL;
1389 
1390  Tcl_Obj* returnObj = Tcl_NewObj();
1391 
1392  if ( !p ) return returnObj;
1393 
1394  if ( p->image->origin()[0] <= 0 || p->image->origin()[0] >= p->sizeX() ) ox = p->sizeX()/2;
1395  if ( p->image->origin()[1] <= 0 || p->image->origin()[1] >= p->sizeY() ) oy = p->sizeY()/2;
1396  if ( p->image->origin()[2] <= 0 || p->image->origin()[2] >= p->sizeZ() ) oz = p->sizeZ()/2;
1397 
1398  if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &ox);
1399  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &oy);
1400  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &oz);
1401 
1402  p->origin(ox, oy, oz);
1403 
1404  if ( objc > 6 ) Tcl_GetDoubleFromObj(NULL, objv[6], &angle);
1405 
1406  if ( objc > 7 ) maskname = Tcl_GetStringFromObj(objv[7], NULL);
1407 
1408  if ( objc > 8 ) Tcl_GetIntFromObj(NULL, objv[8], &wrap);
1409 
1410  angle *= M_PI/180.0;
1411 
1412  Bimage* pmask = NULL;
1413  if ( maskname && strlen(maskname) > 2 ) pmask = read_img(maskname, 1, -1);
1414 
1415  long i, len(p->sizeX()/2);
1416  char string[128];
1417  Bimage* prad = p->radial(0, len, 1, pmask, wrap);
1418 
1419  for ( i=0; i<prad->sizeX(); i++ ) {
1420  if ( !isfinite((*prad)[i]) ) cerr << "Warning: Point " << i << " is a NaN!" << endl;
1421  snprintf(string, 128, " %g", (*prad)[i]);
1422  Tcl_AppendToObj(returnObj, string, strlen(string));
1423  }
1424 
1425  delete prad;
1426 
1427  Vector3<double> end(cos(angle)*len, sin(angle)*len, 0);
1428  prad = p->extract_line(0, p->image->origin(), end, 5);
1429 
1430  for ( i=0; i<len; i++ ) {
1431  if ( !isfinite((*prad)[i]) ) cerr << "Warning: Point " << i << " is a NaN!" << endl;
1432  snprintf(string, 128, " %g", (*prad)[i]);
1433  Tcl_AppendToObj(returnObj, string, strlen(string));
1434  }
1435 
1436  delete prad;
1437 
1438  end = Vector3<double>(sin(angle)*len, cos(angle)*len, 0);
1439  prad = p->extract_line(0, p->image->origin(), end, 5);
1440 
1441  for ( i=0; i<len; i++ ) {
1442  if ( !isfinite((*prad)[i]) ) cerr << "Warning: Point " << i << " is a NaN!" << endl;
1443  snprintf(string, 128, " %g", (*prad)[i]);
1444  Tcl_AppendToObj(returnObj, string, strlen(string));
1445 // cout << i << tab << (*prad)[i] << endl;
1446  }
1447 
1448  delete prad;
1449  delete pmask;
1450  pmask = NULL;
1451 
1452  return returnObj;
1453 }
1454 
1455 int do_diffraction_origin(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1456 {
1457  if ( !p ) return 0;
1458 
1459  double ox(0), oy(0), oz =0;
1460  char* maskname = NULL;
1461 
1462  if ( objc > 3 ) Tcl_GetDoubleFromObj(NULL, objv[3], &ox);
1463 
1464  if ( objc > 4 ) Tcl_GetDoubleFromObj(NULL, objv[4], &oy);
1465 
1466  if ( objc > 5 ) Tcl_GetDoubleFromObj(NULL, objv[5], &oz);
1467 
1468  if ( objc > 7 ) maskname = Tcl_GetStringFromObj(objv[7], NULL);
1469 
1470  if ( ox > 0 ) p->origin(ox, oy, oz);
1471 
1472  Bimage* pmask = NULL;
1473  if ( maskname && strlen(maskname) > 2 ) pmask = read_img(maskname, 1, -1);
1474 
1475  double hires(p->sampling(0)[0]*10), lores(p->sampling(0)[0]*1000);
1476  double radius(p->sizeX()/4.0), sigma(0);
1477  p->find_center(pmask, hires, lores, radius, sigma, 1);
1478 
1479  delete pmask;
1480 
1481  return 1;
1482 }
1483 
1484 int do_fft(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1485 {
1486  if ( !p ) return 0;
1487 
1488  int dir(-1);
1489  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &dir);
1490 
1491  if ( dir > 0 ) {
1492  if ( p->compound_type() == TComplex ) p->fft(FFTW_BACKWARD);
1493  } else if ( dir < 0 ) {
1494  if ( p->compound_type() == TSimple ) p->fft(FFTW_FORWARD);
1495  }
1496 
1497  p->statistics();
1498 
1499  return 1;
1500 }
1501 
1502 Bimage* do_powerspec(Bimage* p, int objc, Tcl_Obj *CONST objv[])
1503 {
1504  if ( !p ) return 0;
1505 
1506  int flags(4);
1507  double tilt_axis(0), tilt_angle(0), tilt_offset(0);
1508  double defocus(0), Cs(2), volt(300);
1509  Vector3<int> tile_size(p->size());
1510 
1511  if ( objc > 3 ) Tcl_GetIntFromObj(NULL, objv[3], &flags);
1512  if ( objc > 4 ) Tcl_GetIntFromObj(NULL, objv[4], &tile_size[0]);
1513  if ( objc > 5 ) Tcl_GetIntFromObj(NULL, objv[5], &tile_size[1]);
1514  if ( objc > 6 ) Tcl_GetIntFromObj(NULL, objv[6], &tile_size[2]);
1515  if ( objc > 7 ) Tcl_GetDoubleFromObj(NULL, objv[7], &tilt_axis);
1516  if ( objc > 8 ) Tcl_GetDoubleFromObj(NULL, objv[8], &tilt_angle);
1517  if ( objc > 9 ) Tcl_GetDoubleFromObj(NULL, objv[9], &tilt_offset);
1518  if ( objc > 10 ) Tcl_GetDoubleFromObj(NULL, objv[10], &defocus);
1519  if ( objc > 11 ) Tcl_GetDoubleFromObj(NULL, objv[11], &Cs);
1520  if ( objc > 12 ) Tcl_GetDoubleFromObj(NULL, objv[12], &volt);
1521 
1522  Bimage* ps = NULL;
1523 
1524  if ( objc > 5 ) {
1525  flags |= 2;
1526  tilt_axis *= M_PI/180.0;
1527  tilt_angle *= M_PI/180.0;
1528  if ( defocus < 100 ) defocus *= 1e4;
1529  if ( Cs < 100 ) Cs *= 1e7;
1530  if ( volt < 10000 ) volt *= 1000;
1531  double lamda(volt);
1532  double iCL2(1.0/(Cs*lamda*lamda));
1533  ps = p->powerspectrum_tiled_and_tilted(tile_size, tilt_axis,
1534  tilt_angle, tilt_offset, defocus, iCL2, flags);
1535  } else
1536  p->power_spectrum(flags);
1537 
1538  return ps;
1539 }
Bsub_image::average
double average()
Definition: Bimage.h:119
do_histogram
Tcl_Obj * do_histogram(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1361
Bmontage::fill
double fill
Definition: tcltk_bimage.cpp:30
MAXLINELEN
#define MAXLINELEN
Definition: utilities.h:45
do_rescale
int do_rescale(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1234
do_reslice
int do_reslice(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1252
Bimage::sizeZ
void sizeZ(long nz)
Definition: Bimage.h:392
Bimage::filter_gaussian
int filter_gaussian(long kernel_size, double sigma)
Applies a gaussian filter to an image.
Definition: Bimage_filter.cpp:324
imglist
Bimage * imglist
Definition: bshow.cpp:32
do_line
Tcl_Obj * do_line(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:867
VERB_DEBUG
#define VERB_DEBUG
Definition: utilities.h:116
do_stats
Tcl_Obj * do_stats(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1028
Bimage::reslice
void reslice(const char *order)
Definition: Bimage.h:717
Bstring
Definition: Bstring.h:29
Bimage::next
Bimage * next
Definition: Bimage.h:179
Bsub_image::select
long select()
Definition: Bimage.h:167
Bimage::show_image
long show_image()
Definition: Bimage.h:559
Bsub_image::standard_deviation
double standard_deviation()
Definition: Bimage.h:120
Bimage::find_center
int find_center(Bimage *pmask, double hires, double lores, double radius, double sigma, int refine_flag)
Finds the center of mass of an image by cross-correlation with its inverse.
Definition: Bimage_correlate.cpp:1235
do_magnify
int do_magnify(Bimage *p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:610
Euler::theta
double theta()
Definition: Euler.h:57
Bimage::variance
int variance(long kernel_size, int flag=0)
Calculates the local variance within the given kernel.
Definition: Bimage_stats.cpp:625
Vector3< int >
Bimage::sizeX
void sizeX(long nx)
Definition: Bimage.h:390
Bimage::resize_copy
Bimage * resize_copy(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
Definition: Bimage_resize.cpp:124
mont
struct Bmontage mont
Euler::psi
double psi()
Definition: Euler.h:56
Bimage::information
int information()
Prints out header information for an image.
Definition: Bimage.cpp:2508
Bimage::radial
Bimage * radial(long minrad, long maxrad, double rad_step=1, int wrap=0)
Calculates the radial average of an image.
Definition: Bimage_polar.cpp:33
TComplex
@ TComplex
Definition: Bimage.h:60
Bimage::background
double background(long nn)
Definition: Bimage.h:549
FILL_USER
#define FILL_USER
Definition: utilities.h:176
Bimage::size
Vector3< long > size() const
Definition: Bimage.h:386
do_radial_average
Tcl_Obj * do_radial_average(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1384
Bimage::zero_origin
int zero_origin()
Shifts the origins to zero with wrapping.
Definition: Bimage_transform.cpp:722
Bimage::image
Bsub_image * image
Definition: Bimage.h:202
Bimage::maximum
double maximum()
Definition: Bimage.h:542
Bmontage::nrow
int nrow
Definition: tcltk_bimage.cpp:28
do_fft
int do_fft(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1484
Bimage::standard_deviation
double standard_deviation()
Definition: Bimage.h:544
Bstring::c_str
const char * c_str()
Definition: Bstring.h:70
Bimage::extract_slice
Bimage * extract_slice(long nz)
Extracts a given slice or slices from an image.
Definition: Bimage_extract.cpp:1036
Bimage::delete_images
long delete_images(Bstring list, int retain=0)
Retains or deletes sub-images from a multi-image structure.
Definition: Bimage.cpp:2156
Bimage::images_to_slices
int images_to_slices()
Changes the 2D images to slices in a 3D image.
Definition: Bimage.cpp:2115
Bimage::images
long images()
Definition: Bimage.h:504
Bsub_image::background
double background()
Definition: Bimage.h:125
Bsub_image::maximum
double maximum()
Definition: Bimage.h:118
do_set
int do_set(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:908
do_crop
int do_crop(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1148
read_img
Bimage * read_img(char *filename, int readdata, int img_select)
General driver function to read multiple image formats.
Definition: rwimg.cpp:77
Bsub_image::origin
void origin(double x, double y, double z)
Definition: Bimage.h:136
TSimple
@ TSimple
Definition: Bimage.h:59
write_img
int write_img(const char *filename, Bimage *p, int compression)
General driver function to write multiple image formats.
Definition: rwimg.cpp:281
do_powerspec
Bimage * do_powerspec(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1502
Bimage::sizeY
void sizeY(long ny)
Definition: Bimage.h:391
Bimage::slices_to_images
int slices_to_images()
Changes the slices in a 3D image into a set of 2D images.
Definition: Bimage.cpp:2074
do_average
int do_average(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1303
Bimage::fft
int fft()
Definition: Bimage.h:830
do_variance
int do_variance(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1318
Bmontage::flip
int flip
Definition: tcltk_bimage.cpp:29
Bimage::rotate
int rotate()
Rotates an image using parameters defined in the image in place.
Definition: Bimage_transform.cpp:255
Bimage::normalize_local
int normalize_local(long kernel_size)
Normalizes by subtracting local average and dividing by local standard deviation.
Definition: Bimage_rescale.cpp:608
Bimage::power_spectrum
int power_spectrum(int flags=0)
Calculates a power spectrum.
Definition: Bimage_powerspectrum.cpp:48
Bimage::stats_in_poly
long stats_in_poly(long nn, int nvert, Vector3< double > *poly, double &vavg, double &vstd)
Calculates the statistics for an image within the given polyhedron.
Definition: Bimage_stats.cpp:419
mg_ctf.h
Functions for CTF (contrast transfer function) processing.
Bimage::extract_show
Bimage * extract_show(int aflag)
Converts a slice from an image to a 2D plane for display.
Definition: Bimage_extract.cpp:816
Bimage
General image parameter class.
Definition: Bimage.h:177
Bimage::compound_type
CompoundType compound_type()
Definition: Bimage.h:364
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:1371
timer.h
Utilities for timing functions.
Bimage::data_type_string
Bstring data_type_string()
Get the string representation of a datatype.
Definition: Bimage.cpp:1689
Bmontage::skip
int skip
Definition: tcltk_bimage.cpp:29
Vector3.h
Class for 3-value vectors.
Bstring::split_into_doubles
vector< double > split_into_doubles(const Bstring &delim)
Definition: Bstring.cpp:673
Bimage::fix_type
void fix_type()
Determines the replacement data type.
Definition: Bimage.cpp:1740
Bmontage
Definition: tcltk_bimage.cpp:27
image_processing
int image_processing(Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:155
VERB_TIME
#define VERB_TIME
Definition: utilities.h:114
do_center
int do_center(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1086
Bimage::truncate_to_min_max
int truncate_to_min_max(double minim, double maxim)
Truncates image data to a given minimum and maximum.
Definition: Bimage_rescale.cpp:331
Bimage::center_wrap
int center_wrap()
Centers an image with wrapping.
Definition: Bimage_transform.cpp:708
Bimage::extract_magnify
Bimage * extract_magnify(long nn, Vector3< long > center, Vector3< long > ext_size, double scale)
Extracts a region from an image to magnify.
Definition: Bimage_extract.cpp:872
Euler::phi
double phi()
Definition: Euler.h:58
Bimage::montage
Bimage * montage(int first, int cols, int rows, int skip=0, int flipy=0)
Rearranges an image into a montage of 2D slices for display.
Definition: Bimage_montage.cpp:49
Bimage::file_name
void file_name(string s)
Definition: Bimage.h:245
timer_start
double timer_start()
Starts timer and prints the time.
Definition: timer.cpp:61
Bimage::data_type
DataType data_type()
Definition: Bimage.h:362
do_get
Tcl_Obj * do_get(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:731
M_PI
#define M_PI
Definition: utilities.h:63
utilities.h
Header file for general utilities.
Long
@ Long
Definition: utilities.h:160
Bimage::interpolate
double interpolate(long cc, double xx, double yy=0, double zz=0, long nn=0, double fill=0) const
Interpolates using a given location.
Definition: Bimage.cpp:1414
do_normalize
int do_normalize(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1331
Bstring::length
long length() const
Definition: Bstring.cpp:263
isfinite
bool isfinite(complex< T > &value)
timer_report
double timer_report(double lasttime)
Reports the time elapsed since a given time.
Definition: timer.cpp:76
Bimage::origin
void origin(double ox, double oy, double oz)
Definition: Bimage.h:570
do_template
int do_template(Bimage *p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:648
Bimage::change_type
void change_type(char letter)
Get the data type indicated by a single letter code.
Definition: Bimage.cpp:1765
Bimage::index
long index(long nx, long ny) const
Definition: Bimage.h:396
Vector3::volume
double volume()
Definition: Vector3.h:237
rwimg.h
Header file for 2D and 3D image I/O.
Bimage::extract_line
Bimage * extract_line(long nn, Vector3< double > start, Vector3< double > end, long width)
Extracts a line from an image into a new image.
Definition: Bimage_extract.cpp:505
do_bin
int do_bin(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1288
verbose
int verbose
do_delete
Tcl_Obj * do_delete(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:716
do_switch
int do_switch(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1003
do_diffraction_origin
int do_diffraction_origin(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1455
Bimage::filter_average
int filter_average(long kernel_size)
Applies an averaging filter to an image.
Definition: Bimage_filter.cpp:207
Bimage::extract
Bimage * extract(long nn)
Extracts one sub-image into new image structure.
Definition: Bimage_extract.cpp:21
do_invert
int do_invert(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1208
Bsub_image::sampling
void sampling(double x, double y, double z)
Definition: Bimage.h:127
linked_list.h
Header file for generalized linked list functions.
Bimage::powerspectrum_tiled_and_tilted
Bimage * powerspectrum_tiled_and_tilted(Vector3< long > tile_size, double tilt_axis, double tilt_angle, double tilt_offset, double defocus, double iCL2, int flags=0)
Prepares a tiled powerspectrum from a tilted image for determining CTF parameters.
Definition: Bimage_powerspectrum.cpp:356
Bimage::show_minimum
double show_minimum()
Definition: Bimage.h:565
do_extract
int do_extract(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1104
Bimage::subimage_information
int subimage_information()
Prints out header information for all sub-images.
Definition: Bimage.cpp:2571
Bimage::invert
void invert()
Inverts the data in the image.
Definition: Bimage.cpp:3111
Bimage::data_pointer
unsigned char * data_pointer()
Definition: Bimage.h:284
Bimage::minimum
double minimum()
Definition: Bimage.h:541
Euler::matrix
Matrix3 matrix()
Definition: Euler.h:67
Bmontage::first
int first
Definition: tcltk_bimage.cpp:29
Bimage::sampling
void sampling(long nn, Vector3< double > u)
Definition: Bimage.h:514
do_show
int do_show(Bimage *p, Tcl_Interp *interp, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:516
image_render
int image_render(Bimage *p, long i, Tcl_Interp *interp, Bstring &photoName)
Definition: tcltk_bimage.cpp:444
do_rotate
int do_rotate(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1266
do_fix_type
int do_fix_type(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1017
command
string command
Definition: utilities.cpp:20
Bimage::show_maximum
double show_maximum()
Definition: Bimage.h:566
Euler.h
Euler object.
do_zero_origin
int do_zero_origin(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1095
Bmontage::ncol
int ncol
Definition: tcltk_bimage.cpp:28
do_pad
int do_pad(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1182
Bimage::identifier
void identifier(Bstring s)
Definition: Bimage.h:231
Bimage::channels
long channels()
Definition: Bimage.h:384
Bsub_image::minimum
double minimum()
Definition: Bimage.h:117
Euler
Definition: Euler.h:28
replace_item
char * replace_item(char **list, char *item, char *new_item)
Finds the given item and replaces it with the new item.
Definition: linked_list.cpp:152
Bimage::histogram
vector< long > histogram(long bins, double &scale, double &offset)
Calculates the histogram of an image.
Definition: Bimage_histogram.cpp:32
Bimage::show_scale
double show_scale()
Definition: Bimage.h:563
Bmontage::pad
int pad
Definition: tcltk_bimage.cpp:29
Bimage::statistics
long statistics()
Calculates the statistics for an image.
Definition: Bimage_stats.cpp:22
Bstring::split_into_integers
vector< long > split_into_integers(const Bstring &delim)
Definition: Bstring.cpp:657
do_montage
Bimage * do_montage(Bimage *p)
Definition: tcltk_bimage.cpp:694
Bimage::resize
int resize(Vector3< long > nusize, Vector3< long > translate, int fill_type=0, double fill=0)
Resizes without interpolation or rescaling.
Definition: Bimage_resize.cpp:28
imgtemp
Bimage * imgtemp
Definition: bshow.cpp:36
Bimage::stats_in_shape
long stats_in_shape(long nn, int type, Vector3< long > start, Vector3< long > end, double &vavg, double &vstd)
Calculates the statistics for an image within the given box.
Definition: Bimage_stats.cpp:282
Bimage::label
void label(string s)
Definition: Bimage.h:250
Bimage::show_slice
long show_slice()
Definition: Bimage.h:561
do_truncate
int do_truncate(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1217
Bimage::rescale_to_avg_std
int rescale_to_avg_std(double nuavg, double nustd)
Rescales the image data to a given average and standard deviation.
Definition: Bimage_rescale.cpp:163
do_gaussian
int do_gaussian(Bimage *p, int objc, Tcl_Obj *CONST objv[])
Definition: tcltk_bimage.cpp:1346
Vector3::max
Type max()
Definition: Vector3.h:175