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