8 #ifndef VIGRA_SHOCKFILTER_HXX
9 #define VIGRA_SHOCKFILTER_HXX
11 #include "basicimage.hxx"
12 #include "convolution.hxx"
13 #include "tensorutilities.hxx"
89 template <
class SrcIterator,
class SrcAccessor,
90 class Src2Iterator,
class Src2Accessor,
91 class DestIterator,
class DestAccessor>
92 void upwindImage(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
93 Src2Iterator s2_ul, Src2Accessor s2_acc,
94 DestIterator d_ul, DestAccessor d_acc,
95 float upwind_factor_h)
99 typedef typename SrcIterator::difference_type DiffType;
101 DiffType shape = s_lr - s_ul;
103 typedef typename SrcAccessor::value_type SrcType;
104 typedef typename DestAccessor::value_type ResultType;
106 SrcType upper, lower, left, right, center;
110 for(
int y=0; y<shape[1]; ++y)
112 for(
int x=0; x<shape[0]; ++x)
114 upper = s_acc(s_ul + Diff2D(x, max(0, y-1)));
115 lower = s_acc(s_ul + Diff2D(x, min(shape[1]-1, y+1)));
116 left = s_acc(s_ul + Diff2D(max(0, x-1), y));
117 right = s_acc(s_ul + Diff2D(min(shape[0]-1, x+1), y));
118 center = s_acc(s_ul + Diff2D(x, y));
120 if(s2_acc(s2_ul+Diff2D(x,y))<0)
122 fx = max(max(right - center, left - center), 0.0f);
123 fy = max(max(lower - center, upper - center), 0.0f);
124 d_acc.set (center + upwind_factor_h*
sqrt( fx*fx + fy*fy), d_ul+Diff2D(x,y));
128 fx = max(max(center - right, center - left), 0.0f);
129 fy = max(max(center - lower, center - upper), 0.0f);
130 d_acc.set (center - upwind_factor_h*
sqrt( fx*fx + fy*fy), d_ul+Diff2D(x,y));
136 template <
class SrcIterator,
class SrcAccessor,
137 class Src2Iterator,
class Src2Accessor,
138 class DestIterator,
class DestAccessor>
139 inline void upwindImage(triple<SrcIterator, SrcIterator, SrcAccessor> s,
140 pair<Src2Iterator, Src2Accessor> s2,
141 pair<DestIterator, DestAccessor> d,
142 float upwind_factor_h)
144 upwindImage(s.first, s.second, s.third, s2.first, s2.second, d.first, d.second, upwind_factor_h);
147 template <
class T1,
class S1,
150 inline void upwindImage(MultiArrayView<2, T1, S1>
const & src,
151 MultiArrayView<2, T2, S2>
const & src2,
152 MultiArrayView<2, T3, S3> dest,
153 float upwind_factor_h)
155 vigra_precondition(src.shape() == src2.shape() && src.shape() == dest.shape(),
156 "vigra::upwindImage(): shape mismatch between input and output.");
232 template <
class SrcIterator,
class SrcAccessor,
233 class DestIterator,
class DestAccessor>
234 void shockFilter(SrcIterator s_ul, SrcIterator s_lr, SrcAccessor s_acc,
235 DestIterator d_ul, DestAccessor d_acc,
236 float sigma,
float rho,
float upwind_factor_h,
237 unsigned int iterations)
240 typedef typename SrcIterator::difference_type DiffType;
241 DiffType shape = s_lr - s_ul;
243 unsigned int w = shape[0],
248 FImage hxx(w,h), hxy(w,h), hyy(w,h), temp(w,h) ,result(w,h);
250 float c, s, v_xx, v_xy, v_yy;
252 copyImage(srcIterRange(s_ul, s_lr, s_acc), destImage(result));
254 for(
unsigned int i = 0; i<iterations; ++i)
260 destImage(hxx), destImage(hxy), destImage(hyy), sigma);
262 for(
int y=0; y<shape[1]; ++y)
264 for(
int x=0; x<shape[0]; ++x)
266 c =
cos(eigen(x,y)[2]);
267 s =
sin(eigen(x,y)[2]);
272 hxx(x,y) = c*c*v_xx + 2*c*s*v_xy + s*s*v_yy;
275 upwindImage(srcImageRange(result),srcImage(hxx), destImage(temp), upwind_factor_h);
279 copyImage(srcImageRange(result), destIter(d_ul, d_acc));
282 template <
class SrcIterator,
class SrcAccessor,
283 class DestIterator,
class DestAccessor>
284 inline void shockFilter(triple<SrcIterator, SrcIterator, SrcAccessor> s,
285 pair<DestIterator, DestAccessor> d,
286 float sigma,
float rho,
float upwind_factor_h,
287 unsigned int iterations)
289 shockFilter(s.first, s.second, s.third,
291 sigma, rho, upwind_factor_h,
295 template <
class T1,
class S1,
297 inline void shockFilter(MultiArrayView<2, T1, S1>
const & src,
298 MultiArrayView<2, T2, S2> dest,
299 float sigma,
float rho,
float upwind_factor_h,
300 unsigned int iterations)
302 vigra_precondition(src.shape() == dest.shape(),
303 "vigra::shockFilter(): shape mismatch between input and output.");
304 shockFilter(srcImageRange(src),
306 sigma, rho, upwind_factor_h,
312 #endif //VIGRA_SHOCKFILTER_HXX
void upwindImage(...)
This function calculates discrete upwinding scheme proposed by J. Weickert (2002) in Coherence-Enhanc...
BasicImage< float > FImage
Definition: stdimage.hxx:143
linalg::TemporaryMatrix< T > sin(MultiArrayView< 2, T, C > const &v)
BasicImage< TinyVector< float, 3 > > FVector3Image
Definition: stdimage.hxx:286
void tensorEigenRepresentation(...)
Calculate eigen representation of a symmetric 2x2 tensor.
void hessianMatrixOfGaussian(...)
Filter image with the 2nd derivatives of the Gaussian at the given scale to get the Hessian matrix...
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.
void copyImage(...)
Copy source image into destination image.
void structureTensor(...)
Calculate the Structure Tensor for each pixel of and image, using Gaussian (derivative) filters...
linalg::TemporaryMatrix< T > cos(MultiArrayView< 2, T, C > const &v)
SquareRootTraits< FixedPoint< IntBits, FracBits > >::SquareRootResult sqrt(FixedPoint< IntBits, FracBits > v)
square root.
Definition: fixedpoint.hxx:616