TPCCLIB
Loading...
Searching...
No Matches
recutil.c File Reference

General routines for image reconstruction procedures. More...

#include "libtpcrec.h"

Go to the source code of this file.

Functions

void recSinTables (int views, float *sinB, float *sinBrot, float rotation)
void recInterpolateSinogram (float *srcsino, float *newsino, int srcrays, int newrays, int views)
int bit_rev_int (int x, int n)
void set_os_set (int os_sets, int *set_seq)
int recGetStatistics (float *buf, int n, float *osum, float *omin, float *omax, int skip_zero_mins)

Detailed Description

General routines for image reconstruction procedures.

Based on the code written by Sakari Alenius.

Author
Vesa Oikonen

Definition in file recutil.c.

Function Documentation

◆ bit_rev_int()

int bit_rev_int ( int x,
int n )

Bit-reverse for integers in a list, used by set_os_set().

See also
set_os_set()
Returns
the converted integer.
Parameters
xInteger to bit-convert.
nNumber of elements.

Definition at line 77 of file recutil.c.

82 {
83 unsigned char c=(char)x;
84 switch(n) {
85 case 4:
86 c = (c&1)<<1 | (c&2)>>1;
87 break;
88 case 8:
89 c = ((c&1) << 2) | (c&2) | ((c&4) >> 2);
90 break;
91 case 16:
92 c = ((c&1) << 3) | ((c&2) << 1) | ((c&4) >> 1) | ((c&8) >> 3);
93 break;
94 case 32:
95 c = ((c&1)<<4) | ((c&2)<<2) | (c&4) | ((c&8)>>2) | ((c&16)>>4);
96 break;
97 case 64:
98 c = ((c&1)<<5) | ((c&2)<<3) | ((c&4)<<1) | ((c&8)>>1) | ((c&16)>>3) |
99 ((c&32)>>5);
100 break;
101 case 128:
102 c = ((c&1)<<6) | ((c&2)<<4) | ((c&4)<<2) | (c&8) | ((c&16)>>2) |
103 ((c&32)>>4) | ((c&64)>>6);
104 break;
105 default: break;
106 }
107 return((int)c);
108}

Referenced by set_os_set().

◆ recGetStatistics()

int recGetStatistics ( float * buf,
int n,
float * osum,
float * omin,
float * omax,
int skip_zero_mins )

Get the sum and minimum and maximum values from a list of floats, optionally ignoring zero values from the minimum.

Returns
Returns the number of non-zero values.
Parameters
bufPointer to the float array of length n.
nArray size.
osumSum of array values is returned here; enter NULL if not needed.
ominMinimum value is returned here; enter NULL if not needed.
omaxMaximum value is returned here; enter NULL if not needed.
skip_zero_minsSkip zero values when determining the minimum; 1 or 0.

Definition at line 154 of file recutil.c.

167 {
168 int i, nonzeroes=0;
169 float sum, min, max;
170
171 if(osum!=NULL) *osum=nanf("");
172 if(omin!=NULL) *omin=nanf("");
173 if(omax!=NULL) *omax=nanf("");
174
175 i=0; while(i<n && !isfinite(buf[i])) i++;
176 if(i==n) return(0);
177
178 sum=0.0; max=buf[i]; min=nanf("");
179 if(!skip_zero_mins || min!=0.0) min=buf[i];
180 for(; i<n; i++) {
181 if(!isfinite(buf[i])) continue;
182 sum+=buf[i];
183 if(buf[i]>max) max=buf[i];
184 if(buf[i]==0.0) {
185 if(skip_zero_mins) continue;
186 } else {
187 nonzeroes++;
188 }
189 if(isnan(min) || buf[i]<min) min=buf[i];
190 }
191 if(osum!=NULL) *osum=sum;
192 if(omin!=NULL) *omin=min;
193 if(omax!=NULL) *omax=max;
194
195 return(nonzeroes);
196}

Referenced by mrp().

◆ recInterpolateSinogram()

void recInterpolateSinogram ( float * srcsino,
float * newsino,
int srcrays,
int newrays,
int views )

Interpolate sinogram so that the sinogram bin width is the same as the image pixel width.

Parameters
srcsinoSource sinogram data, size of srcrays*views.
newsinoNew interpolated sinogram data calculated here; must be allocated with size newrays*views.
srcraysNumber of rays (bins, columns) in the original sinogram.
newraysNumber of rays (bin, columns) in the new interpolated sinogram.
viewsNumber of projection views (angles, rows) in both sinograms.

Definition at line 37 of file recutil.c.

48 {
49 if(srcrays==newrays) {
50 /* no interpolation needed; just copy and return */
51 for(int i=0; i<views*newrays; i++) newsino[i]=srcsino[i];
52 return;
53 }
54
55 float diff, *sp, *np, oposition, weight;
56 np=newsino;
57 for(int j=0; j<views; j++) {
58 sp=srcsino + j*srcrays;
59 for(int i=0; i<newrays; i++) {
60 oposition=(float)(i*srcrays)/(float)newrays;
61 weight = oposition - (float)(int)oposition;
62 sp=srcsino + j*srcrays + (int)oposition;
63 diff = *(sp+1) - *sp;
64 *np++ = *sp + diff*weight;
65 }
66 }
67 np--; *np=srcsino[srcrays*views - 1];
68 return;
69}

Referenced by mrp(), and trmrp().

◆ recSinTables()

void recSinTables ( int views,
float * sinB,
float * sinBrot,
float rotation )

Pre-compute the sine tables for back-projection.

Parameters
viewsNumber of views (sinogram rows).
sinBArray of sine values, length 3*views/2
sinBrotArray of sine values with rotation, length 3*views/2; enter NULL if not needed.
rotationRotation (degrees).

Definition at line 12 of file recutil.c.

21 {
22 int i, n;
23 n=3*views/2;
24 for(i=0; i<n; i++)
25 sinB[i]=(float)sin((double)i*(M_PI/(double)views));
26 if(sinBrot==NULL) return;
27 double rot=M_PI*rotation/180.0;
28 for(i=0; i<n; i++)
29 sinBrot[i]=(float)sin((double)i*(M_PI/(double)views) + rot);
30}

Referenced by fbp(), imgFBP(), imgMRP(), imgReprojection(), mrp(), reprojection(), and trmrp().

◆ set_os_set()

void set_os_set ( int os_sets,
int * set_seq )

Make the Ordered Subset process order (bit-reversed sequence).

Parameters
os_setsNr of OS sets.
set_seqArray of length os_sets to be filled here.

Definition at line 113 of file recutil.c.

118 {
119 if(os_sets==0) {
120 return;
121 } else if(os_sets==1) {
122 set_seq[0]=0;
123 } else if(os_sets==2) {
124 set_seq[0]=0;
125 set_seq[1]=1;
126 } else if(os_sets==4) {
127 int i=0;
128 set_seq[i++]=0; set_seq[i++]=2; set_seq[i++]=1; set_seq[i++]=3;
129 return;
130 } if(os_sets==8) {
131 int i=0;
132 set_seq[i++]=0; set_seq[i++]=4; set_seq[i++]=2; set_seq[i++]=6;
133 set_seq[i++]=1; set_seq[i++]=5; set_seq[i++]=3; set_seq[i++]=7;
134 return;
135 } else if(os_sets==16) {
136 int i=0;
137 set_seq[i++]=0; set_seq[i++]=8; set_seq[i++]=4; set_seq[i++]=12;
138 set_seq[i++]=2; set_seq[i++]=10; set_seq[i++]=6; set_seq[i++]=14;
139 set_seq[i++]=1; set_seq[i++]=9; set_seq[i++]=5; set_seq[i++]=13;
140 set_seq[i++]=3; set_seq[i++]=11; set_seq[i++]=7; set_seq[i++]=15;
141 return;
142 } else {
143 set_seq[0]=0; set_seq[1]=1;
144 for(int i=1; i<os_sets; i++) set_seq[i]=bit_rev_int(i, os_sets);
145 }
146}
int bit_rev_int(int x, int n)
Definition recutil.c:77

Referenced by mrp(), and trmrp().