~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina6/tina-tools/tinatool/tlbase/tlbaseImc_tool.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /**********
  2  * 
  3  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
  4  * University of Manchester, UK.  All rights reserved.
  5  * 
  6  * Redistribution and use in source and binary forms, with or without modification, 
  7  * are permitted provided that the following conditions are met:
  8  * 
  9  *   . Redistributions of source code must retain the above copyright notice, 
 10  *     this list of conditions and the following disclaimer.
 11  *    
 12  *   . Redistributions in binary form must reproduce the above copyright notice,
 13  *     this list of conditions and the following disclaimer in the documentation 
 14  *     and/or other materials provided with the distribution.
 15  * 
 16  *   . Neither the name of the University of Manchester nor the names of its
 17  *     contributors may be used to endorse or promote products derived from this 
 18  *     software without specific prior written permission.
 19  * 
 20  * 
 21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 22  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 25  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 26  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 27  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 28  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 29  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 30  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 31  * POSSIBILITY OF SUCH DAMAGE.
 32  *
 33  **********
 34  * 
 35  * Program :    TINA
 36  * File    :  $Source: tlbaseImc_tool.c $
 37  * Date    :  $Date: 2012/07/03 11:00 $
 38  * Version :  $Revision: 1.9 $
 39  *
 40  * Author  : Legacy TINA modified NAT/HR
 41  *
 42  * Notes : imc_tool.c
 43  *
 44  *********
 45 */
 46 
 47 
 48 #if HAVE_CONFIG_H
 49 #include <config.h>
 50 #endif
 51 
 52 #include <stdio.h>
 53 #include <math.h>
 54 
 55 #include <tina/sys/sysDef.h>
 56 #include <tina/sys/sysPro.h>
 57 #include <tina/geometry/geomPro.h>
 58 #include <tina/image/imgDef.h>
 59 #include <tina/image/imgPro.h>
 60 #include <tinatool/wdgts/wdgtsDef.h>
 61 #include <tinatool/wdgts/wdgtsPro.h>
 62 #include <tinatool/draw/drawDef.h>
 63 #include <tinatool/draw/drawPro.h>
 64 #include <tinatool/tlbase/tlbase_InfrDef.h>
 65 #include <tinatool/tlbase/tlbase_InfrPro.h>
 66 #include <tinatool/tlbase/tlbaseImc_imc.h>
 67 #include <tinatool/tlbase/tlbaseImc_crt_tool.h>
 68 #include <tinatool/tlbase/tlbaseImc_graph.h>
 69 #include <tinatool/tlbase/tlbaseImc_view.h>
 70 #include <tinatool/tlbase/tlbaseImc_tool.h>  /* HR */
 71 
 72 
 73 static int connect = 2;
 74 static int sx = 0, sy = 0;
 75 static int lr = 0, ud = 0;
 76 static double scale = 255.0, sigma = 1.0;
 77 static double thresh = 128.0, constant = 1.0;
 78 static double range = 5.0;
 79 static int old_connect = 2;
 80 static int old_sx = 0, old_sy = 0;
 81 static int old_lr = 0, old_ud = 0;
 82 static double old_scale = 255.0, old_sigma = 1.0;
 83 static double old_thresh = 128.0, old_constant = 1.0;
 84 static double old_range = 5.0;
 85 static void *psx, *psy, *plr, *pud, *pcon;
 86 static void *pth,*psc,*psi,*pac,*pco,*pra;
 87 
 88 void im_free();
 89 extern Tv *imcalc_tv_get();
 90 extern Tv *imcal2_tv_get();
 91 extern Tv *imcmem_tv_get();
 92 extern Tv *imcalc_tv_make();
 93 extern Tv *imcal2_tv_make();
 94 extern Tv *imcmem_tv_make();
 95 extern Tv *imcalc_graph_tv_make();
 96 extern void imcalc_reg_set(Imrect *im,int type);
 97 extern Imrect *imcalc_reg_get(void);
 98 extern void imcalc_xy_norm(double constant, double sigma, double thresh);
 99 static void *image_choice=NULL;
100 
101 
102 /********** Support functions **********/
103 
104 void image_choice_reset(void)
105 {
106     int vtype;
107     Imrect *im;
108     int type;
109 
110     if (im = (Imrect *)stack_inspect(&type))
111     {
112 
113         vtype = im->vtype;
114         switch (vtype)
115         {
116         case char_v:
117         case uchar_v:
118             tw_choice_reset(image_choice, 1);
119             break;
120         case short_v:
121         case ushort_v:
122             tw_choice_reset(image_choice, 2);
123             break;
124         case uint_v:
125         case int_v:
126         case float_v:
127             tw_choice_reset(image_choice, 3);
128             break;
129         case complex_v:
130             tw_choice_reset(image_choice, 4);
131             break;
132         case ptr_v:
133             tw_choice_reset(image_choice, 5);
134             break;
135         }
136 /*
137         if (imcalc_tv_get()!=NULL)
138             tv_set_roi(imcalc_tv_get(),im->region);
139 */
140     }
141 }
142 
143 static void tv_proc(void)
144 {
145     imcalc_tv_set(imcalc_tv_make());
146     imcal2_tv_set(imcal2_tv_make());
147     imcmem_tv_set(imcmem_tv_make());
148     imcalc_graph_tv_set(imcalc_graph_tv_make());
149     tv_set_next(imcalc_tv_get());
150 }
151 
152 /********** Callback functions **********/
153 
154 static void clear_all_proc(void)
155 {
156     extern void imcalc_undo(Imrect * im1 , Imrect * im2 , Bool f);
157     stack_clear();
158     imcalc_undo(NULL,NULL,false);
159     tv_erase(imcalc_tv_get());
160     tv_erase(imcal2_tv_get());
161 }
162 
163 static void     clear_proc()
164 {
165     extern void imcalc_undo(Imrect * im1 , Imrect * im2 , Bool f);
166     Imrect         *im1,*im2;
167     int             type;
168 
169     im1 = (Imrect *) stack_pop(&type);
170     im2 = (Imrect *) stack_pop(&type);
171     imcalc_undo(im1,im2,false);
172     stack_push( im_copy(im2), IMRECT, im_free );
173     imcalc_draw(imcalc_tv_get());
174     imcalc_draw(imcal2_tv_get());
175     redraw_graph_plot(imcalc_tv_get());
176     image_choice_reset();
177 }
178 
179 static void     store_proc()
180 {
181     Imrect         *im;
182     int             type;
183 
184     im = (Imrect *) stack_inspect(&type);
185     imcalc_reg_set(im_copy(im),type);
186     imcalc_draw(imcmem_tv_get());
187 }
188 
189 static void     fetch_proc()
190 {
191     Imrect         *im1;
192 
193     stack_push(im_copy(imcalc_reg_get()), imcalc_reg_type(), im_free);
194     imcalc_draw(imcalc_tv_get());
195     imcalc_draw(imcal2_tv_get());
196     redraw_graph_plot(imcalc_tv_get());
197     image_choice_reset();
198 }
199 
200 static void dup_proc(void)
201 {
202     Imrect *im;
203     int type;
204 
205     im = (Imrect *) stack_inspect(&type);
206     if (type != IMRECT)
207         return;
208 
209     stack_push((void *) im_copy(im), type, im_free);
210     imcalc_draw(imcal2_tv_get());
211     image_choice_reset();
212 }
213 
214 static void flip_proc(void)
215 {
216     stack_flip();
217     imcalc_draw(imcalc_tv_get());
218     imcalc_draw(imcal2_tv_get());
219     redraw_graph_plot(imcalc_tv_get());
220     image_choice_reset();
221 }
222 
223 static void roi_proc(void)
224 {
225     Tv     *tv = imcalc_tv_get();
226     void set_crt_params(float a, float b, float c ,float d);
227     Imregion roi;
228 
229     if (tv == NULL || tv->tv_screen == NULL)
230         return;
231     roi = *tv_get_im_roi(tv);
232     imcalc_roi(&roi);
233     set_crt_params((float)((roi.lx+roi.ux)/2.0),
234                  fabs(roi.ux-roi.lx)/2.0,
235                  (float)((roi.ly+roi.uy)/2.0),
236                  fabs(roi.uy-roi.ly)/2.0);
237 
238     imcalc_draw(imcalc_tv_get());
239 }
240 
241 static void scat_proc(void)
242 {
243     Tv     *tv = imcalc_tv_get();
244     extern void imcalc_scat(Imregion *roi,float scale);
245  
246     if (tv == NULL || tv->tv_screen == NULL)
247         return;
248     imcalc_scat(tv_get_im_roi(tv),scale);
249     imcalc_draw(imcalc_tv_get());
250     imcalc_draw(imcal2_tv_get());
251     image_choice_reset();
252 }
253 
254 static void iscat_proc(void)
255 {
256     Tv     *tv = imcalc_tv_get();
257     extern void imcalc_iscat(Imregion *roi, float scale);
258  
259     if (tv == NULL || tv->tv_screen == NULL)
260         return;
261     imcalc_iscat(tv_get_im_roi(tv), scale);
262     imcalc_draw(imcalc_tv_get());
263     imcalc_draw(imcal2_tv_get());
264     image_choice_reset();
265 }
266 
267 static void dscat_proc(void)
268 {
269     Tv     *tv = imcalc_tv_get();
270     extern void imcalc_dscat(Imregion *roi, float scale);
271 
272     if (tv == NULL || tv->tv_screen == NULL)
273         return;
274     imcalc_dscat(tv_get_im_roi(tv), scale);
275     imcalc_draw(imcalc_tv_get());
276     imcalc_draw(imcal2_tv_get());
277     image_choice_reset();
278 }
279 
280 static void hist_proc(void)
281 {
282     Tv     *tv = imcalc_tv_get();
283     Imregion *roi;
284     extern void imcalc_hist(double *k, double range, double*var, Imregion *roi);
285  
286     if (tv == NULL || tv->tv_screen == NULL)
287         return;
288     roi = tv_get_im_roi(tv);
289     imcalc_hist(&thresh, range, &constant, roi);
290     constant = 1.0/constant;
291     (void) tw_fglobal_reset(pth);
292     (void) tw_fglobal_reset(pco);
293     imcalc_draw(imcalc_tv_get());
294     imcalc_draw(imcal2_tv_get());
295     image_choice_reset();
296 }
297 
298 static void zpad_proc(void)
299 {
300     imcalc_zpad(range);
301     imcalc_draw(imcalc_tv_get());
302     redraw_graph_plot(imcalc_tv_get());
303     image_choice_reset();
304 }
305 
306 static void rescale_proc(void)
307 {
308     imcalc_scale(0.0, scale);
309     imcalc_draw(imcalc_tv_get());
310     redraw_graph_plot(imcalc_tv_get());
311     image_choice_reset();
312 }
313 
314 static void sum_proc(void)
315 {
316     imcalc_sum();
317     imcalc_draw(imcalc_tv_get());
318     imcalc_draw(imcal2_tv_get());
319     redraw_graph_plot(imcalc_tv_get());
320     image_choice_reset();
321 }
322 
323 static void add_proc(void)
324 {
325     imcalc_add(constant);
326     imcalc_draw(imcalc_tv_get());
327     redraw_graph_plot(imcalc_tv_get());
328     image_choice_reset();
329 }
330 
331 static void diff_proc(void)
332 {
333     imcalc_diff();
334     imcalc_draw(imcalc_tv_get());
335     imcalc_draw(imcal2_tv_get());
336     redraw_graph_plot(imcalc_tv_get());
337     image_choice_reset();
338 }
339 
340 static void prod_proc(void)
341 {
342     imcalc_prod();
343     imcalc_draw(imcalc_tv_get());
344     imcalc_draw(imcal2_tv_get());
345     redraw_graph_plot(imcalc_tv_get());
346     image_choice_reset();
347 }
348 
349 static void div_proc(void)
350 {
351     imcalc_div(constant);
352     imcalc_draw(imcalc_tv_get());
353     imcalc_draw(imcal2_tv_get());
354     redraw_graph_plot(imcalc_tv_get());
355     image_choice_reset();
356 }
357 
358 static void minus_proc(void)
359 {
360     imcalc_minus();
361     imcalc_draw(imcalc_tv_get());
362     redraw_graph_plot(imcalc_tv_get());
363     image_choice_reset();
364 }
365 
366 static void times_proc(void)
367 {
368     imcalc_times(constant);
369     imcalc_draw(imcalc_tv_get());
370     redraw_graph_plot(imcalc_tv_get());
371     image_choice_reset();
372 }
373 
374 static void maxsel_proc(void)
375 {
376     imcalc_maxsel();
377     imcalc_draw(imcalc_tv_get());
378     redraw_graph_plot(imcalc_tv_get());
379     image_choice_reset();
380 }
381 
382 static void bshift_proc(void)
383 {
384     imcalc_bshift(sx,sy);
385     imcalc_draw(imcalc_tv_get());
386     redraw_graph_plot(imcalc_tv_get());
387 }
388 
389 static void     shift_proc()
390 {
391     imcalc_shift(sx,sy);
392     imcalc_draw(imcalc_tv_get());
393     redraw_graph_plot(imcalc_tv_get());
394 }
395 
396 static void aratio_proc(void)
397 {
398     imcalc_aratio(constant);
399     imcalc_draw(imcalc_tv_get());
400     redraw_graph_plot(imcalc_tv_get());
401     image_choice_reset();
402 }
403 
404 static void bratio_proc(void)
405 {
406     imcalc_bratio(constant);
407     imcalc_draw(imcalc_tv_get());
408     redraw_graph_plot(imcalc_tv_get());
409     image_choice_reset();
410 }
411 
412 static void sample_proc(void)
413 {
414     imcalc_sample(constant);
415     imcalc_draw(imcalc_tv_get());
416     redraw_graph_plot(imcalc_tv_get());
417     image_choice_reset();
418 }
419 
420 static void sqrt_proc(void)
421 {
422     imcalc_sqrt();
423     imcalc_draw(imcalc_tv_get());
424     redraw_graph_plot(imcalc_tv_get());
425     image_choice_reset();
426 }
427 
428 static void csqrt_proc(void)
429 {
430     imcalc_csqrt();
431     imcalc_draw(imcalc_tv_get());
432     redraw_graph_plot(imcalc_tv_get());
433     image_choice_reset();
434 }
435 
436 static void dilate_proc(void)
437 {
438     imcalc_dilate(range);
439     imcalc_draw(imcalc_tv_get());
440     redraw_graph_plot(imcalc_tv_get());
441     image_choice_reset();
442 }
443 
444 static void erode_proc(void)
445 {
446     imcalc_erode(range);
447     imcalc_draw(imcalc_tv_get());
448     redraw_graph_plot(imcalc_tv_get());
449     image_choice_reset();
450 }
451 
452 static void sqr_proc(void)
453 {
454     imcalc_sqr();
455     imcalc_draw(imcalc_tv_get());
456     redraw_graph_plot(imcalc_tv_get());
457     image_choice_reset();
458 }
459 
460 static void log_proc(void)
461 {
462     imcalc_log();
463     imcalc_draw(imcalc_tv_get());
464     redraw_graph_plot(imcalc_tv_get());
465     image_choice_reset();
466 }
467 
468 static void exp_proc(void)
469 {
470     imcalc_exp();
471     imcalc_draw(imcalc_tv_get());
472     redraw_graph_plot(imcalc_tv_get());
473     image_choice_reset();
474 }
475 
476 static void sin_proc(void)
477 {
478     imcalc_sin();
479     imcalc_draw(imcalc_tv_get());
480     redraw_graph_plot(imcalc_tv_get());
481     image_choice_reset();
482 }
483 
484 static void asin_proc(void)
485 {
486     imcalc_asin();
487     imcalc_draw(imcalc_tv_get());
488     redraw_graph_plot(imcalc_tv_get());
489     image_choice_reset();
490 }
491 
492 static void erf_proc(void)
493 {
494     imcalc_erf(&thresh);
495     imcalc_draw(imcalc_tv_get());
496     redraw_graph_plot(imcalc_tv_get());
497     tw_fglobal_reset(pth);
498     image_choice_reset();
499 }
500 
501 static void arg_proc(void)
502 {
503     imcalc_arg();
504     imcalc_draw(imcalc_tv_get());
505     redraw_graph_plot(imcalc_tv_get());
506     image_choice_reset();
507 }
508 
509 static void cis_proc(void)
510 {
511     imcalc_cis();
512     imcalc_draw(imcalc_tv_get());
513     redraw_graph_plot(imcalc_tv_get());
514     image_choice_reset();
515 }
516 
517 static void fft_proc(void)
518 {
519     imcalc_fft();
520     imcalc_draw(imcalc_tv_get());
521     redraw_graph_plot(imcalc_tv_get());
522     image_choice_reset();
523 }
524 
525 static void fft_inverse_proc(void)
526 {
527     imcalc_fft_inverse();
528     imcalc_draw(imcalc_tv_get());
529     redraw_graph_plot(imcalc_tv_get());
530     image_choice_reset();
531 }
532 
533 static void     optf_proc(void)
534 {
535     imcalc_optf(constant);
536     imcalc_draw(imcalc_tv_get());
537     redraw_graph_plot(imcalc_tv_get());
538 }
539 
540 static void powspec_proc(void)
541 {
542     imcalc_power_spectrum();
543     imcalc_draw(imcalc_tv_get());
544     redraw_graph_plot(imcalc_tv_get());
545     image_choice_reset();
546 }
547 
548 static void conj_proc(void)
549 {
550     imcalc_conj();
551     imcalc_draw(imcalc_tv_get());
552     redraw_graph_plot(imcalc_tv_get());
553 }
554 
555 static void real_proc(void)
556 {
557     imcalc_real();
558     imcalc_draw(imcalc_tv_get());
559     redraw_graph_plot(imcalc_tv_get());
560     image_choice_reset();
561 }
562 
563 static void imag_proc(void)
564 {
565     imcalc_imag();
566     imcalc_draw(imcalc_tv_get());
567     redraw_graph_plot(imcalc_tv_get());
568     image_choice_reset();
569 }
570 
571 static void xy_norm_proc(void)
572 {
573     imcalc_xy_norm(constant, sigma, thresh);
574     imcalc_draw(imcalc_tv_get());
575     redraw_graph_plot(imcalc_tv_get());
576     image_choice_reset();
577 }
578 
579 static void z_norm_proc(void)
580 {
581     void imcalc_z_norm(double *constant, Imregion *roi);
582     Imregion *roi;
583     Tv *tv = imcalc_tv_get();
584 
585     if (tv == NULL || tv->tv_screen == NULL)
586        roi = NULL;
587     else
588        roi = tv_get_im_roi(tv);
589 
590     imcalc_z_norm(&constant, roi);
591     (void) tw_fglobal_reset(pco);
592 }
593 
594 static void rm_dc_proc(void)
595 {
596     imcalc_rm_dc();
597     imcalc_draw(imcalc_tv_get());
598     redraw_graph_plot(imcalc_tv_get());
599     image_choice_reset();
600 }
601 
602 static void quad_proc(void)
603 {
604     imcalc_quad();
605     imcalc_draw(imcalc_tv_get());
606     redraw_graph_plot(imcalc_tv_get());
607     image_choice_reset();
608 }
609 
610 static void fgradx_proc(void)
611 {
612     imcalc_fgradx();
613     imcalc_draw(imcalc_tv_get());
614     redraw_graph_plot(imcalc_tv_get());
615 }
616 
617 static void fgrady_proc(void)
618 {
619     imcalc_fgrady();
620     imcalc_draw(imcalc_tv_get());
621     redraw_graph_plot(imcalc_tv_get());
622 }
623 
624 static void max_dir_proc(void)
625 {
626     imcalc_max_dir(thresh);
627     imcalc_draw(imcalc_tv_get());
628     image_choice_reset();
629 }
630 
631 static void nmax_proc(void)
632 {
633     imcalc_nmax(thresh,connect);
634     imcalc_draw(imcalc_tv_get());
635     image_choice_reset();
636 }
637 
638 static void thresh_proc(void)
639 {
640     imcalc_thresh(thresh);
641     imcalc_draw(imcalc_tv_get());
642     redraw_graph_plot(imcalc_tv_get());
643 }
644 
645 static void gauss_proc(void)
646 {
647     double acc;
648     acc = exp(-range*range/(2.0*sigma*sigma));
649     imcalc_gauss(sigma, acc);
650     imcalc_draw(imcalc_tv_get());
651     redraw_graph_plot(imcalc_tv_get());
652     image_choice_reset();
653 }
654 
655 static void lsf_smooth_proc(void)
656 {
657     imcalc_lsf_smooth(sigma, lr, ud);
658     imcalc_draw(imcalc_tv_get());
659     redraw_graph_plot(imcalc_tv_get());
660     image_choice_reset();
661 }
662 
663 static void median_proc(void)
664 {
665     imcalc_median();
666     imcalc_draw(imcalc_tv_get());
667     redraw_graph_plot(imcalc_tv_get());
668     image_choice_reset();
669 }
670 
671 static void rank_proc(void)
672 {
673     imcalc_rank((int)range,constant);
674     imcalc_draw(imcalc_tv_get());
675     redraw_graph_plot(imcalc_tv_get());
676     image_choice_reset();
677 }
678 
679 static void dx_proc(void)
680 {
681     imcalc_diffx();
682     imcalc_draw(imcalc_tv_get());
683     redraw_graph_plot(imcalc_tv_get());
684     image_choice_reset();
685 }
686 
687 static void dy_proc(void)
688 {
689     imcalc_diffy();
690     imcalc_draw(imcalc_tv_get());
691     redraw_graph_plot(imcalc_tv_get());
692     image_choice_reset();
693 }
694 
695 static void laplacian_proc(void)
696 {
697     imcalc_laplacian();
698     imcalc_draw(imcalc_tv_get());
699     redraw_graph_plot(imcalc_tv_get());
700     image_choice_reset();
701 }
702 
703 static void sqrgrad_proc(void)
704 {
705     imcalc_sqrgrad();
706     imcalc_draw(imcalc_tv_get());
707     redraw_graph_plot(imcalc_tv_get());
708     image_choice_reset();
709 }
710 
711 static void ddn_proc(void)
712 {
713     imcalc_ddn();
714     imcalc_draw(imcalc_tv_get());
715     redraw_graph_plot(imcalc_tv_get());
716     image_choice_reset();
717 }
718 
719 static void ddt_proc(void)
720 {
721     imcalc_ddt();
722     imcalc_draw(imcalc_tv_get());
723     redraw_graph_plot(imcalc_tv_get());
724     image_choice_reset();
725 }
726 
727 static void tsmooth_proc(void)
728 {
729     imcalc_tsmooth();
730     imcalc_draw(imcalc_tv_get());
731     redraw_graph_plot(imcalc_tv_get());
732     image_choice_reset();
733 }
734 
735 static void curv_proc(void)
736 {
737     imcalc_curv(constant,constant);
738     imcalc_draw(imcalc_tv_get());
739     redraw_graph_plot(imcalc_tv_get());
740     image_choice_reset();
741 }
742 
743 /* beth made this */
744 static void noise_proc(void)
745 {
746     Tv     *tv = imcalc_tv_get();
747     Imregion *roi;
748 
749     if (tv == NULL || tv->tv_screen == NULL)
750        roi = NULL;
751     else
752        roi = tv_get_im_roi(tv);
753     imcalc_noise(&constant,roi);
754     (void) tw_fglobal_reset(pco);
755 /* not necessary NAT
756     imcalc_draw(imcalc_tv_get());
757     imcalc_draw(imcal2_tv_get());
758     redraw_graph_plot(imcalc_tv_get());
759     image_choice_reset();
760 */
761 
762     return;
763 }
764 
765 static void window_proc(void)
766 {
767     imcalc_window(thresh,constant);
768     imcalc_draw(imcalc_tv_get());
769     redraw_graph_plot(imcalc_tv_get());
770     image_choice_reset();
771 }
772 
773 static void gwintz_bskel_proc(void)
774 {
775     Imrect *im1, *im2; /* working images */
776     unsigned long pixel_count;
777     int type;
778 
779     im1 = (Imrect *) stack_pop( &type );
780     im2 = (Imrect *) im_alloc(im1->height, im1->width, im1->region, im1->vtype);
781 
782     imcbthin1n( im1, im2, &pixel_count );
783     stack_push( im1, IMRECT, im_free );
784     imcalc_draw(imcalc_tv_get());
785     im_free( im2 );
786 }
787 
788 
789 static void create_tool_proc(void)
790 {
791     image_create_tool(100, 100);
792 }
793 
794 /* sic 22-4-96
795    function to print standard set of image information
796    to tina window display */
797 
798 static void image_info_proc(void)
799 {
800   Imrect *im;
801   char textout[100];
802   int type;
803 
804   /* check for an image on the stack, if not return with a warning */
805 
806   if (stack_check_types(IMRECT, NULL) == false)
807     {
808       error("\nimage_info_proc: non-imrect type on stack", warning);
809       return;
810     }
811 
812   im = (Imrect *) stack_pop(&type);
813 
814   format("\nImage Information\n-----------------\ndata type = ");
815   format_vtype(im->vtype);
816   sprintf(textout, "\nstored width = %i\nstored height = %i", im->width, im->height);
817   format(textout);
818   sprintf(textout, "\nactual width = %i\nactual height = %i", 
819           im->region->ux-im->region->lx, im->region->uy-im->region->ly);
820   format(textout);
821   sprintf(textout, "\nregion : lx = %i\n         ly = %i", im->region->lx, im->region->ly);
822   format(textout);
823   sprintf(textout, "\n         ux = %i\n         uy = %i \n", im->region->ux, im->region->uy);
824   format(textout);
825 
826   stack_push((void *) im, IMRECT, im_free);
827 }
828 
829 static void max_pos_proc(void)
830 {
831     Imrect *im;
832     int     type;
833     Vec2    pos = {Vec2_id};
834     Vec2    vec2();
835     Tv     *tv;
836     Tv     *imcalc_tv_get();
837     int     x, y;
838     float   max;
839 
840     im = (Imrect *) stack_inspect(&type);
841     if (type != IMRECT)
842         return;
843 
844     max = im_locate_max(im, &y, &x);
845     format("max value %5.3f \n",max);
846     thresh = max;
847     tw_fglobal_reset(pth);
848 
849     tv = imcalc_tv_get();
850     tv_set_color(tv, red);
851     pos = vec2((double) x, (double) y);
852     tv_cross2(tv, pos, 5);
853 }
854 
855 static void max_interest_proc(void)
856 {
857     Imrect *im;
858     int     type;
859     Vec2    pos = {Vec2_id};
860     Vec2    vec2();
861     Tv     *tv;
862     Tv     *imcalc_tv_get();
863     int     x, y;
864 
865     im = (Imrect *) stack_inspect(&type);
866     if (type != IMRECT)
867         return;
868 
869     im_locate_interest(im, &y, &x);
870 
871     tv = imcalc_tv_get();
872     tv_set_color(tv, red);
873     pos = vec2((double) x, (double) y);
874     tv_cross2(tv, pos, 5);
875 }
876 
877 static void imcalc_undo_proc()
878 {
879     extern void imcalc_undo(Imrect *im1, Imrect*im2, Bool f);
880     imcalc_undo(NULL,NULL,true);
881     imcalc_draw(imcalc_tv_get());
882     imcalc_draw(imcal2_tv_get());
883     redraw_graph_plot(imcalc_tv_get());
884     image_choice_reset();
885 
886 }
887 
888 
889 /********** Choice item callbacks **********/
890 
891 /**** Tv choice callback ****/
892 
893 static void tv_choice_proc(int val)
894 {
895     switch (val)
896     {
897         case 0:
898         tv_set_next(imcalc_tv_get());
899         break;
900         case 1:
901         tv_set_next(imcal2_tv_get());
902         break;
903         case 2:
904         tv_set_next(imcmem_tv_get());
905         break;
906         case 3:
907         tv_set_next(imcalc_graph_tv_get());
908     }
909 }
910 
911 /**** Imcalc mouse choice callback ****/
912 
913 static void imcalc_mouse_choice_proc(int val)
914 {
915     void set_copy_range(double *range);
916     Tv_mouse connmask_mouse();
917     Tv_mouse imcalc_grey_level_mouse();
918     Tv_mouse imcalc_prof_mouse();
919     Tv_mouse null_mouse();
920 
921     switch (val)
922     {
923     case 0:
924         set_copy_range(&range);
925         tv_set_mouse(imcalc_tv_get(), imcalc_grey_level_mouse());
926         graph_set_type(PL_CTR_DATA);
927         break;
928     case 1:
929         tv_set_mouse(imcalc_tv_get(), connmask_mouse());
930         graph_set_type(PL_CTR_DATA);
931         break;
932     case 2:
933         tv_set_mouse(imcalc_tv_get(), imcalc_prof_mouse());
934         graph_set_type(PL_GRAPH_DATA);
935         break;
936     case 3:
937         tv_set_mouse(imcalc_tv_get(), imcalc_prof_mouse());
938         graph_set_type(PL_HIST_DATA);
939         break;
940     }
941     (void) tv_set_activity(imcalc_tv_get(), MOUSE);
942     redraw_graph_plot(imcalc_tv_get());
943 }
944 
945 static void image_type_choice_proc(int val)
946 {
947     extern void imcalc_undo(Imrect * im1 , Imrect * im2 , Bool f);
948     Imrect *im,*im2;
949     int type, vtype;
950 
951     if (im=(Imrect *) stack_inspect(&type))
952     {
953         vtype = im->vtype;
954     }
955     switch (val)
956     {
957     case 0:
958         if (type == IMRECT || type==EDGERECT)
959         {
960            im = (Imrect *)stack_pop(&type);
961            im2 = im_bthresh(thresh, im);
962            stack_push((void *)im_cast(im2, uchar_v),IMRECT,im_free);
963            im_free(im2);
964            imcalc_undo(im,NULL,false);
965            imcalc_draw(imcalc_tv_get());
966         }
967         break;
968     case 1:
969         if (vtype != uchar_v &&type == IMRECT)
970         {
971            im = (Imrect *)stack_pop(&type);
972            stack_push((void *)im_cast(im, uchar_v),IMRECT,im_free);
973            imcalc_undo(im,NULL,false);
974            imcalc_draw(imcalc_tv_get());
975         }
976         break;
977     case 2:
978         if (vtype != short_v &&type == IMRECT)
979         {
980            im = (Imrect *)stack_pop(&type);
981            stack_push((void *)im_cast(im, short_v),IMRECT,im_free);
982            imcalc_undo(im,NULL,false);
983            imcalc_draw(imcalc_tv_get());
984         }
985         break;
986     case 3:
987         if (vtype != float_v && type==IMRECT)
988         {
989            im = (Imrect *)stack_pop(&type);
990            if (vtype != complex_v && vtype != short_v && vtype != uchar_v)
991            {
992               stack_push(im_cast(im, float_v),IMRECT,im_free);
993 /* don't undo basic casts as some functions do this as a last step NAT 17/2/13 */
994               im_free(im);
995            }
996            else if (vtype != complex_v )
997            {
998               stack_push(im_cast(im, float_v),IMRECT,im_free);
999               imcalc_undo(im,NULL,false);
1000            }
1001            else
1002            {
1003               stack_push((void *)im_im(im),IMRECT,im_free);
1004               stack_push((void *)im_re(im),IMRECT,im_free);
1005               imcalc_undo(im,NULL,false);
1006               imcalc_draw(imcal2_tv_get());
1007            }
1008            imcalc_draw(imcalc_tv_get());
1009         }
1010         break;
1011     case 4:
1012         if (vtype != complex_v && type==IMRECT)
1013         {
1014            im = (Imrect *)stack_pop(&type);
1015            im2 = stack_inspect(&type);
1016            if (type==IMRECT&&im2->vtype!=complex_v)
1017            {
1018               im2 = (Imrect *)stack_pop(&type);
1019               stack_push((void *)imz_cmplx(im, im2),IMRECT,im_free);
1020               imcalc_undo(im,im2,false);
1021            }
1022            else
1023            {
1024               stack_push((void *)im,IMRECT,im_free);
1025            }
1026            imcalc_draw(imcalc_tv_get());
1027            imcalc_draw(imcal2_tv_get());
1028         }
1029         break;
1030     case 5:
1031         if (vtype != ptr_v && type==IMRECT)
1032         {
1033            imcalc_nmax(thresh,connect);
1034            imcalc_draw(imcalc_tv_get());
1035         }
1036         break;
1037     }
1038     redraw_graph_plot(imcalc_tv_get());
1039 }
1040 
1041 /********** Paramter dialog callbacks **********/
1042 
1043 /**** Imcalc parameter dialog box callback ****/
1044 
1045 static void param_store_proc()
1046 {
1047    old_connect = connect;
1048    old_sx = sx;
1049    old_sy = sy;
1050    old_lr = lr;
1051    old_ud = ud;
1052    old_scale = scale;
1053    old_sigma = sigma;
1054    old_thresh = thresh;
1055    old_constant = constant;
1056    old_range = range;
1057 }
1058 
1059 static void param_restore_proc()
1060 {
1061    connect = old_connect;
1062    sx = old_sx;
1063    sy = old_sy;
1064    lr = old_lr;
1065    ud = old_ud;
1066    scale = old_scale;
1067    sigma = old_sigma;
1068    thresh = old_thresh;
1069    constant = old_constant;
1070    range = old_range;
1071    (void) tw_fglobal_reset(psc);
1072    (void) tw_fglobal_reset(psi);
1073    (void) tw_fglobal_reset(pac);
1074    (void) tw_fglobal_reset(pth);
1075    (void) tw_fglobal_reset(pco);
1076    (void) tw_fglobal_reset(pra);
1077    (void) tw_iglobal_reset(pcon);
1078    (void) tw_iglobal_reset(psx);
1079    (void) tw_iglobal_reset(psy);
1080    (void) tw_iglobal_reset(plr);
1081    (void) tw_iglobal_reset(pud);
1082 }
1083 
1084 static void invert_const_proc()
1085 {
1086    if (constant!=0.0) constant = 1.0/constant;
1087    (void) tw_fglobal_reset(pco);
1088 }
1089 
1090 static void swap_const_proc()
1091 {
1092    double temp = constant;
1093    constant = thresh;
1094    thresh = temp;
1095    (void) tw_fglobal_reset(pco);
1096    (void) tw_fglobal_reset(pth);
1097 }
1098 
1099 static void imcalc_dialog_proc(void)
1100 {
1101     static void *dialog = NULL;
1102 
1103     if (dialog)
1104     {
1105         tw_show_dialog(dialog);
1106         return;
1107     }
1108     dialog = tw_dialog("Imcalc Parameters");
1109 
1110     psx = (void *) tw_iglobal("sx:", &sx, 2);
1111     psy = (void *) tw_iglobal("sy:", &sy, 2);
1112     tw_newrow();
1113     plr = (void *) tw_iglobal("left/right:", &lr, 2);
1114     pud = (void *) tw_iglobal("up/down:", &ud, 2);
1115     tw_newrow();
1116     psi = (void *) tw_fglobal("sigma     :", &sigma, 16);
1117     tw_newrow();
1118     pco = (void *) tw_fglobal("const     :", &constant, 16);
1119     tw_button("1/const", invert_const_proc, NULL); 
1120     tw_newrow();
1121     pra = (void *) tw_fglobal("range     :", &range, 16);
1122     tw_newrow();
1123     psc = (void* ) tw_fglobal("scale     :", &scale, 16);
1124     tw_newrow();
1125     pth = (void *) tw_fglobal("thres     :", &thresh, 16);
1126     tw_button("swap", swap_const_proc, NULL); 
1127     tw_newrow();
1128     pcon = (void *) tw_iglobal("connect:", &connect, 2);
1129     tw_button("store", param_store_proc, NULL);
1130     tw_button("restore", param_restore_proc, NULL);
1131 
1132     tw_end_dialog();
1133 }
1134 
1135 /********** Tool creation **********/
1136 
1137 void    imcalc_tool(int x, int y)
1138 {
1139     static void *tv_screen = NULL;
1140     Imrect *im;
1141     int vtype,type,val;
1142 
1143     if (tv_screen)
1144     {
1145         tw_show_tool(tv_screen);
1146         return;
1147     }
1148     tv_proc();
1149 
1150     tv_screen = tw_tool("Imcalc Tool", x, y);
1151 
1152     tw_choice("Tv List :    ",
1153               tv_choice_proc, 0, "imcalc", "imcalc2", "register", "graph", NULL);
1154 
1155     tw_newrow();
1156 
1157     tw_choice("Imcalc Mice: ",
1158            imcalc_mouse_choice_proc, 0, "grey", "conn", "prof", "hist", NULL);
1159     tw_help_button("imcalc_tool");
1160 
1161     tw_newrow();
1162     if (im=(Imrect *) stack_inspect(&type))
1163     {
1164         if(type==IMRECT)
1165         {
1166            vtype = im->vtype;
1167            if (vtype==uchar_v) val = 1;
1168            if (vtype==short_v) val = 2;
1169            if (vtype==ushort_v) val = 2;
1170            if (vtype==int_v) val = 2;
1171            if (vtype==float_v) val = 3;
1172            if (vtype==complex_v) val = 4;
1173            if (vtype==ptr_v) val = 5;
1174         }
1175         else val = 0;
1176     }
1177     else val = 0;
1178 
1179     image_choice = tw_choice("Image type:  ",
1180            image_type_choice_proc,val,"bin","chr","int","flt","cmp","ptr", NULL);
1181 
1182     tw_newrow();
1183 
1184     tw_button("Imcalc Params", imcalc_dialog_proc, NULL);
1185     tw_button(" Create Tool ", create_tool_proc, NULL);
1186 
1187     /* sic 22-4-96
1188        function to print standard set of image information
1189        to tina window display */
1190 
1191     tw_button(" Info ", image_info_proc, NULL);
1192     tw_button(" Undo ", imcalc_undo_proc, NULL);
1193 
1194     tw_newrow();
1195 
1196     tw_button(" C ", clear_proc, NULL);
1197     tw_button(" CA ", clear_all_proc, NULL);
1198     tw_button("store", store_proc, NULL);
1199     tw_button("fetch", fetch_proc, NULL);
1200     tw_button("dup", dup_proc, NULL);
1201     tw_button("flp", flip_proc, NULL);
1202     tw_button("roi", roi_proc, NULL);
1203 
1204     tw_newrow();
1205 
1206     tw_button("scale", rescale_proc, NULL);
1207     tw_button("xrat", bratio_proc, NULL);
1208     tw_button("yrat", aratio_proc, NULL);
1209     tw_button("smpl", sample_proc, NULL);
1210     tw_button("shift", shift_proc, NULL);
1211     tw_button("bshift", bshift_proc, NULL);
1212 
1213     tw_newrow();
1214 
1215     tw_button(" + ", sum_proc, NULL);
1216     tw_button(" - ", diff_proc, NULL);
1217     tw_button(" * ", prod_proc, NULL);
1218     tw_button(" / ", div_proc, NULL);
1219     tw_button("-1* ", minus_proc, NULL);
1220     tw_button(" +k ", add_proc, NULL);
1221     tw_button(" k* ", times_proc, NULL);
1222     tw_button("max", maxsel_proc, NULL);
1223 
1224     tw_newrow();
1225 
1226     tw_button("sqrt", sqrt_proc, NULL);
1227     tw_button("csqrt", csqrt_proc, NULL);
1228     tw_button("sqr", sqr_proc, NULL);
1229     tw_button("log", log_proc, NULL);
1230     tw_button("exp", exp_proc, NULL);
1231     tw_button("sin", sin_proc, NULL);
1232     tw_button("asin", asin_proc, NULL);
1233 
1234     tw_newrow();
1235 
1236     tw_button("thres", thresh_proc, NULL);
1237     tw_button(" lsf ", lsf_smooth_proc, NULL);
1238     tw_button(" med ", median_proc, NULL);
1239     tw_button("rank", rank_proc, NULL);
1240     tw_button("gauss", gauss_proc, NULL);
1241     tw_button("tsmooth", tsmooth_proc, NULL);
1242 
1243     tw_newrow();
1244 
1245     tw_button("diffx", dx_proc, NULL);
1246     tw_button("diffy", dy_proc, NULL);
1247     tw_button("grdsq", sqrgrad_proc, NULL);
1248     tw_button("lap", laplacian_proc, NULL);
1249     tw_button("ddn", ddn_proc, NULL);
1250     tw_button("ddt", ddt_proc, NULL);
1251     tw_button("crv", curv_proc, NULL);
1252 
1253     tw_newrow();
1254 
1255     tw_button("xy norm ", xy_norm_proc, NULL);
1256     tw_button("z norm ", z_norm_proc, NULL);
1257     tw_button("arg", arg_proc, NULL);
1258     tw_button("cis", cis_proc, NULL);
1259     tw_button("conj", conj_proc, NULL);
1260     tw_button("optf", optf_proc, NULL);
1261 
1262     tw_newrow();
1263 
1264     tw_button("rmdc", rm_dc_proc, NULL);
1265     tw_button("quad", quad_proc, NULL);
1266     tw_button("fft", fft_proc, NULL);
1267     tw_button("ffti", fft_inverse_proc, NULL);
1268     tw_button("power", powspec_proc, NULL);
1269     tw_button("fdx", fgradx_proc, NULL);
1270     tw_button("fdy", fgrady_proc, NULL);
1271 
1272     tw_newrow();
1273 
1274 /*
1275     tw_button("max con", nmax_proc, NULL);
1276 */
1277     tw_button("erfp", erf_proc, NULL);
1278     tw_button("max pos", max_pos_proc, NULL);
1279 /*    tw_button("max crv", max_interest_proc, NULL);
1280 */
1281     tw_button("skel", gwintz_bskel_proc,NULL);
1282     tw_button("erode", erode_proc, NULL);
1283     tw_button("dilate", dilate_proc, NULL);
1284     tw_button("zpad", zpad_proc, NULL);
1285     tw_newrow();
1286  
1287     tw_button("scat", scat_proc, NULL);
1288     tw_button("iscat", iscat_proc, NULL);
1289     tw_button("dscat", dscat_proc, NULL);
1290     tw_button("hist", hist_proc, NULL);
1291     tw_button("noise", noise_proc, NULL);
1292     tw_button("window", window_proc, NULL);
1293 
1294 
1295     tw_end_tool();
1296 }
1297 
1298 
1299 
1300 static void mono_push_proc(void)  /* HR: duplicated from tlbaseMono_tool.c */
1301 {
1302     Imrect *im;
1303 
1304     im = im_copy(mono_image());
1305     stack_push((void *) im, IMRECT, im_free);
1306     if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
1307     if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
1308     image_choice_reset();
1309 }
1310 
1311 static void mono_pop_proc(void)  /* HR: duplicated from tlbaseMono_tool.c */
1312 {
1313     int     type;
1314 
1315     if (stack_check_types(IMRECT, NULL) == false)
1316         if (stack_check_types(EDGERECT, NULL) == false)
1317             error("pop_proc: wrong type on stack", warning);
1318         else
1319             mono_edges_set((Imrect *) stack_pop(&type)); 
1320     else
1321         mono_image_set((Imrect *) stack_pop(&type));
1322     if (imcalc_tv_get()!=NULL) tv_init(imcalc_tv_get());
1323     if (imcal2_tv_get()!=NULL) tv_init(imcal2_tv_get());
1324     image_choice_reset();
1325 }
1326 
1327 void    phantom_noise_reduction(int shiftx, int shifty)            /* HR: new */
1328 {
1329     mono_push_proc();
1330     sx = -shiftx;
1331     shift_proc();
1332 
1333     mono_push_proc();
1334     sx = shiftx;
1335     shift_proc();
1336     sum_proc();
1337 
1338     mono_push_proc();
1339     sy = -shifty;
1340     shift_proc();
1341 
1342     mono_push_proc();
1343     sy = shifty;
1344     shift_proc();
1345     sum_proc();
1346 
1347     sum_proc();
1348     add_proc();
1349     dup_proc();
1350     div_proc();
1351 
1352     mono_push_proc();
1353 
1354     prod_proc();
1355     noise_proc();
1356     invert_const_proc();
1357 
1358     mono_push_proc();
1359 
1360     times_proc();
1361 
1362     mono_pop_proc();
1363 }
1364 
1365 
1366 
1367 
1368 
1369 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.