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

Linux Cross Reference
Tina4/src/vision/improc/im_rank.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 
  9 #define MAXRANGE 10 /* maximum of unrolled for loop NAT 3/9/2000 */
 10 #define SOFT_RANK( x , y , z) ((fabs((x)-(y))< (z)) ? (0.5*((y)-(x))/(z)) : 1.0)
 11 
 12 /* Replaces each pixel of the image with it`s rank in a window of
 13    size 2*size +1 with a rank accuracy given by noise.
 14 */
 15 Imrect * imi_rank(Imrect *im, int size, double noise)
 16 {
 17         int lx,ux,ly,uy,i,j;
 18         int m,icen,jcen;
 19         int isize;
 20         Imrect *fim;
 21         int *rowpix,*newpix;
 22         int *otherpix;
 23         double cenpix;
 24         double level;
 25 
 26         if(im==NULL)
 27            return(NULL);
 28         lx = im->region->lx;
 29         ux = im->region->ux;
 30         ly = im->region->ly;
 31         uy = im->region->uy;
 32 
 33         fim=im_alloc(im->height, im->width,im->region,int_v);
 34         for(i=ly; i<uy; i++){
 35            newpix = IM_ROW(fim,i);
 36            icen = i;
 37            if(i<ly+size) icen = ly+size;
 38            if(i>uy-size-1) icen = uy-size-1;
 39            for(j=lx; j<ux; j++){
 40               jcen = j;
 41               if(j<lx+size) jcen = lx+size;
 42               if(j>ux-size-1) jcen = ux-size-1;
 43               cenpix = IM_INT(im, i, j);
 44               level = 0.0;
 45               isize = icen+size+1;
 46               for(m=icen-size; m<isize; m++)
 47               {
 48                  rowpix = IM_ROW(im, m);        
 49                  otherpix = &rowpix[jcen-size-1];
 50                  switch(size)
 51                  {
 52                      case 10:
 53                          if (*(++otherpix)<cenpix)
 54                              level += SOFT_RANK(*otherpix, cenpix, noise);
 55                          if (*(++otherpix)<cenpix)
 56                              level += SOFT_RANK(*otherpix, cenpix, noise);
 57                      case 9:
 58                          if (*(++otherpix)<cenpix)
 59                              level += SOFT_RANK(*otherpix, cenpix, noise);
 60                          if (*(++otherpix)<cenpix)
 61                              level += SOFT_RANK(*otherpix, cenpix, noise);
 62                      case 8:
 63                          if (*(++otherpix)<cenpix)
 64                              level += SOFT_RANK(*otherpix, cenpix, noise);
 65                          if (*(++otherpix)<cenpix)
 66                              level += SOFT_RANK(*otherpix, cenpix, noise);
 67                      case 7:
 68                          if (*(++otherpix)<cenpix)
 69                              level += SOFT_RANK(*otherpix, cenpix, noise);
 70                          if (*(++otherpix)<cenpix)
 71                              level += SOFT_RANK(*otherpix, cenpix, noise);
 72                      case 6:
 73                          if (*(++otherpix)<cenpix)
 74                              level += SOFT_RANK(*otherpix, cenpix, noise);
 75                          if (*(++otherpix)<cenpix)
 76                              level += SOFT_RANK(*otherpix, cenpix, noise);
 77                      case 5:
 78                          if (*(++otherpix)<cenpix)
 79                              level += SOFT_RANK(*otherpix, cenpix, noise);
 80                          if (*(++otherpix)<cenpix)
 81                              level += SOFT_RANK(*otherpix, cenpix, noise);
 82                      case 4:
 83                          if (*(++otherpix)<cenpix)
 84                              level += SOFT_RANK(*otherpix, cenpix, noise);
 85                          if (*(++otherpix)<cenpix)
 86                              level += SOFT_RANK(*otherpix, cenpix, noise);
 87                      case 3:
 88                          if (*(++otherpix)<cenpix)
 89                              level += SOFT_RANK(*otherpix, cenpix, noise);
 90                          if (*(++otherpix)<cenpix)
 91                              level += SOFT_RANK(*otherpix, cenpix, noise);
 92                      case 2:
 93                          if (*(++otherpix)<cenpix)
 94                              level += SOFT_RANK(*otherpix, cenpix, noise);
 95                          if (*(++otherpix)<cenpix)
 96                              level += SOFT_RANK(*otherpix, cenpix, noise);
 97                      case 1:
 98                          if (*(++otherpix)<cenpix)
 99                              level += SOFT_RANK(*otherpix, cenpix, noise);
100                          if (*(++otherpix)<cenpix)
101                              level += SOFT_RANK(*otherpix, cenpix, noise);
102                          if (*(++otherpix)<cenpix)
103                              level += SOFT_RANK(*otherpix, cenpix, noise);
104                  }
105               }
106               newpix[j] = level;
107            }
108         }
109         return(fim);
110 }
111 
112 /* for test purposes only NAT 3/9/2000 */
113 static double soft_rank(float otherpix, double cenpix, double noise)
114 {
115    if (fabs((double)(otherpix-cenpix))<noise)
116       return(0.5*(cenpix-otherpix)/noise);
117    else
118       return(1.0);
119 
120 }
121 
122 Imrect * imf_rank(Imrect *im, int size, double noise)
123 {
124         int lx,ux,ly,uy,i,j;
125         int m,icen,jcen;
126         int isize;
127         Imrect *fim;
128         float *rowpix,*newpix;
129         float *otherpix;
130         double cenpix;
131         double level;
132 
133         if(im==NULL)
134            return(NULL);
135 /*  try to introduce a sensible radially symetric filter
136         static float **weight=NULL;
137     radial gaussian weighting with sigma = size/2.0 
138     significantly increases computation and required region size
139     but does not improve final result. NAT 8/6/95
140         if (weight == NULL)
141         {
142             weight = farray_alloc(-size,-size,size+1,size+1);
143             for (i=-size;i<size+1;i++)
144             {
145                 for (j=-size;j<size+1;j++)
146                 {
147                      weight[i][j] = exp(-2.0*(i*i + j*j)/(double)(size*size));
148                 }
149             }
150         }
151 */
152 
153         lx = im->region->lx;
154         ux = im->region->ux;
155         ly = im->region->ly;
156         uy = im->region->uy;
157 
158         fim=im_alloc(im->height, im->width,im->region,float_v);
159         for(i=ly; i<uy; i++){
160            newpix = IM_ROW(fim,i);
161            icen = i;
162            if(i<ly+size) icen = ly+size; 
163            if(i>uy-size-1) icen = uy-size-1;
164            for(j=lx; j<ux; j++){
165               jcen = j;
166               if(j<lx+size) jcen = lx+size; 
167               if(j>ux-size-1) jcen = ux-size-1;
168               cenpix = IM_FLOAT(im, i, j);
169               level = 0.0;
170               isize = icen+size+1;
171 
172               for(m=icen-size; m<isize; m++)
173               {
174                  rowpix = IM_ROW(im, m);        
175                  otherpix = &rowpix[jcen-size-1];
176                  switch(size) /* unrolled loop for speed */
177                  {
178                      case 10:
179                          if (*(++otherpix)<cenpix)
180                              level += SOFT_RANK(*otherpix, cenpix, noise);
181                          if (*(++otherpix)<cenpix)
182                              level += SOFT_RANK(*otherpix, cenpix, noise);
183                      case 9:
184                          if (*(++otherpix)<cenpix)
185                              level += SOFT_RANK(*otherpix, cenpix, noise);
186                          if (*(++otherpix)<cenpix)
187                              level += SOFT_RANK(*otherpix, cenpix, noise);
188                      case 8:
189                          if (*(++otherpix)<cenpix)
190                              level += SOFT_RANK(*otherpix, cenpix, noise);
191                          if (*(++otherpix)<cenpix)
192                              level += SOFT_RANK(*otherpix, cenpix, noise);
193                      case 7:
194                          if (*(++otherpix)<cenpix)
195                              level += SOFT_RANK(*otherpix, cenpix, noise);
196                          if (*(++otherpix)<cenpix)
197                              level += SOFT_RANK(*otherpix, cenpix, noise);
198                      case 5:
199                          if (*(++otherpix)<cenpix)
200                              level += SOFT_RANK(*otherpix, cenpix, noise);
201                          if (*(++otherpix)<cenpix)
202                              level += SOFT_RANK(*otherpix, cenpix, noise);
203                      case 4:
204                          if (*(++otherpix)<cenpix)
205                              level += SOFT_RANK(*otherpix, cenpix, noise);
206                          if (*(++otherpix)<cenpix)
207                              level += SOFT_RANK(*otherpix, cenpix, noise);
208                      case 3:
209                          if (*(++otherpix)<cenpix)
210                              level += SOFT_RANK(*otherpix, cenpix, noise);
211                          if (*(++otherpix)<cenpix)
212                              level += SOFT_RANK(*otherpix, cenpix, noise);
213                      case 2:
214                          if (*(++otherpix)<cenpix)
215                              level += SOFT_RANK(*otherpix, cenpix, noise);
216                          if (*(++otherpix)<cenpix)
217                              level += SOFT_RANK(*otherpix, cenpix, noise);
218                      case 1:
219                          if (*(++otherpix)<cenpix)
220                              level += SOFT_RANK(*otherpix, cenpix, noise);
221                          if (*(++otherpix)<cenpix)
222                              level += SOFT_RANK(*otherpix, cenpix, noise);
223                          if (*(++otherpix)<cenpix)
224                              level += SOFT_RANK(*otherpix, cenpix, noise);
225                  }
226               }
227               newpix[j] = level;
228            }
229         }
230         return(fim);
231 }
232 
233 Imrect *im_rank(Imrect *im, int range, double noise)
234 {
235     Imrect *rim;
236     if(im == NULL || range > MAXRANGE)
237         return(NULL);
238     switch(im->vtype)
239     {
240         case uchar_v:
241         case char_v:
242         case short_v:
243         case ushort_v:
244              im = im_cast(im, int_v);
245              rim = imi_rank(im, range, noise); 
246              im_free(im);
247              return(rim);
248         case int_v:
249              return(imi_rank(im, range, noise));
250         case double_v:
251              im = im_cast(im, float_v);
252              rim = imf_rank(im, range, noise);
253              im_free(im);
254              return(rim);
255         case float_v:
256              return(imf_rank(im, range, noise));
257         case complex_v:
258              return(NULL);
259         default:
260              return(NULL);
261     }
262 }
263 

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