oln::convol::fast Namespace Reference

Convolution algorithms. More...


Namespaces

namespace  internal
 Internal namespace.

Functions

template<class DestValue, class I, class J>
mute< I, DestValue >::ret convolve (const abstract::image< I > &input, const abstract::image< J > &k)
 Perform a convolution of two images.
template<class DestValue, class I, class Info, class Win>
mute< I, DestValue >::ret convolve (const abstract::image< I > &input, const mlc::array2d< Info, Win > &arr)
 Perform a convolution of an image and a window.
template<class C, class B, class I, class BE>
mute< I, typename convoutput<
C, B, typename mlc::exact<
I >::ret::value_type >::ret
>::ret 
gaussian (const convert::abstract::conversion< C, B > &input_conv, const abstract::image< I > &in, ntg::float_s sigma, const abstract::behavior< BE > &behavior)
 Gaussian filter.
template<class C, class B, class I, class BE>
mute< I, typename convoutput<
C, B, typename mlc::exact<
I >::ret::value_type >::ret
>::ret 
gaussian_derivative (const convert::abstract::conversion< C, B > &input_conv, const abstract::image< I > &in, ntg::float_s sigma, const abstract::behavior< BE > &behavior)
 Derivative gaussian filter.
template<class C, class B, class I, class BE>
mute< I, typename convoutput<
C, B, typename mlc::exact<
I >::ret::value_type >::ret
>::ret 
gaussian_second_derivative (const convert::abstract::conversion< C, B > &input_conv, const abstract::image< I > &in, ntg::float_s sigma, const abstract::behavior< BE > &behavior)
 Second derivative gaussian filter.
template<class I, class BE>
oln::mute< I >::ret gaussian (const abstract::image< I > &in, ntg::float_s sigma, const abstract::behavior< BE > &behavior)
 Gaussian filter with a default conversion.
template<class I, class BE>
oln::mute< I >::ret gaussian_derivative (const abstract::image< I > &in, ntg::float_s sigma, const abstract::behavior< BE > &behavior)
 Derivative gaussian filter with a default conversion.
template<class I, class BE>
oln::mute< I >::ret gaussian_second_derivative (const abstract::image< I > &in, ntg::float_s sigma, const abstract::behavior< BE > &behavior=mirror_behavior<>())
 Second derivative gaussian filter with a default conversion.
template<class I>
oln::mute< I >::ret gaussian (const abstract::image< I > &in, ntg::float_s sigma)
 Gaussian filter with a default conversion and a default behavior.
template<class I>
oln::mute< I >::ret gaussian_derivative (const abstract::image< I > &in, ntg::float_s sigma)
 Derivative gaussian filter with a default conversion and a default behavior.
template<class I>
oln::mute< I >::ret gaussian_second_derivative (const abstract::image< I > &in, ntg::float_s sigma)
 Second derivative gaussian filter with a default conversion and a default behavior.


Detailed Description

Convolution algorithms.

The algorithms you can find here are fast. This mean these ones are evolved versions for large structuring elements.


Function Documentation

template<class DestValue, class I, class Info, class Win>
mute<I, DestValue>::ret oln::convol::fast::convolve ( const abstract::image< I > &  input,
const mlc::array2d< Info, Win > &  arr 
)

Perform a convolution of an image and a window.

Parameters:
DestValue Data type of the output image you want.
I Exact type of the input image.
Info Informations about the array.
Win Data type of the array.
Todo:
FIXME: don't use array1d, ..., arraynd.

Definition at line 212 of file fast_convolution.hh.

00214       {
00215         return convolve<DestValue>(input, static_cast< image2d<Win> >(arr));
00216         // FIXME: Should be abstract::w_window<T_arr>.  Adjust #include once done.
00217       }

template<class DestValue, class I, class J>
mute<I, DestValue>::ret oln::convol::fast::convolve ( const abstract::image< I > &  input,
const abstract::image< J > &  k 
)

Perform a convolution of two images.

Parameters:
DestValue Data type of the output image you want.
I Exact type of the input image.
J Exact type of the input image (convolution kernel).
Todo:
FIXME: the kernel could be bigger than the image.
Todo:
FIXME: supports only 2 dimensions (like the fft).
The algorithm is just the convolution theorem application.

This example compute a fast gaussian convolution :

 #include <oln/basics2d.hh>
 #include <oln/convol/slow_gaussian.hh>
 #include <oln/convol/fast_convolution.hh>

 using namespace oln;
 using namespace ntg;

 int main() {
 #ifdef HAVE_FFTW
   image2d<int_u8> src(IMG_IN "lena.pgm");
   float_d sigma = 2.5;
   float_d radius = 3;
   image2d<float_d> k = convol::slow::gaussian_kernel<2>::kernel(sigma, radius);
   image2d<float_d> f_src(src.size());
   oln_iter_type_(image2d<float_d>) i(src);
   for_all(i)
     f_src[i] = float_d(src[i]);
   image2d<float_d> tmp = convol::fast::convolve<float_d>(f_src, k);
   for_all(i)
     src[i] = int_u8(tmp[i]);
   save(src, IMG_OUT "oln_convol_fast_convolve.pgm");
 #endif
 }
lena_pgm.png
=>
oln_convol_fast_convolve.pgm

Definition at line 126 of file fast_convolution.hh.

References oln::abstract::image< Exact >::border(), oln::convol::fast::internal::center(), mlc::eq< i, j >::ensure(), mlc_hierarchy::any_with_diamond< Exact >::exact(), oln::replicate_bhv(), and oln::abstract::image< Exact >::size().

00128       {
00129 # ifdef HAVE_FFTW
00130         mlc::eq<I::dim, J::dim>::ensure();
00131         mlc::eq<I::dim, 2>::ensure();
00132 
00133         oln_size_type(I) big_size;
00134         coord width_input = 0;
00135         coord width_k = 0;
00136         for (unsigned i = 0; i < I::dim; i++)
00137         {
00138           big_size.nth(i) = input.size().nth(i) + k.size().nth(i) - 1;
00139           if (width_input < k.size().nth(i) - 1)
00140           {
00141             width_input = k.size().nth(i) - 1;
00142             width_k = input.size().nth(i) - 1;
00143           }
00144         }
00145         big_size.border() = input.border();
00146 
00147         const morpher::border_morpher< const image2d<oln_value_type(I)>, replicate_behavior<> >
00148           big_input(input.exact(), (width_input + 1) / 2, replicate_bhv());
00149 
00150         J big_k(big_size);
00151         oln_iter_type(J) big_iter(big_k);
00152         for_all(big_iter)
00153           big_k[big_iter] = 0;
00154         oln_iter_type(J) k_iter(k);
00155         oln_iter_type(J) input_iter(input);
00156 
00157         morpher::piece_morpher<J>
00158           piece_k(big_k, internal::center<J, J, oln_dpoint_type(J)>(big_k, k), k.size());
00159 
00160         for_all(k_iter)
00161           piece_k[k_iter] = k[k_iter];
00162 
00164         I big_input_(big_input.size());
00165         for_all(big_iter)
00166           big_input_[big_iter] = big_input[big_iter];
00167 
00168         transforms::fft<oln_value_type(I), ntg::rect> tr_input(big_input_.exact());
00169         transforms::fft<oln_value_type(J), ntg::rect> tr_k(big_k.exact());
00170 
00171         tr_input.transform();
00172         typename mute<I, ntg::cplx<ntg::rect, ntg::float_d> >::ret&
00173           Input = tr_input.transformed_image();
00174         const typename mute<J, ntg::cplx<ntg::rect, ntg::float_d> >::ret
00175           K = tr_k.transform();
00176 
00177         for_all(big_iter) {
00178           Input[big_iter] *= K[big_iter];
00179           // Scale.
00180           Input[big_iter] *= Input.nrows() * Input.ncols();
00181         }
00182 
00183         typename mute<I, DestValue>::ret big_output = tr_input.shift_transform_inv();
00184         typename mute<I, DestValue>::ret output(input.size());
00185 
00186         morpher::piece_morpher<J>
00187           piece_output(big_output, internal::center<J, J, oln_dpoint_type(J)>(big_input_, input), input.size());
00188         for_all(input_iter)
00189             output[input_iter] = piece_output[input_iter];
00190 
00191         return output;
00192 # else
00193         assert(0);
00194 # endif // !HAVE_FFTW
00195       }

template<class I>
oln::mute< I >::ret oln::convol::fast::gaussian ( const abstract::image< I > &  in,
ntg::float_s  sigma 
) [inline]

Gaussian filter with a default conversion and a default behavior.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Warning:
The content of the border is the mirror of the image.
Parameters:
I Exact type of the image.
 #include <oln/basics2d.hh>
 #include <oln/convol/fast_gaussian.hh>
 #include <oln/core/behavior.hh>
 #include <ntg/all.hh>
 int main()
 {
   typedef oln::image2d<ntg::int_u8>    im_type;

   im_type      im1(oln::load(IMG_IN "lena256.pgm"));

   oln::save(oln::convol::fast::gaussian(im1, 2),
             IMG_OUT "oln_convol_fast_gaussian_default.pbm");
   return 0;
 }

lena256_pgm.png
=>
oln_convol_fast_gaussian_default.png

Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 326 of file fast_gaussian.hh.

References gaussian(), and oln::mirror_bhv().

00327       { return gaussian(convert::force<oln_value_type(I)>(), in, sigma,
00328                         mirror_bhv()); }

template<class I, class BE>
oln::mute< I >::ret oln::convol::fast::gaussian ( const abstract::image< I > &  in,
ntg::float_s  sigma,
const abstract::behavior< BE > &  behavior 
) [inline]

Gaussian filter with a default conversion.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Parameters:
I Exact type of the image.
BE Exact type of the behavior.
 #include <oln/basics2d.hh>
 #include <oln/convol/fast_gaussian.hh>
 #include <oln/core/behavior.hh>
 #include <ntg/all.hh>
 int main()
 {
   typedef oln::image2d<ntg::int_u8>    im_type;

   im_type      im1(oln::load(IMG_IN "lena256.pgm"));

   oln::save(oln::convol::fast::gaussian(im1, 2,
                                         oln::value_behavior<oln_value_type_(im_type)>(0)),
             IMG_OUT "oln_convol_fast_gaussian.pbm");
   return 0;
 }

lena256_pgm.png
=>
oln_convol_fast_gaussian.png

Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 180 of file fast_gaussian.hh.

References gaussian().

00182       { return gaussian(convert::force<oln_value_type(I)>(), in, sigma,
00183                         behavior); }

template<class C, class B, class I, class BE>
mute< I, typename convoutput< C, B, oln_value_type(I)>::ret >::ret oln::convol::fast::gaussian ( const convert::abstract::conversion< C, B > &  input_conv,
const abstract::image< I > &  in,
ntg::float_s  sigma,
const abstract::behavior< BE > &  behavior 
)

Gaussian filter.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Parameters:
C Exact type of the conversion object.
B Base type of the conversion object.
I Exact type of the image.
BE Exact type of the behavior.
Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 337 of file fast_gaussian.hxx.

References oln::convol::fast::internal::gaussian_common_().

Referenced by gaussian().

00340       {
00341         internal::recursivefilter_coef_<float>
00342           coef(1.68f, 3.735f,
00343                1.783f, 1.723f,
00344                -0.6803f, -0.2598f,
00345                0.6318f, 1.997f,
00346                sigma,
00347                internal::recursivefilter_coef_<float>::DericheGaussian);
00348 
00349         return internal::gaussian_common_(c, in, coef, sigma, behavior);
00350       }

template<class I>
oln::mute< I >::ret oln::convol::fast::gaussian_derivative ( const abstract::image< I > &  in,
ntg::float_s  sigma 
) [inline]

Derivative gaussian filter with a default conversion and a default behavior.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Warning:
The content of the border is the mirror of the image.
Parameters:
I Exact type of the image.
BE Exact type of the behavior.
 #include <oln/basics2d.hh>
 #include <oln/convol/fast_gaussian.hh>
 #include <oln/core/behavior.hh>
 #include <ntg/all.hh>
 int main()
 {
   typedef oln::image2d<ntg::int_u8>    im_type;

   im_type      im1(oln::load(IMG_IN "lena256.pgm"));

   oln::save(oln::convol::fast::gaussian_derivative(im1, 2),
             IMG_OUT "oln_convol_fast_gaussian_derivative_default.pbm");
   return 0;
 }

lena256_pgm.png
=>
oln_convol_fast_gaussian_derivative_default.png

Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 376 of file fast_gaussian.hh.

References gaussian_derivative(), and oln::mirror_bhv().

00377       { return gaussian_derivative(convert::force<oln_value_type(I)>(), in, sigma,
00378                                    mirror_bhv()); }

template<class I, class BE>
oln::mute< I >::ret oln::convol::fast::gaussian_derivative ( const abstract::image< I > &  in,
ntg::float_s  sigma,
const abstract::behavior< BE > &  behavior 
) [inline]

Derivative gaussian filter with a default conversion.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Parameters:
I Exact type of the image.
BE Exact type of the behavior.
 #include <oln/basics2d.hh>
 #include <oln/convol/fast_gaussian.hh>
 #include <oln/core/behavior.hh>
 #include <ntg/all.hh>
 int main()
 {
   typedef oln::image2d<ntg::int_u8>    im_type;

   im_type      im1(oln::load(IMG_IN "lena256.pgm"));

   oln::save(oln::convol::fast::gaussian_derivative(im1, 2,
                                         oln::value_behavior<oln_value_type_(im_type)>(0)),
             IMG_OUT "oln_convol_fast_gaussian_derivative.pbm");
   return  0;
 }

lena256_pgm.png
=>
oln_convol_fast_gaussian_derivative.png

Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 228 of file fast_gaussian.hh.

References gaussian_derivative().

00230       { return gaussian_derivative(convert::force<oln_value_type(I)>(), in, sigma,
00231                                    behavior); }

template<class C, class B, class I, class BE>
mute< I, typename convoutput< C, B, oln_value_type(I)>::ret >::ret oln::convol::fast::gaussian_derivative ( const convert::abstract::conversion< C, B > &  input_conv,
const abstract::image< I > &  in,
ntg::float_s  sigma,
const abstract::behavior< BE > &  behavior 
)

Derivative gaussian filter.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Parameters:
C Exact type of the conversion object.
B Base type of the conversion object.
I Exact type of the image.
BE Exact type of the behavior.
Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 354 of file fast_gaussian.hxx.

References oln::convol::fast::internal::gaussian_common_().

Referenced by gaussian_derivative().

00357       {
00358         internal::recursivefilter_coef_<float>
00359           coef(-0.6472f, -4.531f,
00360                1.527f, 1.516f,
00361                0.6494f, 0.9557f,
00362                0.6719f, 2.072f,
00363                sigma,
00364                internal::recursivefilter_coef_<float>
00365                ::DericheGaussianFirstDerivative);
00366 
00367         return internal::gaussian_common_(c, in, coef, sigma, behavior);
00368       }

template<class I>
oln::mute< I >::ret oln::convol::fast::gaussian_second_derivative ( const abstract::image< I > &  in,
ntg::float_s  sigma 
) [inline]

Second derivative gaussian filter with a default conversion and a default behavior.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Warning:
The content of the border is the mirror of the image.
Parameters:
I Exact type of the image.
BE Exact type of the behavior.
 #include <oln/basics2d.hh>
 #include <oln/convol/fast_gaussian.hh>
 #include <oln/core/behavior.hh>
 #include <ntg/all.hh>
 int main()
 {
   typedef oln::image2d<ntg::int_u8>    im_type;

   im_type      im1(oln::load(IMG_IN "lena256.pgm"));

   oln::save(oln::convol::fast::gaussian_second_derivative(im1, 2),
             IMG_OUT "oln_convol_fast_gaussian_second_derivative_default.pbm");
   return 0;
 }

lena256_pgm.png
=>
oln_convol_fast_gaussian_second_derivative_default.png

Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 426 of file fast_gaussian.hh.

References gaussian_second_derivative(), and oln::mirror_bhv().

00427       { return gaussian_second_derivative(convert::force<oln_value_type(I)>(), in, sigma,
00428                                           mirror_bhv()); }

template<class I, class BE>
oln::mute< I >::ret oln::convol::fast::gaussian_second_derivative ( const abstract::image< I > &  in,
ntg::float_s  sigma,
const abstract::behavior< BE > &  behavior = mirror_behavior<>() 
) [inline]

Second derivative gaussian filter with a default conversion.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Parameters:
I Exact type of the image.
BE Exact type of the behavior.
 #include <oln/basics2d.hh>
 #include <oln/convol/fast_gaussian.hh>
 #include <oln/core/behavior.hh>
 #include <ntg/all.hh>
 int main()
 {
   typedef oln::image2d<ntg::int_u8>    im_type;

   im_type      im1(oln::load(IMG_IN "lena256.pgm"));

   oln::save(oln::convol::fast::gaussian_second_derivative(im1, 2,
                                         oln::value_behavior<oln_value_type_(im_type)>(0)),
             IMG_OUT "oln_convol_fast_gaussian_second_derivative.pbm");
   return 0;
 }

lena256_pgm.png
=>
oln_convol_fast_gaussian_second_derivative.png

Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 275 of file fast_gaussian.hh.

References gaussian_second_derivative().

00278       { return gaussian_second_derivative(convert::force<oln_value_type(I)>(),
00279                                           in, sigma, behavior); }

template<class C, class B, class I, class BE>
mute< I, typename convoutput< C, B, oln_value_type(I)>::ret >::ret oln::convol::fast::gaussian_second_derivative ( const convert::abstract::conversion< C, B > &  input_conv,
const abstract::image< I > &  in,
ntg::float_s  sigma,
const abstract::behavior< BE > &  behavior 
)

Second derivative gaussian filter.

Gaussian filter implementation from "Recursively implementing the gaussian and its derivatives" Deriche 93 INRIA REPORT (num RR-1893).

Parameters:
C Exact type of the conversion object.
B Base type of the conversion object.
I Exact type of the image.
BE Exact type of the behavior.
Warning:
If sigma is big enough, the result may differ a little bit with the -O3 flag of g++.

Definition at line 372 of file fast_gaussian.hxx.

References oln::convol::fast::internal::gaussian_common_().

Referenced by gaussian_second_derivative().

00375       {
00376         internal::recursivefilter_coef_<float>
00377           coef(-1.331f, 3.661f,
00378                1.24f, 1.314f,
00379                0.3225f, -1.738f,
00380                0.748f, 2.166f,
00381                sigma,
00382                internal::recursivefilter_coef_<float>
00383                ::DericheGaussianSecondDerivative);
00384 
00385         return internal::gaussian_common_(c, in, coef, sigma, behavior);
00386       }


Generated on Tue Feb 20 20:27:00 2007 for Olena by  doxygen 1.5.1