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

Linux Cross Reference
Tina5/tina-libs/tina/image/imgPrc_median3D.c

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

  1 /**********
  2  * 
  3  * This file is part of the TINA Open Source Image Analysis Environment
  4  * henceforth known as TINA
  5  *
  6  * TINA is free software; you can redistribute it and/or modify
  7  * it under the terms of the GNU Lesser General Public License as 
  8  * published by the Free Software Foundation.
  9  *
 10  * TINA is distributed in the hope that it will be useful,
 11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  * GNU Lesser General Public License for more details.
 14  *
 15  * You should have received a copy of the GNU Lesser General Public License
 16  * along with TINA; if not, write to the Free Software Foundation, Inc., 
 17  * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 18  *
 19  **********
 20  * 
 21  * Program :    TINA
 22  * File    :  $Source: /home/tina/cvs/tina-libs/tina/image/imgPrc_median3D.c,v $
 23  * Date    :  $Date: 2007/02/15 01:52:29 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: imgPrc_median3D.c,v 1.3 2007/02/15 01:52:29 paul Exp $
 26  *
 27  * Author  : mjs
 28  *
 29  * Notes :
 30  *
 31  *********
 32 */
 33 
 34 #include "imgPrc_median3D.h"
 35 
 36 #if HAVE_CONFIG_H
 37   #include <config.h>
 38 #endif
 39 
 40 #include <stdio.h>
 41 #include <sys/param.h>
 42 #include <string.h>
 43 #include <math.h>
 44 
 45 #include <tina/sys/sysDef.h>
 46 #include <tina/sys/sysPro.h>
 47 #include <tina/math/mathDef.h>
 48 #include <tina/math/mathPro.h>
 49 #include <tina/image/imgDef.h>
 50 #include <tina/image/imgPro.h>
 51 
 52 #undef MAXFLOAT
 53 #define MAXFLOAT 1000000.0
 54 
 55 
 56 float med3by3by3f(float *b1, float *b2, float *b3, float *b4, float *b5, float *b6, float *b7, float *b8, float *b9)
 57 {
 58   float r[27]; /*Again, all by brute force..*/
 59   float fin;
 60     int label[27], count = 0;
 61     int i,j;
 62     float max=-MAXFLOAT,min=MAXFLOAT;
 63     int max_label=0,min_label=0;
 64 
 65     /*if(b5[0] == 0)  
 66       return(0.0); */
 67     /* Where the centre pixel is 0, we do not wish to replace it*/
 68     /* for the moment */
 69 
 70     r[0] = b1[-1]; r[1] = b1[0]; r[2] = b1[1];
 71     r[3] = b2[-1]; r[4] = b2[0]; r[5] = b2[1];
 72     r[6] = b3[-1]; r[7] = b3[0]; r[8] = b3[1];
 73 
 74     r[9] = b4[-1]; r[10] = b4[0]; r[11] = b4[1];
 75     r[12] = b5[-1]; r[13] = b5[0]; r[14] = b5[1];
 76     r[15] = b6[-1]; r[16] = b6[0]; r[17] = b6[1];
 77 
 78     r[18] = b7[-1]; r[19] = b7[0]; r[20] = b7[1];
 79     r[21] = b8[-1]; r[22] = b8[0]; r[23] = b8[1];
 80     r[24] = b9[-1]; r[25] = b9[0]; r[26] = b9[1];
 81 
 82     for (i=0;i<27;i++) 
 83       {
 84         label[i] = 1;
 85         if(r[i] != 0)
 86           {
 87             count++;
 88           }
 89       }
 90     fin = ((float)count/2)+0.5;
 91 
 92     if(count>13)
 93       {
 94         for(j=0;j<fin;j++)
 95           {
 96             for(i=0;i<27;i++)
 97               {
 98                 if(r[i] != 0)
 99                   {
100                     if (label[i] && (r[i]<=min))
101                       {
102                         min_label = i; 
103                         min = r[i];
104                       }
105                     if (label[i] && (r[i]>=max))
106                       {
107                         max_label = i;
108                         max = r[i];
109                       }
110                   }
111                 else
112                   {}
113                 
114               }
115             label[max_label] = 0;
116             label[min_label] = 0;
117             max = -MAXFLOAT;
118             min = MAXFLOAT;
119           }
120         return(r[min_label]);
121       }
122 
123     else 
124       return(0);
125 
126 }
127 
128 static Imrect *imf_median_3D(Imrect *im1, Imrect *im2, Imrect *im3)
129 {
130     Imrect *new_im;
131     Imregion *roi;
132     /*mjs I have chosen to do this by brute force, and not by using 3d matrices*/
133     float *row, *row11, *row12, *row13;
134     float *row21, *row22, *row23; 
135     float *row31, *row32, *row33;
136     int lx, ux, ly, uy;
137     int i, j;
138 
139     if (im1 == NULL)
140       {
141         format("\nFirst image NULL\n");
142         return (NULL);
143       }
144 
145     roi = im1->region;
146     if (roi == NULL)
147       {
148         format("\nROI is NULL\n");
149         return (NULL);
150       }
151     lx = roi->lx;
152     ux = roi->ux;
153     ly = roi->ly;
154     uy = roi->uy;
155 
156     new_im = im_alloc(im1->height, im1->width, roi, float_v);
157     row  = fvector_alloc(lx, ux);
158 
159     row11 = fvector_alloc(lx-1, ux+1);
160     row12 = fvector_alloc(lx-1, ux+1);
161     row13 = fvector_alloc(lx-1, ux+1);
162 
163     row21 = fvector_alloc(lx-1, ux+1);
164     row22 = fvector_alloc(lx-1, ux+1);
165     row23 = fvector_alloc(lx-1, ux+1);
166 
167     row31 = fvector_alloc(lx-1, ux+1);
168     row32 = fvector_alloc(lx-1, ux+1);
169     row33 = fvector_alloc(lx-1, ux+1);
170 
171     im_get_rowf(row12, im1, ly, lx, ux);
172     row12[lx-1] = row12[lx]; row12[ux] = row12[ux-1];
173     im_get_rowf(row13, im1, ly, lx, ux);
174     row13[lx-1] = row31[lx]; row13[ux] = row13[ux-1];
175 
176     im_get_rowf(row22, im2, ly, lx, ux);
177     row22[lx-1] = row22[lx]; row22[ux] = row22[ux-1];
178     im_get_rowf(row23, im1, ly, lx, ux);
179     row23[lx-1] = row23[lx]; row23[ux] = row23[ux-1];
180 
181     im_get_rowf(row32, im3, ly, lx, ux);
182     row32[lx-1] = row32[lx]; row32[ux] = row32[ux-1];
183     im_get_rowf(row33, im1, ly, lx, ux);
184     row33[lx-1] = row33[lx]; row33[ux] = row33[ux-1];
185 
186 
187     for (i = ly; i < uy; ++i)
188     {
189         float *temp1 = row11, *temp2 = row21, *temp3 = row31; 
190         row11 = row12; row21 = row22; row31 = row32;
191         row12 = row13; row22 = row23; row32 = row33;
192         row13 = temp1; row23 = temp2; row33 = temp3;
193 
194         if(i != uy-1)
195           {
196             im_get_rowf(row13, im1, i+1, lx, ux);
197             im_get_rowf(row23, im2, i+1, lx, ux);
198             im_get_rowf(row33, im3, i+1, lx, ux);
199           }
200         else
201           {
202             im_get_rowf(row13, im1, i, lx, ux);
203             im_get_rowf(row23, im2, i, lx, ux);
204             im_get_rowf(row33, im3, i, lx, ux);
205           }
206 
207         row13[lx-1] = row13[lx]; row13[ux] = row13[ux-1];
208         row23[lx-1] = row23[lx]; row23[ux] = row23[ux-1];
209         row33[lx-1] = row33[lx]; row33[ux] = row33[ux-1];
210 
211         for (j = lx; j < ux; ++j)
212             row[j] = med3by3by3f(&row11[j], &row12[j], &row13[j], &row21[j], &row22[j], &row23[j], &row31[j], &row32[j], &row33[j] );
213 
214         im_put_rowf(row, new_im, i, lx, ux);
215     }
216 
217     fvector_free(row,  lx);
218     fvector_free(row11, lx-1);
219     fvector_free(row12, lx-1);
220     fvector_free(row13, lx-1);
221     fvector_free(row21, lx-1);
222     fvector_free(row22, lx-1);
223     fvector_free(row23, lx-1);
224     fvector_free(row31, lx-1);
225     fvector_free(row32, lx-1);
226     fvector_free(row33, lx-1);
227     return (new_im);
228 }
229 /*
230 Imrect *imz_median(Imrect *im)
231 {
232     return(NULL);
233 }
234 */
235 Imrect *im_median_3D(Imrect *im1, Imrect *im2, Imrect *im3)
236 {
237   if((im1 == NULL) || (im2 == NULL) || (im3 == NULL))
238       {
239         format("\nOne of the images is NULL\n");
240         return(NULL);
241       }
242     if((im1->vtype != im2->vtype) || (im1->vtype != im3->vtype))
243       {
244         format("\nImages are not of the same type\n");
245         return(NULL);
246       }
247 
248     switch(im1->vtype)
249     {
250         case uchar_v:
251             return(NULL);
252         case short_v:
253         case ushort_v:
254         case int_v:
255             return(NULL);
256         case float_v:
257             return(imf_median_3D(im1, im2, im3));
258         case complex_v:
259             return(NULL);
260         default:
261             return(NULL); 
262     }
263 }
264 
265 

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