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

Linux Cross Reference
Tina4/src/tools/nmr-segment/gaus_tri_gen.c

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

  1 #include <stdio.h>
  2 #include <sys/param.h>
  3 #include <string.h>
  4 #include <tina/sys.h>
  5 #include <tina/sysfuncs.h>
  6 #include <tina/math.h>
  7 #include <tina/mathfuncs.h>
  8 #include <tina/vision.h>
  9 #include <tina/visionfuncs.h>
 10 #include <tina/file.h>
 11 #include <tina/filefuncs.h>
 12 #include <tina/file_gen.h>
 13 #include <tina/tv.h>
 14 #include <tina/tvfuncs.h>
 15 #include <tina/draw.h>
 16 #include <tina/drawfuncs.h>
 17 #include <tina/toolsfuncs.h>
 18 #include <tina/tw_Xfuncs.h>
 19 #include <tina/hist_funcs.h>
 20 
 21 extern Prof1 *csfgmtri;
 22 extern Prof1 *csfgmgaus;
 23 extern Prof1 *csfgmlookup;
 24 extern Prof1 *gmwmtri;
 25 extern Prof1 *gmwmgaus;
 26 extern Prof1 *gmwmlookup;
 27 double pi = 3.14159;
 28 
 29 void csfgmtrigen (double start, double end, double height, int test_flag)
 30 /* Generates a triangle of the required height and length */
 31 {
 32    int i, slices, start_i, end_i, id=11;
 33    double progfac;
 34    shistogram *trihist;
 35    float fill;
 36    Tv *imcalc_graph_tv_get();
 37    void hist_fit(shistogram *trihist);
 38 
 39    slices = (int)((end-start)+1);
 40    start_i = tina_int(start);
 41    end_i = tina_int(end);
 42    csfgmtri = prof1_alloc(start_i, end_i, float_v);
 43    progfac = height / (double)slices;
 44    csfgmtri->el.float_v[start_i] = 0.0;
 45 
 46    for (i=start_i+1; i<end_i; i++)
 47       csfgmtri->el.float_v[i] = csfgmtri->el.float_v[i-1] + (float)progfac;
 48 
 49    if (test_flag==1)
 50    {
 51       format("CSF GM TRI Gen: Start Value: %f\n",start);
 52       format("CSF GM TRI Gen: End Value: %f\n",end);
 53       format("CSF GM TRI Gen: Height: %f\n",height);
 54       format("CSF GM TRI Gen: Slices Required: %d\n",slices);
 55       format("CSF GM TRI Gen: Progression Factor: %f\n",progfac);
 56 /*
 57       format("CSF GM Triangle Values are as follows:\n");
 58       for (i=start_i;i<end_i;i++)
 59          format("%d\t%f\n",i,csfgmtri->el.float_v[i]);
 60 */
 61       trihist = hbook1(id, "Triangle", (float)start_i, (float)end_i, slices);
 62 
 63       for (i=start_i; i<end_i; i++)
 64          fill = hfill1(trihist,(float)(i), csfgmtri->el.float_v[i]);
 65 
 66       graph_hfit(imcalc_graph_tv_get(), trihist);
 67 
 68       hfree(trihist);
 69    }
 70 }
 71 
 72 void gmwmtrigen (double start, double end, double height, int test_flag)
 73 /* Generates a triangle of the required height and length */
 74 {
 75    int i, slices, start_i, end_i, id=11;
 76    double progfac;
 77    shistogram *trihist;
 78    float fill;
 79    Tv *imcalc_graph_tv_get();
 80    void hist_fit(shistogram *trihist);
 81 
 82    slices = (int)((end-start)+1);
 83    start_i = tina_int(start);
 84    end_i = tina_int(end);
 85    gmwmtri = prof1_alloc(start_i, end_i, float_v);
 86    progfac = height / (double)slices;
 87    gmwmtri->el.float_v[start_i] = 0.0;
 88 
 89    for (i=start_i+1; i<end_i; i++)
 90       gmwmtri->el.float_v[i] = gmwmtri->el.float_v[i-1] + (float)progfac;
 91 
 92    if (test_flag==1)
 93    {
 94       format("GM WM TRI Gen: Start Value: %f\n",start);
 95       format("GM WM TRI Gen: End Value: %f\n",end);
 96       format("GM WM TRI Gen: Height: %f\n",height);
 97       format("GM WM TRI Gen: Slices Required: %d\n",slices);
 98       format("GM WM TRI Gen: Progression Factor: %f\n",progfac);
 99 /*
100       format("GM WM Triangle Values are as follows:\n");
101       for (i=start_i;i<end_i;i++)
102          format("%d\t%f\n",i,gmwmtri->el.float_v[i]);
103 */
104       trihist = hbook1(id, "Triangle", (float)start_i, (float)end_i, slices);
105 
106       for (i=start_i; i<end_i; i++)
107          fill = hfill1(trihist,(float)(i), gmwmtri->el.float_v[i]);
108 
109       graph_hfit(imcalc_graph_tv_get(), trihist);
110 
111       hfree(trihist);
112    }
113 }
114 
115 Prof1 *gausgen (double stddev, int test_flag)
116 {
117    int i, peakslice, id=12, slices; /* Fixed number of slices */
118    double total=0.0;
119    shistogram *gaushist;
120    float fill;
121    Tv *imcalc_graph_tv_get();
122    void hist_fit(shistogram *gaushist);
123    Prof1 *gmwmgaus=NULL;
124 
125    /* Width of each slice - 10 slices per stddev */
126    slices = tina_int(8.1*stddev);
127    gmwmgaus = prof1_alloc(-slices/2, slices/2, float_v);
128 
129    for (i=-slices/2; i<slices/2; i++)
130    {
131       gmwmgaus->el.float_v[i] = exp(-(i*i)/(2.0*sqr(stddev)));
132       total += gmwmgaus->el.float_v[i];
133    }
134    for (i=-slices/2; i<slices/2; i++)
135    {
136       gmwmgaus->el.float_v[i] /= total;
137    }
138 
139 
140 
141    if (test_flag==1)
142    {
143       format("GM WM GAUS Gen: Standard Deviation: %f\n",stddev);
144       format("GM WM GAUS Gen: Slices: %d\n",slices);
145 /*
146       format("GM WM Gaussian Values are as follows:\n");
147       for (i=0;i<slices;i++)
148          format("%d\t%f\n",i,gmwmgaus->el.float_v[i]);
149 */
150       gaushist = hbook1(id, "Gaussian", 0, slices, slices);
151 
152       for (i=0; i<slices; i++)
153          fill = hfill1(gaushist,(float)(i), gmwmgaus->el.float_v[i]);
154 
155       graph_hfit(imcalc_graph_tv_get(), gaushist);
156 
157       hfree(gaushist);
158    }
159    return(gmwmgaus);
160 
161 }
162 
163 Prof1 *convolve (Prof1 *arr1, Prof1 *arr2, int test_flag)
164 /* 1D Convolution of two predefined arrays - results in a new longer array*/
165 /* arr1 is assumed as the convolution mask */
166 {
167    Prof1 *conv, *tempconv;
168    int newlength, arr1len, arr2len, id=13;
169    int startval, endval, offset;
170    int i=0, totlen=0, p, q;
171    float convval=0.0, fill;
172    shistogram *trigaush;
173    Tv *imcalc_graph_tv_get();
174 
175    arr1len = (arr1->n2) - (arr1->n1);
176    arr2len = (arr2->n2) - (arr2->n1);
177    newlength = (2*arr1len) + arr2len;
178 
179    startval = (arr2->n1) - arr1len;
180    endval = (arr2->n2) + arr1len;
181 
182    conv = prof1_alloc(startval, endval, float_v);
183    tempconv = prof1_alloc(startval, endval, float_v);
184 
185    for (i=startval;i<endval;i++)
186       tempconv->el.float_v[i]=0.0;
187    for (i=arr2->n1;i<arr2->n2;i++)
188       tempconv->el.float_v[i]=arr2->el.float_v[i];
189 
190    offset = -arr1->n1;
191 
192    for (p=(arr2->n1-arr1->n2);p<(arr2->n2-arr1->n1);p++)
193    {
194       
195       convval=0.0; 
196       for (q=arr1->n1;q<arr1->n2;q++)
197          convval += arr1->el.float_v[q] * tempconv->el.float_v[p+q];
198       conv->el.float_v[p] = convval; /* Set the value on target */
199    }
200 
201    if (test_flag==1)
202    {
203       format("CONVOLVE: ARR 1 n1: %d\n",arr1->n1);
204       format("CONVOLVE: ARR 1 n2: %d\n",arr1->n2);
205       format("CONVOLVE: ARR 2 n1: %d\n",arr2->n1);
206       format("CONVOLVE: ARR 2 n2: %d\n",arr2->n2);
207       format("CONVOLVE: ARR 1 length: %d\n",arr1len);
208       format("CONVOLVE: ARR 2 length: %d\n",arr2len);
209       format("CONVOLVE: New Length: %d\n",newlength);
210       format("CONVOLVE: Start Value of Prof: %d\n",startval);
211       format("CONVOLVE: End Value of Prof: %d\n",endval);
212       trigaush = hbook1(id, "Gaussian Triangle",(float)startval,(float)endval,(endval-startval));
213 
214       for (i=startval; i<endval; i++)
215          fill = hfill1(trigaush,(float)(i), conv->el.float_v[i]);
216 
217       graph_hfit(imcalc_graph_tv_get(), trigaush);
218 
219       hfree(trigaush);
220    }
221 
222    return (conv);
223 }
224 
225 double trilookup (Prof1 *array, double value, int test_flag)
226 /* A function to lookup the required value */
227 {
228    double newval, xfac;
229    int startval, endval, slices, slice;
230 
231    startval = array->n1;
232    endval = array->n2;
233    slices = endval-startval;
234 
235    if(value<=(double)(startval))
236       return (0.0);
237 
238    if(value>=(double)(endval-1))
239       return (0.0);
240 
241    slice = tina_int(value);
242    xfac = value - slice;
243    newval = xfac*array->el.float_v[slice]
244           +(1.0-xfac)*array->el.float_v[slice+1];
245 
246 
247    if (test_flag==1)
248    {
249       format("TRI LOOKUP: Value to LookUp: %f\n",value);
250       format("TRI LOOKUP: Start Value of LookUp Array: %d\n",startval);
251       format("TRI LOOKUP: End Value of LookUp Array: %d\n",endval);
252       format("TRI LOOKUP: Slices in LookUp Array: %d\n",slices);
253       format("TRI LOOKUP: Looked Up Value: %f\n",newval);
254    }
255 
256    return (newval);
257 }
258 

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