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

Linux Cross Reference
Tina4/src/tools/imcalc/imcalc.c

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

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

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