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

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

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