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

Linux Cross Reference
Tina5/tina-libs/tina/vision/visPgh_analysis2.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/vision/visPgh_analysis2.c,v $
 23  * Date    :  $Date: 2003/10/06 12:29:48 $
 24  * Version :  $Revision: 1.3 $
 25  * CVS Id  :  $Id: visPgh_analysis2.c,v 1.3 2003/10/06 12:29:48 neil Exp $
 26  *
 27  * Author  : Legacy TINA
 28  *
 29  * Notes :
 30  *
 31  *********
 32 */
 33 
 34 #include "visPgh_analysis2.h"
 35 #include <stdio.h>
 36 #include <tina/vision/visPgh_histfuncs.h>
 37 
 38 #include <tina/geometry/geom_LineDef.h>
 39 #include <tina/file/fileUtil_name.h>
 40 #include <tina/geometry/geomDef.h>
 41 #include <tina/math/mathGeom_vec2.h>
 42 #include <tina/math/mathTran_rot2.h>
 43 #include <tina/math/mathGeom_mat2.h>
 44 #include <tina/image/imgGen_alloc.h>
 45 #include <tina/math/mathGeom_geom2.h>
 46 
 47 #define MAXCHIDATA 100000
 48 
 49 /* ---------- Functions ---------- */
 50 
 51 /* Cross matches the histograms in the supplied list,
 52    puts the results into a frequency histogram which
 53    is output to the standard io
 54 
 55    The mean and standard dev. of the histogram is determined
 56    and printed
 57 */
 58 
 59 void pgh_plot_interclass(List *pairs_list, int bins)
 60 {
 61         List *ptr1;
 62         List *ptr2;
 63         Imrect *im1;
 64         Imrect *im2;
 65         double dp;
 66         int frequency_hist[1000]; /*Max number of bins*/ 
 67     double norm_hist[1000];
 68         int bin;
 69         int i;
 70         double area = 0.0;
 71     double mean = 0.0;
 72     double var = 0.0;
 73     double bin_width;
 74 
 75     bin_width = 1.0/(double)bins;
 76 
 77         for(i=0;i<bins;i++) frequency_hist[i]=0;
 78 
 79         for(ptr1=pairs_list;ptr1!=NULL;ptr1=ptr1->next)
 80         {
 81                 im1 = ptr1->to;
 82                 for(ptr2=ptr1->next;ptr2!=NULL;ptr2=ptr2->next)
 83                 {
 84                         im2 = ptr2->to;
 85                         dp = dot_product(im1, im2, im1->vtype, im2->vtype);
 86 
 87                         bin = tina_int((dp*bins));
 88                         if (bin==bins) bin--; /* When dp=1.0 */
 89                         frequency_hist[bin]++;
 90                 }
 91         }
 92 
 93         for(i=0;i<bins;i++) 
 94         {
 95                 area+=(double)frequency_hist[i]*bin_width;
 96         }
 97 
 98     for(i=0;i<bins;i++)
 99     {
100         norm_hist[i] = (double)frequency_hist[i]/area;
101     }
102 
103 
104     /* Calc the mean and variance */
105 
106     for(i=0;i<bins;i++)
107     {
108         mean += norm_hist[i]*bin_width*(i+0.5)*bin_width;
109     }
110 
111     printf("\n#\n# Interclass Distance Histogram\n#\n");
112 
113     system("date '+# %a %h %d'");
114 
115 
116     printf("#\n# mean %f\n", mean);
117 
118     for(i=0;i<bins;i++)
119     {
120         var += (mean-(i+0.5)*(1.0/bins))*(mean-(i+0.5)*(1.0/bins))*
121                            (float)norm_hist[i]*bin_width;
122     }
123 
124     printf("# std  %f\n\n", sqrt(var));
125 
126         for(i=0;i<bins;i++) 
127         {
128                 printf("%f %f\n", (i+0.5)*bin_width,(float)norm_hist[i]);
129         }
130 
131 }
132 
133 
134 void poly_addgaussnoise(List *geom, double sigma)
135 {
136     List *ptr;
137     Line2      *lptr;
138     double x1_err, y1_err, x2_err, y2_err;
139     Vec2 p1, p2;
140 
141     
142     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
143     {
144         lptr=ptr->to;
145 
146         x1_err = rand_normal(0.0, sigma);
147         y1_err = rand_normal(0.0, sigma);
148         x2_err = rand_normal(0.0, sigma);
149         y2_err = rand_normal(0.0, sigma);
150 
151 
152         vec2_x(p1) = (float)(vec2_x(lptr->p1)+x1_err);
153         vec2_y(p1) = (float)(vec2_y(lptr->p1)+y1_err);
154         vec2_x(p2) = (float)(vec2_x(lptr->p2)+x2_err);
155         vec2_y(p2) = (float)(vec2_y(lptr->p2)+y2_err);
156 
157         line2_free(lptr);
158 
159         ptr->to = line2_make(p1, p2, LINE2);
160     }
161 }
162 
163 void write_pgh_vector_file(char *path)
164 {
165 
166     List *model_list;
167     FILE *ofp;
168     List *ptr;
169         Imregion *roi;
170     int lx, ly, ux, uy;
171     int i, j;
172     Imrect *pgh;
173     double data;
174 
175     model_list = pairs_model_pairs_list_get();
176 
177         ofp = fopen(path, "w");
178 
179         if (ofp==NULL)
180         {
181                 printf("Error: Couldn't open '%s'\n", path);
182                 return;
183     }
184 
185 
186     for(ptr=model_list;ptr!=NULL;ptr=ptr->next)
187     {
188         pgh = ptr->to;
189 
190         roi = pgh->region;
191 
192         lx = roi->lx;
193         ly = roi->ly;
194             ux = roi->ux;
195             uy = roi->uy;
196 
197         for(i=ly;i<uy;i++)
198         {
199                 for(j=lx;j<ux;j++)
200                 {
201                 IM_PIX_GET(pgh, i, j, data);
202 
203                         fprintf(ofp, "%f \n", data);
204                 }
205         }
206 
207         fprintf(ofp, "\n");
208     }
209 
210     fclose(ofp);
211 }
212 
213 /* Only creates pghs for geom in list after 'geom' but uses lines from start of 
214    list 'full_geom' */
215 
216 List *geom2pgh_clutter(List *geom, List *full_geom, List *scene_pairs_list, double min_length, double window_r)
217 {
218     List     *ptr;
219     Line2    *lptr;
220     Imrect   *im;
221  
222     if (geom==NULL) return(NULL);
223  
224 /* set the p-field of each line to the lines mid-point */
225  
226     for(ptr=geom; ptr!=NULL;ptr=ptr->next)
227     {
228         lptr = ptr->to;
229         lptr->p = vec2_midpoint(lptr->p1, lptr->p2);
230     }
231  
232 /* If a pairwise list has already been constructed free this to make room
233    for the new list */
234  
235     if (scene_pairs_list!=NULL)
236     {
237         list_rm(scene_pairs_list, im_free);
238         scene_pairs_list = NULL;
239     }
240  
241 /* Now build the histograms and adds them to the scene_pairs_list */
242  
243     for(ptr=geom;ptr!=NULL;ptr=ptr->next)
244     {
245         lptr = ptr->to;
246                 if (lptr->length>min_length)
247                 {
248                         im = build_normalized_pairwise(lptr, NULL, full_geom, window_r);      
249                         scene_pairs_list = ref_addtostart(scene_pairs_list, im, IMRECT); 
250                 }
251  
252     }/*endfor(ptr)*/
253  
254     return scene_pairs_list;
255 }
256 
257 

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