Classes | Macros | Enumerations | Functions
vil_convolve_1d.h File Reference

1D Convolution with cunning boundary options More...

#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cassert>
#include <vil/vil_image_view.h>
#include <vil/vil_image_resource.h>
#include <vil/vil_property.h>

Go to the source code of this file.

Classes

class  vil_convolve_1d_resource< kernelT, accumT, destT >
 A resource adaptor that behaves like a convolved version of its input. More...
 

Macros

#define macro(F, T)
 

Enumerations

enum  vil_convolve_boundary_option {
  vil_convolve_ignore_edge, vil_convolve_no_extend, vil_convolve_zero_extend, vil_convolve_constant_extend,
  vil_convolve_periodic_extend, vil_convolve_reflect_extend, vil_convolve_trim
}
 Available options for boundary behavior. More...
 

Functions

template<class srcT , class destT , class kernelT , class accumT >
void vil_convolve_edge_1d (const srcT *src, unsigned n, std::ptrdiff_t s_step, destT *dest, std::ptrdiff_t d_step, const kernelT *kernel, std::ptrdiff_t k_lo, std::ptrdiff_t k_hi, std::ptrdiff_t kstep, accumT, vil_convolve_boundary_option option)
 Convolve edge with kernel[x*kstep] x in [k_lo,k_hi] (k_hi>=0). More...
 
template<class srcT , class destT , class kernelT , class accumT >
void vil_convolve_1d (const srcT *src0, unsigned nx, std::ptrdiff_t s_step, destT *dest0, std::ptrdiff_t d_step, const kernelT *kernel, std::ptrdiff_t k_lo, std::ptrdiff_t k_hi, accumT ac, vil_convolve_boundary_option start_option, vil_convolve_boundary_option end_option)
 Convolve kernel[x] (x in [k_lo,k_hi]) with srcT. More...
 
template<class srcT , class destT , class kernelT , class accumT >
void vil_convolve_1d (const vil_image_view< srcT > &src_im, vil_image_view< destT > &dest_im, const kernelT *kernel, std::ptrdiff_t k_lo, std::ptrdiff_t k_hi, accumT ac, vil_convolve_boundary_option start_option, vil_convolve_boundary_option end_option)
 Convolve kernel[i] (i in [k_lo,k_hi]) with srcT in i-direction. More...
 
template<class destT , class kernelT , class accumT >
vil_image_resource_sptr vil_convolve_1d (const vil_image_resource_sptr &src_im, const destT, const kernelT *kernel, int k_lo, int k_hi, const accumT, vil_convolve_boundary_option start_option, vil_convolve_boundary_option end_option)
 Create an image_resource object which convolve kernel[x] x in [k_lo,k_hi] with srcT. More...
 

Detailed Description

1D Convolution with cunning boundary options

Author
Tim Cootes, Ian Scott (based on work by fsm)
Note
The convolution operation is defined by $(f*g)(x) = \int f(x-y) g(y) dy$ i.e. the kernel g is reflected before the integration is performed. If you don't want this to happen, the behaviour you want is not called "convolution". So don't break the convolution routines in that particular way.

Definition in file vil_convolve_1d.h.

Macro Definition Documentation

◆ macro

#define macro (   F,
 
)
Value:
case F : \
vil_convolve_1d(static_cast<vil_image_view<T >&>(*vs),dest, \
kernel_, klo_, khi_, accumT(), start_option_, end_option_); \
return new vil_image_view<destT>(vil_crop(dest, lboundary, n_i, 0, n_j));
Concrete view of image data of type T held in memory.
Definition: vil_fwd.h:13
vil_image_view< T > vil_crop(const vil_image_view< T > &im, unsigned i0, unsigned n_i, unsigned j0, unsigned n_j)
Create a view which is a cropped version of src.
Definition: vil_crop.h:21

Enumeration Type Documentation

◆ vil_convolve_boundary_option

Available options for boundary behavior.

When convolving a finite signal the boundaries may be treated in various ways which can often be expressed in terms of ways to extend the signal outside its original range.

Enumerator
vil_convolve_ignore_edge 

Do not fill destination edges at all.

i.e. leave them unchanged.

vil_convolve_no_extend 

Do not to extend the signal, but pad with zeros.

    |                               |
K                       ----*-------
in   ... ---------------------------
out  ... --------------------0000000
vil_convolve_zero_extend 

Zero-extend the input signal beyond the boundary.

    |                               |
K                              ----*--------
in   ... ---------------------------000000000000...
out  ... ---------------------------
vil_convolve_constant_extend 

Extend the signal to be constant beyond the boundary.

    |                               |
K                              ----*--------
in   ... --------------------------aaaaaaaaaaaaa...
out  ... ---------------------------
vil_convolve_periodic_extend 

Extend the signal periodically beyond the boundary.

    |                               |
K                              ----*--------
in   abc...-------------------------abc...------..
out  ... ---------------------------
vil_convolve_reflect_extend 

Extend the signal by reflection about the boundary.

    |                               |
K                              ----*--------
in   ... -------------------...edcbabcde...
out  ... ---------------------------
vil_convolve_trim 

Kernel is trimmed and reweighed, to allow convolution up to boundary.

This one is slightly different. The input signal is not extended in any way, but the kernel is trimmed to allow convolution to proceed up to the boundary and reweighed to keep the total area the same.

Note
may not work with kernels which take negative values.

Definition at line 33 of file vil_convolve_1d.h.

Function Documentation

◆ vil_convolve_1d() [1/3]

template<class srcT , class destT , class kernelT , class accumT >
void vil_convolve_1d ( const srcT *  src0,
unsigned  nx,
std::ptrdiff_t  s_step,
destT *  dest0,
std::ptrdiff_t  d_step,
const kernelT *  kernel,
std::ptrdiff_t  k_lo,
std::ptrdiff_t  k_hi,
accumT  ac,
vil_convolve_boundary_option  start_option,
vil_convolve_boundary_option  end_option 
)
inline

Convolve kernel[x] (x in [k_lo,k_hi]) with srcT.

Assumes dest and src same size (nx) Kernel must not be larger than nx;

Definition at line 203 of file vil_convolve_1d.h.

◆ vil_convolve_1d() [2/3]

template<class srcT , class destT , class kernelT , class accumT >
void vil_convolve_1d ( const vil_image_view< srcT > &  src_im,
vil_image_view< destT > &  dest_im,
const kernelT *  kernel,
std::ptrdiff_t  k_lo,
std::ptrdiff_t  k_hi,
accumT  ac,
vil_convolve_boundary_option  start_option,
vil_convolve_boundary_option  end_option 
)
inline

Convolve kernel[i] (i in [k_lo,k_hi]) with srcT in i-direction.

On exit dest_im(i,j) = sum src(i-x,j)*kernel(x) (x=k_lo..k_hi)

Note
This function reverses the kernel. If you don't want the kernel reversed, use vil_correlate_1d instead. The kernel must not be larger than src_im.ni()
Parameters
kernelshould point to tap 0.
dest_imwill be resized to size of src_im.

Definition at line 248 of file vil_convolve_1d.h.

◆ vil_convolve_1d() [3/3]

template<class destT , class kernelT , class accumT >
vil_image_resource_sptr vil_convolve_1d ( const vil_image_resource_sptr src_im,
const destT  dt,
const kernelT *  kernel,
int  k_lo,
int  k_hi,
const accumT  ac,
vil_convolve_boundary_option  start_option,
vil_convolve_boundary_option  end_option 
)

Create an image_resource object which convolve kernel[x] x in [k_lo,k_hi] with srcT.

Note
This function reverses the kernel. If you don't want the kernel reversed, use vil_correlate_1d instead.
Parameters
kernelshould point to tap 0.

Definition at line 406 of file vil_convolve_1d.h.

◆ vil_convolve_edge_1d()

template<class srcT , class destT , class kernelT , class accumT >
void vil_convolve_edge_1d ( const srcT *  src,
unsigned  n,
std::ptrdiff_t  s_step,
destT *  dest,
std::ptrdiff_t  d_step,
const kernelT *  kernel,
std::ptrdiff_t  k_lo,
std::ptrdiff_t  k_hi,
std::ptrdiff_t  kstep,
accumT  ,
vil_convolve_boundary_option  option 
)
inline

Convolve edge with kernel[x*kstep] x in [k_lo,k_hi] (k_hi>=0).

Fills only edge: dest[i], i=0..(k_hi-1)

Definition at line 96 of file vil_convolve_1d.h.