| blockwise_convolution.hxx |  | 
    1 #ifndef VIGRA_BLOCKWISE_CONVOLUTION_HXX_ 
    2 #define VIGRA_BLOCKWISE_CONVOLUTION_HXX_ 
    4 #include <vigra/overlapped_blocks.hxx> 
    5 #include <vigra/multi_convolution.hxx> 
    6 #include <vigra/blockify.hxx> 
    7 #include <vigra/multi_array.hxx> 
   12 namespace blockwise_convolution_detail
 
   15 template <
class DataArray, 
class OutputBlocksIterator, 
class KernelIterator>
 
   16 void convolveImpl(
const Overlaps<DataArray>& overlaps, OutputBlocksIterator output_blocks_begin, KernelIterator kit)
 
   18     static const unsigned int N = DataArray::actual_dimension;
 
   19     typedef typename MultiArrayShape<N>::type Shape;
 
   20     typedef typename OutputBlocksIterator::value_type OutputBlock;
 
   22     Shape shape = overlaps.shape();
 
   23     vigra_assert(shape == output_blocks_begin.shape(), 
"");
 
   25     MultiCoordinateIterator<N> it(shape);
 
   26     MultiCoordinateIterator<N> end = it.getEndIterator();
 
   27     for( ; it != end; ++it)
 
   29         OutputBlock output_block = output_blocks_begin[*it];
 
   30         OverlappingBlock<DataArray> data_block = overlaps[*it];
 
   35 template <
class Shape, 
class KernelIterator>
 
   36 std::pair<Shape, Shape> kernelOverlap(KernelIterator kit)
 
   41     for(
unsigned int i = 0; i != Shape::static_size; ++i, ++kit)
 
   44         before[i] = kit->right();
 
   45         after[i] = -kit->left();
 
   47     return std::make_pair(before, after);
 
   53 template <
unsigned int N, 
class T1, 
class S1,
 
   56 void separableConvolveBlockwise(MultiArrayView<N, T1, S1> 
source, MultiArrayView<N, T2, S2> dest, KernelIterator kit,
 
   57                                 const typename MultiArrayView<N, T1, S1>::difference_type& block_shape =
 
   58                                      typename MultiArrayView<N, T1, S1>::difference_type(128))
 
   60     using namespace blockwise_convolution_detail;
 
   62     typedef typename MultiArrayView<N, T1, S1>::difference_type Shape;
 
   64     Shape shape = source.shape();
 
   65     vigra_precondition(shape == dest.shape(), 
"shape mismatch of source and destination");
 
   67     std::pair<Shape, Shape> overlap = kernelOverlap<Shape, KernelIterator>(kit);
 
   68     Overlaps<MultiArrayView<N, T2, S2> > overlaps(source, block_shape, overlap.first, overlap.second);
 
   70     MultiArray<N, MultiArrayView<N, T2, S2> > destination_blocks = blockify(dest, block_shape);
 
   72     convolveImpl(overlaps, destination_blocks.begin(), kit);
 
   74 template <
unsigned int N, 
class T1, 
class S1,
 
   77 void separableConvolveBlockwise(MultiArrayView<N, T1, S1> source, MultiArrayView<N, T2, S2> dest, 
const Kernel1D<T3>& kernel,
 
   78                                 const typename MultiArrayView<N, T1, S1>::difference_type& block_shape =
 
   79                                      typename MultiArrayView<N, T1, S1>::difference_type(128))
 
   81     std::vector<Kernel1D<T3> > kernels(N, kernel);
 
   82     separableConvolveBlockwise(source, dest, kernels.begin(), block_shape);
 
  112 template <
unsigned int N, 
class T1, 
class T2, 
class KernelIterator>
 
  113 void separableConvolveBlockwise(
const ChunkedArray<N, T1>& source, ChunkedArray<N, T2>& destination, KernelIterator kit)
 
  115     using namespace blockwise_convolution_detail;
 
  117     typedef typename ChunkedArray<N, T1>::shape_type Shape;
 
  119     Shape shape = source.shape();
 
  120     vigra_precondition(shape == destination.shape(), 
"shape mismatch of source and destination");
 
  122     std::pair<Shape, Shape> overlap = kernelOverlap<Shape, KernelIterator>(kit);
 
  123     Shape block_shape = source.chunkShape();
 
  124     vigra_precondition(block_shape == destination.chunkShape(), 
"chunk shapes do not match");
 
  125     Overlaps<ChunkedArray<N, T1> > overlaps(source, block_shape, overlap.first, overlap.second);
 
  127     convolveImpl(overlaps, destination.chunk_begin(Shape(0), shape), kit);
 
  129 template <
unsigned int N, 
class T1, 
class T2, 
class T>
 
  130 void separableConvolveBlockwise(
const ChunkedArray<N, T1>& source, ChunkedArray<N, T2>& destination, 
const Kernel1D<T>& kernel)
 
  132     std::vector<Kernel1D<T> > kernels(N, kernel);
 
  133     separableConvolveBlockse(source, destination, kernels.begin());
 
void separableConvolveMultiArray(...)
Separated convolution on multi-dimensional arrays. 
vigra::GridGraph< N, DirectedTag >::vertex_descriptor source(typename vigra::GridGraph< N, DirectedTag >::edge_descriptor const &e, vigra::GridGraph< N, DirectedTag > const &g)
Get a vertex descriptor for the start vertex of edge e in graph g (API: boost). 
Definition: multi_gridgraph.hxx:2943
doxygen_overloaded_function(template<...> void separableConvolveBlockwise) template< unsigned int N
Separated convolution on ChunkedArrays.