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

Linux Cross Reference
Tina4/src/vision/improc/im_scat.c

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

  1 #include <math.h>
  2 #include <tina/sys.h>
  3 #include <tina/sysfuncs.h>
  4 #include <tina/math.h>
  5 #include <tina/mathfuncs.h>
  6 #include <tina/vision.h>
  7 #include <tina/visionfuncs.h>
  8 #define MAXPLOT 255 
  9 
 10 Imrect *imz_scat(Imrect *im1, Imregion *roi, float scale)
 11 {
 12     Imregion *roi2;
 13     Imrect *im2;
 14     Complex *row1;
 15     double pixval,range=(MAXPLOT+1.0)/scale;
 16     int lx, ux, ly, uy;
 17     int i, j;
 18  
 19     if (im1 == NULL)
 20         return (NULL);
 21  
 22     if (roi == NULL ) roi = im1->region;
 23     lx = roi->lx;
 24     ux = roi->ux;
 25     ly = roi->ly;
 26     uy = roi->uy;
 27  
 28     im2 = im_alloc(256, 256, NULL, float_v);
 29     roi2 = im2->region;
 30     row1 = zvector_alloc(lx, ux);
 31  
 32     for (i = ly; i < uy; ++i)
 33     {
 34         im_get_rowz(row1, im1, i, lx, ux);
 35         for (j = lx; j < ux; ++j)
 36         {
 37              if ((int)(range*row1[j].x) > roi2->lx && (int)(range*row1[j].x) < roi2->ux
 38               && (int)(range*row1[j].y) > roi2->ly && (int)(range*row1[j].y) < roi2->uy )
 39              {
 40                 IM_PIX_GET(im2, MAXPLOT - (int)(range*row1[j].y), (int)(range*row1[j].x), pixval);
 41                 pixval += 1.0;
 42                 IM_PIX_SET(im2, MAXPLOT - (int)(range*row1[j].y), (int)(range*row1[j].x), pixval);
 43              }
 44         }
 45     }
 46  
 47     zvector_free(row1, lx);
 48     return (im2);
 49 }
 50 
 51 Imrect *imz_iscat(Imrect *im1, Imrect *im2, Imregion *roi, float scale)
 52 {
 53     Imregion *roi2;
 54     Imrect *im3;
 55     Complex *row2;
 56     float *row3;
 57     double pixval, range = (MAXPLOT+1.0)/scale;
 58     Imrect *im4;
 59     int lx, ux, ly, uy;
 60     int i, j;
 61  
 62     if (im1 == NULL || im2 == NULL)
 63         return (NULL);
 64  
 65     if (roi != NULL )
 66     {
 67         im4 = im_subim(im1, roi);
 68     }
 69     else im4 = im_copy(im1);
 70     roi = im4->region;
 71 
 72     roi2 = im2->region;
 73     lx = roi2->lx;
 74     ux = roi2->ux;
 75     ly = roi2->ly;
 76     uy = roi2->uy;
 77  
 78     im3 = im_alloc(im2->height, im2->width, roi2, float_v);
 79     row2 = zvector_alloc(lx, ux);
 80     row3 = fvector_alloc(lx, ux);
 81  
 82     for (i = ly; i < uy; ++i)
 83     {
 84         im_get_rowz(row2, im2, i, lx, ux);
 85         for (j = lx; j < ux; ++j)
 86         {
 87              if ((int)(range*row2[j].x) > roi->lx && (int)(range*row2[j].x) < roi->ux
 88               && MAXPLOT - (int)(range*row2[j].y) > roi->ly && MAXPLOT - (int)(range*row2[j].y) < roi->uy )
 89              {
 90                 IM_PIX_GET(im4, MAXPLOT - (int)(range*row2[j].y), (int)(range*row2[j].x), pixval);
 91                 row3[j] = pixval;     
 92              }
 93              else
 94                 row3[j] = 0.0;
 95         }
 96         im_put_rowf(row3, im3, i, lx, ux);
 97     }
 98  
 99     zvector_free(row2, lx);
100     fvector_free(row3, lx);
101     im_free(im4);
102     return (im3);
103 }
104 
105 static Imrect *normaliser(Imrect *graph_im)
106 {
107         int type, i, j, ux, lx, uy, ly;
108         float total=0, pix, new_pix;
109         Imrect *norm_graph_im;
110         Imregion *roi;
111 
112         norm_graph_im = im_copy(graph_im);
113         roi = graph_im->region;
114         ux = roi->ux;
115         uy = roi->uy;
116         lx = roi->lx;
117         ly = roi->ly;
118 
119         for(i=lx; i<ux; i++)
120         {
121                 total = 0.0;
122                 for(j=ly; j<uy; j++)
123                 {
124                         total = total + im_get_pixf(graph_im, j, i);
125                 }
126                 for(j=ly; j<uy; j++)
127                 {
128                         pix = im_get_pixf(graph_im, j, i);
129                         if(total!=0)
130                                 new_pix = (pix)/(total);
131                         im_put_pixf(new_pix, norm_graph_im, j, i);
132                 }
133         }
134         return(norm_graph_im);
135 }
136 
137 Imrect *imz_dscat(Imrect *graph_im, Imrect *complex_im, Imregion *roi, float scale)
138 {
139         int i, j, k, ux, lx, uy, ly, imux, imlx, imuy, imly;
140         double left_pix, right_pix, subpix;
141         float range = (MAXPLOT+1.0)/scale;
142         float graph_pix, test, total, this_pix, prev_pix, next_pix, subfrac;
143         Imrect *left_im, *right_im;
144         Imrect *difference_im, *norm_graph_im;
145         Imregion *imroi;
146 
147         left_im = im_re(complex_im);
148         right_im = im_im(complex_im);
149 
150         imroi=roi_inter(left_im->region, right_im->region);
151         if(imroi==NULL) return;
152         imlx = imroi->lx;
153         imux = imroi->ux;
154         imly = imroi->ly;
155         imuy = imroi->uy;
156 
157         lx = roi->lx;
158         ux = roi->ux;
159         ly = roi->ly;
160         uy = roi->uy;
161 
162         difference_im = im_cast(right_im, float_v);
163         norm_graph_im = normaliser(graph_im);
164 
165         for(i=imly; i<imuy; i++)
166         {
167            for(j=imlx; j<imux; j++)
168            {
169               left_pix = range*im_get_pixf(left_im, i, j);
170               right_pix = range*im_get_pixf(right_im, i, j);
171               graph_pix = im_sub_pixf(norm_graph_im, MAXPLOT-right_pix, left_pix);
172               subpix = (int)(right_pix) - right_pix;
173               prev_pix = im_sub_pixf(norm_graph_im, ly,
174                                        (left_pix));
175               this_pix = im_sub_pixf(norm_graph_im, ly+1.0,
176                                        (left_pix));
177               total = 0.0;
178               for(k=ly+1; k<uy-1; k++)
179               {
180                   next_pix = im_sub_pixf(norm_graph_im, k+1.0,
181                                        (left_pix));
182                   subfrac = fabs((next_pix-prev_pix)/2.0);
183                   if(graph_pix>this_pix+subfrac)
184                   {
185                      total += this_pix;
186                   }
187                   else if (graph_pix>this_pix-subfrac)
188                   {
189                      total += 0.5*this_pix*(graph_pix-this_pix+subfrac)/subfrac;
190                   }
191                   prev_pix = this_pix;
192                   this_pix = next_pix;
193               }
194               im_put_pixf(total, difference_im, i, j);
195            }
196         }
197 
198         im_free(left_im);
199         im_free(right_im);
200         im_free(norm_graph_im);
201 
202         return(difference_im);
203 }
204 
205 Imrect *im_scat(Imrect *im, Imregion *roi, float scale)
206 {
207     if(im == NULL )
208         return(NULL);
209     switch(im->vtype)
210     {
211         case complex_v:
212             return(imz_scat(im,roi,scale));
213         default:
214             return(NULL);
215     }
216 }
217 
218 Imrect *im_iscat(Imrect *im, Imrect *im2, Imregion *roi, float scale)
219 {
220     if(im == NULL || im2==NULL)
221         return(NULL);
222     switch(im2->vtype)
223     {
224         case complex_v:
225             return(imz_iscat(im, im2, roi, scale));
226         default:
227             return(NULL);
228     }
229 }
230 
231 Imrect *im_dscat(Imrect *im, Imrect *im2, Imregion *roi, float scale)
232 {
233     if(im == NULL || im2==NULL)
234         return(NULL);
235     switch(im2->vtype)
236     {
237         case complex_v:
238             return(imz_dscat(im, im2, roi, scale));
239         default:
240             return(NULL);
241     }
242 }
243 

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