Total Variation Deconvolution using Split Bregman
util_deconv.h
Go to the documentation of this file.
1 
14 #ifndef _UTIL_DECONV_H_
15 #define _UTIL_DECONV_H_
16 
17 #include "tvregopt.h"
18 
19 
49 static void Divergence(num *DivV, int DivWidth, int DivHeight,
50  const numvec2 *V, int Width, int Height, int NumChannels)
51 {
52  int x, y, k;
53 
54  for(k = 0; k < NumChannels; k++)
55  {
56  /* Top-left corner */
57  DivV[0] = V[0].x + V[0].y;
58 
59  /* Top row, x = 1, ..., Width - 2 */
60  for(x = 1; x < Width - 1; x++)
61  DivV[x] = V[x].x - V[x - 1].x + V[x].y;
62 
63  /* Top-right corner */
64  DivV[x] = V[x].y;
65  DivV += DivWidth;
66  V += Width;
67 
68  for(y = 1; y < Height - 1; y++, DivV += DivWidth, V += Width)
69  {
70  /* Left edge */
71  DivV[0] = V[0].x + V[0].y - V[-Width].y;
72 
73  /* Interior */
74  for(x = 1; x < Width - 1; x++)
75  DivV[x] = V[x].x - V[x - 1].x
76  + V[x].y - V[x - Width].y;
77 
78  /* Top-right corner */
79  DivV[x] = V[x].y - V[x - Width].y;
80  }
81 
82  /* Bottom-reft corner */
83  DivV[0] = V[0].x;
84 
85  /* Bottom row, x = 1, ..., Width - 2 */
86  for(x = 1; x < Width - 1; x++)
87  DivV[x] = V[x].x - V[x - 1].x;
88 
89  /* Bottom-right corner */
90  DivV[x] = 0;
91  DivV += ((long)DivWidth)*((long)DivHeight - Height + 1);
92  V += Width;
93  }
94 }
95 
96 
102 static num UUpdate(tvregsolver *S)
103 {
104  num *u = S->u;
105  const num *B = S->B;
106  const int Width = S->Width;
107  const int Height = S->Height;
108  const int PadWidth = S->PadWidth;
109  const int PadHeight = S->PadHeight;
110  const long PadJump = ((long)PadWidth) * (PadHeight - Height);
111  num Norm = 0;
112  int x, y, k;
113 
114  for(k = 0; k < S->NumChannels; k++, B += PadJump)
115  for(y = 0; y < Height; y++, u += Width, B += PadWidth)
116  for(x = 0; x < Width; x++)
117  {
118  num unew = B[x];
119  num Diff = unew - u[x];
120  Norm += Diff * Diff;
121  u[x] = unew;
122  }
123 
124  return (num)sqrt(Norm) / S->fNorm;
125 }
126 
127 
136 static ATTRIBUTE_ALWAYSINLINE int WSymExtension(int N, int i)
137 {
138  while(1)
139  {
140  if(i < 0)
141  i = -i;
142  else if(i >= N)
143  i = (2*N - 2) - i;
144  else
145  return i;
146  }
147 }
148 
149 
158 static ATTRIBUTE_ALWAYSINLINE int PeriodicExtension(int N, int i)
159 {
160  while(1)
161  {
162  if(i < 0)
163  i += N;
164  else if(i >= N)
165  i -= N;
166  else
167  return i;
168  }
169 }
170 
171 #endif /* _UTIL_DECONV_H_ */