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

Linux Cross Reference
Tina5/tina-tools/tinatool/tlbase/tlbaseImc_imc.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: /home/tina/cvs/tina-tools/tinatool/tlbase/tlbaseImc_imc.c,v $
 37  * Date    :  $Date: 2007/02/15 01:55:50 $
 38  * Version :  $Revision: 1.6 $
 39  * CVS Id  :  $Id: tlbaseImc_imc.c,v 1.6 2007/02/15 01:55:50 paul Exp $
 40  *
 41  * Author  :  Legacy TINA
 42  *
 43  * Notes :
 44  *
 45  *********
 46 */
 47 
 48 #include "tlbaseImc_imc.h"
 49 
 50 #if HAVE_CONFIG_H
 51 #include <config.h>
 52 #endif
 53 
 54 #include <stdio.h>
 55 #include <math.h>
 56 #include <float.h>
 57 
 58 #include <tina/sys/sysDef.h>
 59 #include <tina/sys/sysPro.h>
 60 #include <tina/image/imgDef.h>
 61 #include <tina/image/imgPro.h>
 62 #include <tina/geometry/geomPro.h>
 63 #include <tina/medical/medPro.h>
 64 #include <tinatool/draw/drawDef.h>
 65 #include <tinatool/tlbase/tlbase_InfrDef.h>
 66 #include <tinatool/tlbase/tlbase_InfrPro.h>
 67 #include <tinatool/tlbase/tlbaseImc_view.h>
 68 
 69 static Tv *tv_imcalc1 = NULL;
 70 static Tv *tv_imcalc2 = NULL;
 71 static Tv *tv_memory = NULL;
 72 static Tv *tv_graph = NULL;
 73 
 74 
 75 Tv     *imcalc_tv(void) /* backward compatability only now */
 76 {
 77     return (tv_imcalc1);
 78 }
 79 
 80 Tv     *imcalc_tv_get(void)
 81 {
 82     return (tv_imcalc1);
 83 }
 84 
 85 void    imcalc_tv_set(Tv * tv)
 86 {
 87     tv_imcalc1 = tv;
 88 }
 89 
 90 Tv     *imcal2_tv_get(void)
 91 {
 92     return (tv_imcalc2);
 93 }
 94 
 95 void    imcal2_tv_set(Tv * tv)
 96 {
 97     tv_imcalc2 = tv;
 98 }
 99 
100 Tv     *imcalc_graph_tv(void) /* backward compatability */
101 {
102     return (tv_graph);
103 }
104 
105 Tv     *imcalc_graph_tv_get(void)
106 {
107     return (tv_graph);
108 }
109 
110 void    imcalc_graph_tv_set(Tv * tv)
111 {
112     tv_graph = tv;
113 }
114 
115 Tv     *imcmem_tv_get(void)
116 {
117     return (tv_memory);
118 }
119 
120 void    imcmem_tv_set(Tv * tv)
121 {
122     tv_memory = tv;
123 }
124 
125 void imcalc_undo(Imrect *newim1, Imrect *newim2, Bool undo)
126 {
127     static Imrect *im1=NULL,*im2=NULL,*imtemp=NULL;
128     int type;
129 
130     if (undo == true)
131     {
132        if (im1==NULL&&im2==NULL)
133        {
134           format("cannot un-do last operation\n");
135           return;
136        }
137        if (stack_check_types(IMRECT, NULL) != false)
138        {
139           imtemp = (Imrect *) stack_pop(&type);
140           im_free(imtemp);
141        }
142      
143        if (im2!=NULL) stack_push((void *) im2, IMRECT, im_free);
144        if (im1!=NULL) stack_push((void *) im1, IMRECT, im_free);
145        im1 = NULL;
146        im2 = NULL;
147     }
148     else
149     {
150        if (im1 !=NULL) im_free(im1);
151        if (im2 !=NULL) im_free(im2);
152        im1 = newim1;
153        im2 = newim2;
154     }
155 }
156 
157 void    imcalc_sum(void)
158 /* +      - add TOS to NOS. */
159 {
160     Imrect *im1;
161     Imrect *im2;
162     int     type;
163 
164     if (stack_check_types(IMRECT, IMRECT, NULL) == false)
165     {
166         error("imcalc_sum: wrong types on stack", warning);
167         return;
168     }
169     im1 = (Imrect *) stack_pop(&type);
170     im2 = (Imrect *) stack_pop(&type);
171 
172     stack_push((void *) im_sum(im1, im2), IMRECT, im_free);
173 
174     imcalc_undo(im1,im2,false);
175 }
176 
177 void            imcalc_add(double k)
178 /* +k     - add IP(const) to TOS.*/
179 {
180     Imrect         *im;
181     int             type;
182 
183     if (stack_check_types(IMRECT, NULL) == false)
184     {
185         error("imcalc_sum: wrong types on stack", warning);
186         return;
187     }
188 
189     im = (Imrect *) stack_pop(&type);
190 
191     stack_push(im_add(k, im), IMRECT, im_free);
192 
193     imcalc_undo(im,NULL,false);
194 }
195 
196 void    imcalc_max_dir(double thres)
197 /* max grd - IP(thres) take top three images from stack dx,dy and sumsq and
198           peform edge detection. */
199 {
200     Imrect *im1;
201     Imrect *im2;
202     Imrect *im3;
203     int     type;
204 
205     if (stack_check_types(IMRECT, IMRECT, IMRECT, NULL) == false)
206     {
207         error("imcalc_sum: wrong types on stack", warning);
208         return;
209     }
210     im1 = (Imrect *) stack_pop(&type);
211     im2 = (Imrect *) stack_pop(&type);
212     im3 = (Imrect *) stack_pop(&type);
213 
214     stack_push((void *) nonmaxsup(im1, im2, im3, thres), EDGERECT, er_free);
215 
216     im_free(im1);
217     im_free(im2);
218     im_free(im3);
219     imcalc_undo(NULL,NULL,false);
220 }
221 
222 void    imcalc_nmax(double thres, int connect)
223 {
224     Imrect *im1;
225     int     type;
226 
227     if (stack_check_types(IMRECT, NULL) == false)
228     {
229         error("imcalc_sum: wrong types on stack", warning);
230         return;
231     }
232     im1 = (Imrect *) stack_pop(&type);
233 
234     stack_push((void *) imf_nmax(im1,(float) thres, connect), EDGERECT, er_free);
235 
236     imcalc_undo(im1,NULL,false);
237 
238 }
239 
240 void    imcalc_diff(void)
241 /* -1*    - negate TOS.*/
242 {
243     Imrect *im1;
244     Imrect *im2;
245     int     type;
246 
247     if (stack_check_types(IMRECT, IMRECT, NULL) == false)
248     {
249         error("imcalc_diff: wrong types on stack", warning);
250         return;
251     }
252     im1 = (Imrect *) stack_pop(&type);
253     im2 = (Imrect *) stack_pop(&type);
254 
255     stack_push((void *) im_diff(im1, im2), IMRECT, im_free);
256 
257     imcalc_undo(im1,im2,false);
258 }
259 
260 void    imcalc_maxsel(void)
261 {
262     Imrect *im1;
263     Imrect *im2;
264     int     type;
265 
266     if (stack_check_types(IMRECT, IMRECT, NULL) == false)
267     {
268         error("imcalc_maxsel: wrong types on stack", warning);
269         return;
270     }
271     im1 = (Imrect *) stack_pop(&type);
272     im2 = (Imrect *) stack_pop(&type);
273 
274     stack_push((void *) im_maxsel(im1, im2), IMRECT, im_free);
275 
276     imcalc_undo(im1,im2,false);
277 }
278 
279 void    imcalc_prod(void)
280 {
281     Imrect *im1;
282     Imrect *im2;
283     int     type;
284 
285     if (stack_check_types(IMRECT, IMRECT, NULL) == false)
286     {
287         error("imcalc_prod: wrong types on stack", warning);
288         return;
289     }
290     im1 = (Imrect *) stack_pop(&type);
291     im2 = (Imrect *) stack_pop(&type);
292 
293     stack_push((void *) im_prod(im1, im2), IMRECT, im_free);
294 
295     imcalc_undo(im1,im2,false);
296 }
297 
298 void    imcalc_div(double thres)
299 {
300     Imrect *im1;
301     Imrect *im2;
302     int     type;
303 
304     if (stack_check_types(IMRECT, IMRECT, NULL) == false)
305     {
306         error("imcalc_div: wrong types on stack", warning);
307         return;
308     }
309     im1 = (Imrect *) stack_pop(&type);
310     im2 = (Imrect *) stack_pop(&type);
311 
312     stack_push((void *) im_div(im1, im2, thres, thres), IMRECT, im_free);
313 
314     imcalc_undo(im1,im2,false);
315 }
316 
317 void    imcalc_minus(void)
318 {
319     Imrect *im;
320     int     type;
321 
322     if (stack_check_types(IMRECT, NULL) == false)
323     {
324         error("imcalc_minus: wrong type on stack", warning);
325         return;
326     }
327     im = (Imrect *) stack_pop(&type);
328     stack_push((void *) im_minus(im), IMRECT, im_free);
329 
330     imcalc_undo(im,NULL,false);
331 }
332 
333 void    imcalc_fft(void)
334 {
335     Imrect         *im,*im2;
336     Imregion *roi;
337     int             type;
338 
339     if (stack_check_types(IMRECT, NULL) == false)
340     {
341         error("imcalc_fft: wrong type on stack", warning);
342         return;
343     }
344 
345     im = (Imrect *) stack_pop(&type);
346     roi = im->region;
347     im2  = im_fft(im,roi);
348     im_shift(im2, -roi->ly,-roi->lx);
349     stack_push(im2, IMRECT, im_free);
350 
351     imcalc_undo(im,NULL,false);
352 }
353 
354 void    imcalc_fft_inverse(void)
355 {
356     Imrect *im;
357     Imregion *roi;
358     int     type;
359 
360     if (stack_check_types(IMRECT, NULL) == false)
361     {
362         error("imcalc_fft_inverse: wrong type on stack", warning);
363         return;
364     }
365     im = (Imrect *) stack_pop(&type);
366     roi = im->region;
367     stack_push((void *) im_fft_inverse(im,roi), IMRECT, im_free);
368 
369     imcalc_undo(im,NULL,false);
370 }
371 
372 void    imcalc_power_spectrum(void)
373 {
374     Imrect *im;
375     int     type;
376 
377     if (stack_check_types(IMRECT, NULL) == false)
378     {
379         error("imcalc_power_spectrum: wrong type on stack", warning);
380         return;
381     }
382     im = (Imrect *) stack_pop(&type);
383     stack_push((void *) im_power_spectrum(im), IMRECT, im_free);
384 
385     imcalc_undo(im,NULL,false);
386 }
387 
388 void    imcalc_conj(void)
389 {
390     Imrect *im;
391     int     type;
392 
393     if (stack_check_types(IMRECT, NULL) == false)
394     {
395         error("imcalc_conj: wrong type on stack", warning);
396         return;
397     }
398     im = (Imrect *) stack_pop(&type);
399     stack_push((void *) im_conj(im), IMRECT, im_free);
400 
401     imcalc_undo(im,NULL,false);
402 }
403 
404 void imcalc_optf(double k)
405 {
406     Imrect *im,*im2,*im3,*im4,*im5,*im6;
407     Imrect *im_thresh();
408     int             type;
409 
410     if (stack_check_types(IMRECT, NULL) == false)
411     {
412         error("imcalc_optf: wrong type on stack", warning);
413         return;
414     }
415 
416     im = (Imrect *) stack_pop(&type);
417     im2 = im_conj(im);
418     im3 = im_prod(im,im2);
419     im_free(im2);
420     im4 = im_add(-k*k,im3);    
421     im5 = im_thresh(0.0,im4);
422     im_free(im4);
423     im6 = im_div(im5,im3,FLT_MIN,FLT_MIN);
424     im_free(im3);
425     im_free(im5);
426     stack_push(im_prod(im,im6), IMRECT, im_free);
427     im_free(im6);
428     imcalc_undo(im,NULL,false);
429 }
430 
431 void    imcalc_real(void)
432 {
433     Imrect *im;
434     int     type;
435 
436     if (stack_check_types(IMRECT, NULL) == false)
437     {
438         error("imcalc_real: wrong type on stack", warning);
439         return;
440     }
441     im = (Imrect *) stack_pop(&type);
442     stack_push((void *) im_re(im), IMRECT, im_free);
443 
444     imcalc_undo(im,NULL,false);
445 }
446 
447 void    imcalc_imag(void)
448 {
449     Imrect *im;
450     int     type;
451 
452     if (stack_check_types(IMRECT, NULL) == false)
453     {
454         error("imcalc_imag: wrong type on stack", warning);
455         return;
456     }
457     im = (Imrect *) stack_pop(&type);
458     stack_push((void *) im_im(im), IMRECT, im_free);
459 
460     imcalc_undo(im,NULL,false);
461 }
462 
463 
464 void imcalc_xy_norm(double constant, double sigma, double thresh)
465 {
466    Imrect *im,*im3,*im4,*im5,*im6;
467    float maxim, minim;
468    int     type;
469 
470    if (stack_check_types(IMRECT, NULL) == false)
471    {
472       error("imcalc_xy_norm: wrong type on stack", warning);
473       return;
474    }
475    
476    im = (Imrect *) stack_inspect(&type);
477    im3  = xy_norm(im, constant, sigma, thresh);
478    im4 = imf_exp(im3);
479    im_free(im3);
480 /* check change scale */
481    im5 = im_prod(im, im4);
482    im6 = im_diff(im, im5);
483    im_free(im5);
484    imf_minmax(im6, &minim, &maxim); 
485    im_free(im6);
486    if (minim < -thresh*constant || maxim > thresh*constant)
487    {
488        format("correction %f %f greater than specified limit (IP thres)\n",
489                minim/constant,maxim/constant);
490        im3 = imf_times(0.0,im4);
491        im_free(im4);
492        im4 = imf_exp(im3);
493        im_free(im3);
494    }
495    
496    stack_push((void*) im4,IMRECT,im_free);
497    imcalc_draw(imcalc_tv_get());
498    imcalc_undo(NULL,NULL,false);
499    return;
500 }
501 
502 void eval_norm(double constant)
503 {
504    extern  double im_corscale2(Imrect *im0, Imrect *corr, double noise);
505    extern  double im_corscale(Imrect *im0, Imrect *corr, double noise);
506    Imrect *im, *im1, *im2, *im3;
507    int type;
508    double fac;
509 
510    im1 = (Imrect *) stack_pop(&type);
511    if (im1==NULL) return;
512    im = (Imrect *) stack_pop(&type);
513    if (im!=NULL) 
514    {
515       im2 = imf_log(im1);
516       im3 = imf_times(-1.0,im2);
517       fac = im_corscale2(im, im3, constant); 
518       fac = im_corscale(im, im3, constant); 
519       im_free(im2);
520       im_free(im3);
521       stack_push((void *) im, IMRECT, im_free);
522    }
523    stack_push((void *) im1, IMRECT, im_free);
524 }
525 
526 void imcalc_z_norm(double * constant, Imregion *roi)
527 {
528    Imrect *im1,*im2,*image1,*image2,*cut,*imsub1,*imsub2;
529    int type;
530    extern void edge_mask(double sig_noise, Imrect *im1, Imrect *im2, Imrect **cut,
531                      Imrect **image1, Imrect **image2);
532    extern double im_fraction(Imrect *cut, Imrect *image1, Imrect *image2,
533                           int nbin, double sig_noise);
534         
535    if (stack_check_types(IMRECT, IMRECT, NULL) == false)
536    {
537       error("imcalc_z_norm: wrong types on stack", warning);
538       return;
539    }
540    if (*constant <= 0.0)
541    {
542       error("imcalc_z_norm: no noise measurement",warning);
543       return;
544    }
545    im1 = (Imrect *) stack_pop(&type);
546    im2 = (Imrect *) stack_pop(&type);
547    if (roi !=NULL && 0) /* always use full image for now NAT 24/1/2001 */
548    {
549        imsub1 = im_subim(im1 , roi); 
550        imsub2 = im_subim(im2 , roi); 
551    }
552    else
553    {
554        imsub1 = im_copy(im1);
555        imsub2 = im_copy(im2);
556    }
557    edge_mask(*constant,imsub1,imsub2,&cut,&image1,&image2);
558    *constant = 1.0/exp(im_fraction(cut,image1,image2,21,*constant));
559    format("Estimated ratio  %f\n",*constant);
560    im_free(image1);
561    im_free(imsub1);
562    im_free(image2);
563    im_free(imsub2);
564    im_free(cut);
565    stack_push((void *) im2,IMRECT,im_free);
566    stack_push((void *) im1,IMRECT,im_free);
567 }
568 
569 void    imcalc_gabor(double k, double b, double theta)
570 {
571     Imrect *im;
572     int     type;
573 
574     if (stack_check_types(IMRECT, NULL) == false)
575     {
576         error("imcalc_gabor: wrong type on stack", warning);
577         return;
578     }
579     im = (Imrect *) stack_pop(&type);
580 
581     stack_push((void *) im_gabor_fft(im, k, b, theta), IMRECT, im_free);
582 
583     imcalc_undo(im,NULL,false);
584 }
585 
586 void    imcalc_shade(double slant, double tilt, double scale)
587 {
588     Imrect *im;
589     int     type;
590 
591     if (stack_check_types(IMRECT, NULL) == false)
592     {
593         error("imcalc_shade: wrong type on stack", warning);
594         return;
595     }
596     im = (Imrect *) stack_pop(&type);
597 
598     stack_push((void *) im_shading(im, slant, tilt, scale), IMRECT, im_free);
599 
600     imcalc_undo(im,NULL,false);
601 }
602 
603 void    imcalc_times(double k)
604 {
605     Imrect *im;
606     int     type;
607 
608     if (stack_check_types(IMRECT, NULL) == false)
609     {
610         error("imcalc_times: wrong type on stack", warning);
611         return;
612     }
613     im = (Imrect *) stack_pop(&type);
614     stack_push((void *) im_times(k, im), IMRECT, im_free);
615 
616     imcalc_undo(im,NULL,false);
617 }
618 
619 void    imcalc_aratio(double k)
620 {
621     Imrect *im;
622     int     type;
623 
624     if (stack_check_types(IMRECT, NULL) == false)
625     {
626         error("imcalc_aratio: wrong type on stack", warning);
627         return;
628     }
629     im = (Imrect *) stack_pop(&type);
630     stack_push((void *) imf_aratio(k, im), IMRECT, im_free);
631 
632     imcalc_undo(im,NULL,false);
633 }
634 
635 void    imcalc_bratio(double k)
636 {
637     Imrect *im;
638     int     type;
639 
640     if (stack_check_types(IMRECT, NULL) == false)
641     {
642         error("imcalc_bratio: wrong type on stack", warning);
643         return;
644     }
645     im = (Imrect *) stack_pop(&type);
646     stack_push((void *) imf_bratio(k, im), IMRECT, im_free);
647 
648     imcalc_undo(im,NULL,false);
649 }
650 
651 void            imcalc_shift(int x, int y)
652 {
653     Imrect         *im;
654     int             type;
655 
656     if (stack_check_types(IMRECT, NULL) == false)
657     {
658         error("imcalc_shift: wrong type on stack", warning);
659         return;
660     }
661 
662     im = (Imrect *) stack_inspect(&type);
663     im_shift(im,y,x);
664 /* no free necessary here as data shifted in place */
665 }
666 
667 void            imcalc_bshift(int x, int y)
668 {
669     Imrect         *im,*im2,*im_bshift();
670     int             type;
671 
672     if (stack_check_types(IMRECT, NULL) == false)
673     {
674         error("imcalc_bshift: wrong type on stack", warning);
675         return;
676     }
677 
678     im = (Imrect *) stack_pop(&type);
679     im2 = im_bshift(im, y, x);
680     stack_push(im2, IMRECT, im_free);
681     imcalc_undo(im,NULL,false);
682 }
683 
684 void    imcalc_sample(double k)
685 {
686     Imrect *im;
687     int     type;
688 
689     if (stack_check_types(IMRECT, NULL) == false)
690     {
691         error("imcalc_sample: wrong type on stack", warning);
692         return;
693     }
694     im = (Imrect *) stack_pop(&type);
695     stack_push((void *) imf_sample(k, im), IMRECT, im_free);
696 
697     imcalc_undo(im,NULL,false);
698 }
699 
700 void    imcalc_log(void)
701 {
702     Imrect *im;
703     int     type;
704 
705     if (stack_check_types(IMRECT, NULL) == false)
706     {
707         error("imcalc_log: wrong type on stack", warning);
708         return;
709     }
710     im = (Imrect *) stack_pop(&type);
711     stack_push((void *) im_log(im), IMRECT, im_free);
712 
713     imcalc_undo(im,NULL,false);
714 }
715 
716 void    imcalc_exp(void)
717 {
718     Imrect *im;
719     int     type;
720 
721     if (stack_check_types(IMRECT, NULL) == false)
722     {
723         error("imcalc_exp: wrong type on stack", warning);
724         return;
725     }
726     im = (Imrect *) stack_pop(&type);
727     stack_push((void *) im_exp(im), IMRECT, im_free);
728 
729     imcalc_undo(im,NULL,false);
730 }
731 
732 void    imcalc_mod(void)
733 {
734     Imrect *im;
735     int     type;
736 
737     if (stack_check_types(IMRECT, NULL) == false)
738     {
739         error("imcalc_mod: wrong type on stack", warning);
740         return;
741     }
742     im = (Imrect *) stack_pop(&type);
743     stack_push((void *) im_mod(im), IMRECT, im_free);
744 
745     imcalc_undo(im,NULL,false);
746 }
747 
748 void    imcalc_arg(void)
749 {
750     Imrect *im;
751     int     type;
752 
753     if (stack_check_types(IMRECT, NULL) == false)
754     {
755         error("imcalc_arg: wrong type on stack", warning);
756         return;
757     }
758     im = (Imrect *) stack_pop(&type);
759     stack_push((void *) im_arg(im), IMRECT, im_free);
760 
761     imcalc_undo(im,NULL,false);
762 }
763 
764 void    imcalc_cis(void)
765 {
766     Imrect *im;
767     int     type;
768 
769     if (stack_check_types(IMRECT, NULL) == false)
770     {
771         error("imcalc_cis: wrong type on stack", warning);
772         return;
773     }
774     im = (Imrect *) stack_pop(&type);
775     stack_push((void *) im_cis(im), IMRECT, im_free);
776 
777     imcalc_undo(im,NULL,false);
778 }
779 
780 void    imcalc_sin(void)
781 {
782     Imrect *im;
783     int     type;
784 
785     if (stack_check_types(IMRECT, NULL) == false)
786     {
787         error("imcalc_sin: wrong type on stack", warning);
788         return;
789     }
790     im = (Imrect *) stack_pop(&type);
791     stack_push((void *) im_sin(im), IMRECT, im_free);
792 
793     imcalc_undo(im,NULL,false);
794 }
795 
796 void    imcalc_asin(void)
797 {
798     Imrect *im;
799     int     type;
800 
801     if (stack_check_types(IMRECT, NULL) == false)
802     {
803         error("imcalc_sin: wrong type on stack", warning);
804         return;
805     }
806     im = (Imrect *) stack_pop(&type);
807     stack_push((void *) im_asin(im), IMRECT, im_free);
808 
809     imcalc_undo(im,NULL,false);
810 }
811 
812 void    imcalc_erf(double *thresh)
813 {
814     Imrect *im;
815     int     type;
816     double ml;
817     char temp[1024];
818 
819     if (stack_check_types(IMRECT, NULL) == false)
820     {
821         error("imcalc_erf: wrong type on stack", warning);
822         return;
823     }
824     im = (Imrect *) stack_pop(&type);
825     stack_push((void *) im_erf(im,thresh,&ml), IMRECT, im_free);
826     sprintf(temp, "Max-Likelihood score %f \n", ml);
827     format(temp);
828 
829     imcalc_undo(im,NULL,false);
830 }
831 
832 void    imcalc_roi(Imregion * roi)
833 {
834     Imrect *im,*im2;
835     int     type;
836     List   *tv_poly_get();
837     void    im_poly_crop(Imrect *im, List *poly);
838 
839     if (stack_check_types(IMRECT, NULL) == false)
840     {
841         error("imcalc_roi: wrong type on stack", warning);
842         return;
843     }
844     im = (Imrect *) stack_pop(&type);
845 
846     im2 = im_subim(im, roi);
847     if (tv_poly_get()!=NULL) im_poly_crop(im2,tv_poly_get());
848     stack_push(im2, IMRECT, im_free);
849     imcalc_undo(im,NULL,false);
850 }
851 
852 void    imcalc_hist(double *k, double range, double *variance, Imregion *roi)
853 {
854     Imrect *im;
855     int     type;
856     char   temp[1024];
857     shistogram *hist=NULL;
858     Imrect *im_hist(shistogram **imhist, double k, double range,
859                     Imrect *im, Imregion *roi);
860     void graph_hfit(Tv * tv, shistogram * hist);
861  
862     if (stack_check_types(IMRECT, NULL) == false)
863     {
864         error("imcalc_roi: wrong type on stack", warning);
865         return;
866     }
867     im = (Imrect *) stack_inspect(&type);
868  
869     stack_push((void *) im_hist(&hist, *k, range, im, roi), IMRECT, im_free);
870     imcalc_undo(NULL,NULL,false);
871     sprintf(temp, "over %f under %f \n",
872             hist->over,hist->under);
873     format(temp);
874     sprintf(temp, "entries %f total %f \n",
875            (float)hist->entries, (float)(hist->entries*hist->mean));
876     format(temp);
877     *variance = sqrt(fabs(hist->mean2-hist->mean*hist->mean));
878     sprintf(temp, "standard deviation %f \n",
879            (float)*variance);
880     format(temp);
881     
882 
883     *k = hist->mean;
884     graph_hfit(imcalc_graph_tv_get(), hist);
885     hfree(hist); 
886     hist = NULL;
887 }
888 
889 
890 void    imcalc_zpad(double range)
891 {
892     Imrect *im;
893     int     type;
894     Imrect *im_zeropad(Imrect *im, int range);
895  
896     if (stack_check_types(IMRECT, NULL) == false)
897     {
898         error("imcalc_roi: wrong type on stack", warning);
899         return;
900     }
901     im = (Imrect *) stack_pop(&type);
902  
903     stack_push((void *) im_zeropad(im, (int) range), IMRECT, im_free);
904     /* zero pad frees the image */
905     imcalc_undo(NULL,NULL,false);
906 }
907 
908 void    imcalc_scat(Imregion * roi, float scale)
909 {
910     Imrect *im;
911     int     type;
912     Imrect *im_scat(Imrect *im, Imregion *roi, float scale);
913  
914     if (stack_check_types(IMRECT, NULL) == false)
915     {
916         error("imcalc_roi: wrong type on stack", warning);
917         return;
918     }
919     im = (Imrect *) stack_inspect(&type);
920  
921     stack_push((void *) im_scat(im, roi, scale), IMRECT, im_free);
922     imcalc_undo(NULL,NULL,false);
923 }
924 
925 void    imcalc_iscat(Imregion * roi, float scale)
926 {
927     Imrect *im, *im2;
928     int     type;
929     Imrect *im_iscat(Imrect *im, Imrect*im2 , Imregion *roi, float scale);
930  
931     if (stack_check_types(IMRECT, NULL) == false)
932     {
933         error("imcalc_roi: wrong type on stack", warning);
934         return;
935     }
936     im = (Imrect *) stack_pop(&type);
937     im2 = (Imrect *) stack_inspect(&type);
938  
939     stack_push((void *) im_iscat(im, im2, roi, scale), IMRECT, im_free);
940     imcalc_undo(im,NULL,false);
941 }
942 
943 void    imcalc_dscat(Imregion * roi, float scale)
944 {
945     Imrect *im, *im2;
946     int     type;
947     Imrect *im_dscat(Imrect *im, Imrect*im2 , Imregion *roi, float scale);
948 
949     if (stack_check_types(IMRECT, NULL) == false)
950     {
951         error("imcalc_roi: wrong type on stack", warning);
952         return;
953     }
954     im = (Imrect *) stack_pop(&type);
955     im2 = (Imrect *) stack_inspect(&type);
956 
957     stack_push((void *) im_dscat(im, im2, roi, scale), IMRECT, im_free);
958     imcalc_undo(im,NULL,false);
959 }
960 
961 void    imcalc_sqrt(void)
962 {
963     Imrect *im;
964     int     type;
965 
966     if (stack_check_types(IMRECT, NULL) == false)
967     {
968         error("imcalc_sqrt: wrong type on stack", warning);
969         return;
970     }
971     im = (Imrect *) stack_pop(&type);
972     stack_push((void *) im_sqrt(im), IMRECT, im_free);
973 
974     imcalc_undo(im,NULL,false);
975 }
976 
977 void    imcalc_csqrt(void)
978 {
979     Imrect *im;
980     int     type;
981 
982     if (stack_check_types(IMRECT, NULL) == false)
983     {
984         error("imcalc_csqrt: wrong type on stack", warning);
985         return;
986     }
987     im = (Imrect *) stack_pop(&type);
988     stack_push((void *) imz_sqrt(im), IMRECT, im_free);
989 
990     imcalc_undo(im,NULL,false);
991 }
992 
993 void    imcalc_sqr(void)
994 {
995     Imrect *im;
996     int     type;
997 
998     if (stack_check_types(IMRECT, NULL) == false)
999     {
1000         error("imcalc_sqrt: wrong type on stack", warning);
1001         return;
1002     }
1003     im = (Imrect *) stack_pop(&type);
1004     stack_push((void *) im_sqr(im), IMRECT, im_free);
1005 
1006     imcalc_undo(im,NULL,false);
1007 }
1008 
1009 void    imcalc_rm_dc(void)
1010 {
1011     Imrect *im;
1012     int     type;
1013 
1014     if (stack_check_types(IMRECT, NULL) == false)
1015     {
1016         error("imcalc_rm_dc: wrong type on stack", warning);
1017         return;
1018     }
1019     im = (Imrect *) stack_pop(&type);
1020     stack_push((void *) imf_rm_dc(im), IMRECT, im_free);
1021 
1022     imcalc_undo(im,NULL,false);
1023 }
1024 
1025 void    imcalc_quad(void)
1026 {
1027     Imrect *im;
1028     int     type;
1029     Imrect *im_quad2();
1030 
1031     if (stack_check_types(IMRECT, NULL) == false)
1032     {
1033         error("imcalc_quad: wrong type on stack", warning);
1034         return;
1035     }
1036     im = (Imrect *) stack_pop(&type);
1037     stack_push((void *) im_quad2(im), IMRECT, im_free);
1038 
1039     imcalc_undo(im,NULL,false);
1040 }
1041 
1042 void    imcalc_fgradx(void)
1043 {
1044     Imrect *im;
1045     int     type;
1046 
1047     if (stack_check_types(IMRECT, NULL) == false)
1048     {
1049         error("imcalc_fgradx: wrong type on stack", warning);
1050         return;
1051     }
1052     im = (Imrect *) stack_pop(&type);
1053     if (im && im->vtype != complex_v)
1054     {
1055         error("imcalc_fgradx: wrong image type", warning);
1056         stack_push((void *) im, IMRECT, im_free);
1057         return;
1058     }
1059     stack_push((void *) imz_fxgrad(im), IMRECT, im_free);
1060 
1061     imcalc_undo(im,NULL,false);
1062 }
1063 
1064 void    imcalc_fgrady(void)
1065 {
1066     Imrect *im;
1067     int     type;
1068 
1069     if (stack_check_types(IMRECT, NULL) == false)
1070     {
1071         error("imcalc_fgrady: wrong type on stack", warning);
1072         return;
1073     }
1074     im = (Imrect *) stack_pop(&type);
1075     if (im && im->vtype != complex_v)
1076     {
1077         error("imcalc_fgrady: wrong image type", warning);
1078         stack_push((void *) im, IMRECT, im_free);
1079         return;
1080     }
1081     stack_push((void *) imz_fygrad(im), IMRECT, im_free);
1082 
1083     imcalc_undo(im,NULL,false);
1084 }
1085 
1086 void    imcalc_scale(double lower, double upper)
1087 {
1088     Imrect *im;
1089     int     type;
1090 
1091     if (stack_check_types(IMRECT, NULL) == false)
1092     {
1093         error("imcalc_sqrt: wrong type on stack", warning);
1094         return;
1095     }
1096     im = (Imrect *) stack_pop(&type);
1097     stack_push((void *) imf_scale(im, lower, upper), IMRECT, im_free);
1098 
1099     imcalc_undo(im,NULL,false);
1100 }
1101 
1102 void    imcalc_tsmooth(void)
1103 {
1104     Imrect *im;
1105     int     type;
1106 
1107     if (stack_check_types(IMRECT, NULL) == false)
1108     {
1109         error("imcalc_tsmooth: wrong type on stack", warning);
1110         return;
1111     }
1112     im = (Imrect *) stack_pop(&type);
1113     stack_push((void *) im_tsmooth(im), IMRECT, im_free);
1114 
1115     imcalc_undo(im,NULL,false);
1116 }
1117 
1118 void    imcalc_diffx(void)
1119 {
1120     Imrect *im;
1121     int     type;
1122 
1123     if (stack_check_types(IMRECT, NULL) == false)
1124     {
1125         error("imcalc_diffx: wrong type on stack", warning);
1126         return;
1127     }
1128     im = (Imrect *) stack_pop(&type);
1129     stack_push((void *) imf_diffx(im), IMRECT, im_free);
1130 
1131     imcalc_undo(im,NULL,false);
1132 }
1133 
1134 void    imcalc_diffy(void)
1135 {
1136     Imrect *im;
1137     int     type;
1138 
1139     if (stack_check_types(IMRECT, NULL) == false)
1140     {
1141         error("imcalc_diffy: wrong type on stack", warning);
1142         return;
1143     }
1144     im = (Imrect *) stack_pop(&type);
1145     stack_push((void *) imf_diffy(im), IMRECT, im_free);
1146 
1147     imcalc_undo(im,NULL,false);
1148 }
1149 
1150 /****** BETH START ********/
1151 
1152 void imcalc_noise(double *k, Imregion *roi)
1153 {
1154     Imrect *im;
1155     double sigma_x,sigma_y, diffxy;
1156     int    type;
1157 
1158    if (stack_check_types(IMRECT, NULL) == false)
1159     {
1160         error("imcalc_noise: wrong type on stack", warning);
1161         return;
1162     }
1163 
1164     im = (Imrect *) stack_pop(&type);
1165     if (roi == NULL || 1) roi = im->region; /* always use full image for now 
1166                                                NAT 24/1/2001 */
1167 /* nice little memory leak.. fixed NAT
1168     immask = im_alloc(im->height, im->width, roi, float_v);
1169 */
1170 
1171     sigma_x = imf_diffx_noise(im, roi);
1172 
1173     sigma_y = imf_diffy_noise(im, roi);
1174 
1175     diffxy = fabs(sigma_x - sigma_y);
1176     if (diffxy > 0.1*sigma_x || diffxy > 0.1*sigma_y)
1177             format("imcalc_noise:  noise in x and y quite different %f %f \n",sigma_x,sigma_y);
1178     *k = (sigma_x + sigma_y)/2;
1179     stack_push(im, IMRECT, im_free);
1180 /*
1181    no imcalc_undo neccesary for noise generation .... NAT
1182 */
1183    
1184     return;
1185 }
1186 /***** BETH DONE *****/
1187 
1188 void    imcalc_laplacian(void)
1189 {
1190     Imrect *im;
1191     int     type;
1192 
1193     if (stack_check_types(IMRECT, NULL) == false)
1194     {
1195         error("imcalc_laplacian: wrong type on stack", warning);
1196         return;
1197     }
1198     im = (Imrect *) stack_pop(&type);
1199     stack_push((void *) imf_laplacian(im), IMRECT, im_free);
1200     imcalc_undo(im,NULL,false);
1201 }
1202 
1203 void    imcalc_sqrgrad(void)
1204 {
1205     Imrect *im;
1206     int     type;
1207 
1208     if (stack_check_types(IMRECT, NULL) == false)
1209     {
1210         error("imcalc_sqrgrad: wrong type on stack", warning);
1211         return;
1212     }
1213     im = (Imrect *) stack_pop(&type);
1214     stack_push((void *) imf_sqrgrad(im), IMRECT, im_free);
1215     imcalc_undo(im,NULL,false);
1216 }
1217 
1218 void    imcalc_ddn(void)
1219 {
1220     Imrect *im;
1221     int     type;
1222 
1223     if (stack_check_types(IMRECT, NULL) == false)
1224     {
1225         error("imcalc_ddn: wrong type on stack", warning);
1226         return;
1227     }
1228     im = (Imrect *) stack_pop(&type);
1229     stack_push((void *) imf_ddn(im), IMRECT, im_free);
1230     imcalc_undo(im,NULL,false);
1231 }
1232 
1233 void    imcalc_ddt(void)
1234 {
1235     Imrect *im;
1236     int     type;
1237 
1238     if (stack_check_types(IMRECT, NULL) == false)
1239     {
1240         error("imcalc_ddt: wrong type on stack", warning);
1241         return;
1242     }
1243     im = (Imrect *) stack_pop(&type);
1244     stack_push((void *) imf_ddt(im), IMRECT, im_free);
1245     imcalc_undo(im,NULL,false);
1246 }
1247 
1248 void    imcalc_curv(double thresh, double val)
1249 {
1250     Imrect *im;
1251     int     type;
1252 
1253     if (stack_check_types(IMRECT, NULL) == false)
1254     {
1255         error("imcalc_curv: wrong type on stack", warning);
1256         return;
1257     }
1258     im = (Imrect *) stack_pop(&type);
1259     stack_push((void *) imf_curv(im, thresh, val), IMRECT, im_free);
1260     imcalc_undo(im,NULL,false);
1261 }
1262 
1263 void    imcalc_thresh(double k)
1264 {
1265     Imrect *im;
1266     int     type;
1267 
1268     if (stack_check_types(IMRECT, NULL) == false)
1269     {
1270         error("imcalc_thresh: wrong type on stack", warning);
1271         return;
1272     }
1273     im = (Imrect *) stack_pop(&type);
1274     stack_push((void *) imf_thresh(k, im), IMRECT, im_free);
1275 
1276     imcalc_undo(im,NULL,false);
1277 }
1278 
1279 void    imcalc_dilate(double radius)
1280 {
1281     Imrect *im;
1282     Imrect *el_val;
1283     int     type;
1284 
1285     if (stack_check_types(IMRECT, NULL) == false)
1286     {
1287         error("imcalc_gauss: wrong type on stack", warning);
1288         return;
1289     }
1290     im = (Imrect *) stack_pop(&type);
1291     morph_spere(radius, &el_val);
1292     stack_push((void *) imf_dilate(im, el_val), IMRECT, im_free);
1293 
1294     im_free(el_val);
1295     imcalc_undo(im,NULL,false);
1296 }
1297 
1298 void    imcalc_erode(double radius)
1299 {
1300     Imrect *im;
1301     Imrect *el_val;
1302     int     type;
1303 
1304     if (stack_check_types(IMRECT, NULL) == false)
1305     {
1306         error("imcalc_gauss: wrong type on stack", warning);
1307         return;
1308     }
1309     im = (Imrect *) stack_pop(&type);
1310     morph_spere(radius, &el_val);
1311     stack_push((void *) imf_erode(im, el_val), IMRECT, im_free);
1312 
1313     im_free(el_val);
1314     imcalc_undo(im,NULL,false);
1315 }
1316 
1317 void    imcalc_gauss(double sigma, double accuracy)
1318 {
1319     Imrect *im;
1320     int     type;
1321 
1322     if (stack_check_types(IMRECT, NULL) == false)
1323     {
1324         error("imcalc_gauss: wrong type on stack", warning);
1325         return;
1326     }
1327     im = (Imrect *) stack_pop(&type);
1328     stack_push((void *) imf_gauss(im, sigma, accuracy), IMRECT, im_free);
1329 
1330     imcalc_undo(im,NULL,false);
1331 }
1332 
1333 void    imcalc_lsf_smooth(double sigma, int sx, int sy)
1334 {
1335     Imrect *im;
1336     int     type;
1337 
1338     if (stack_check_types(IMRECT, NULL) == false)
1339     {
1340         error("imcalc_lsf_smooth: wrong type on stack", warning);
1341         return;
1342     }
1343     im = (Imrect *) stack_pop(&type);
1344     if (sx == 0 && sy == 0)
1345         stack_push((void *) imf_lsf_smooth(im, sigma), IMRECT, im_free);
1346     else
1347         stack_push((void *) imf_lsf_smooth_quad(im, sigma, sx, sy), IMRECT, im_free);
1348 
1349 
1350     imcalc_undo(im,NULL,false);
1351 }
1352 
1353 void    imcalc_median(void)
1354 {
1355     Imrect *im;
1356     int     type;
1357 
1358     if (stack_check_types(IMRECT, NULL) == false)
1359     {
1360         error("imcalc_median: wrong type on stack", warning);
1361         return;
1362     }
1363     im = (Imrect *) stack_pop(&type);
1364     stack_push((void *) im_median(im), IMRECT, im_free);
1365 
1366     imcalc_undo(im,NULL,false);
1367 }
1368 
1369 void    imcalc_rank(int scale, double sigma)
1370 {
1371     Imrect *im;
1372     int     type;
1373 
1374     if (stack_check_types(IMRECT, NULL) == false)
1375     {
1376         error("imcalc_rank: wrong type on stack", warning);
1377         return;
1378     }
1379     im = (Imrect *) stack_pop(&type);
1380     stack_push((void *) im_rank(im,scale,sigma), IMRECT, im_free);
1381 
1382     imcalc_undo(im,NULL,false);
1383 }
1384 
1385 void    imcalc_window(double thresh, double constant)
1386 {
1387     Imrect *im;
1388     extern Imrect *im_window(Imrect *im, double thresh,double constant);
1389     int     type;
1390  
1391     if (stack_check_types(IMRECT, NULL) == false)
1392     {
1393         error("imcalc_rank: wrong type on stack", warning);
1394         return;
1395     }
1396     im = (Imrect *) stack_pop(&type);
1397     stack_push((void *) im_window(im,thresh,constant), IMRECT, im_free);
1398  
1399     imcalc_undo(im,NULL,false);
1400 }
1401 

~ [ 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.