pyramid2.h File Reference

#include <functional>
#include <vector>
#include <vigra/convolution.hxx>
#include <vigra/error.hxx>
#include <vigra/inspectimage.hxx>
#include <vigra/numerictraits.hxx>
#include <vigra/rgbvalue.hxx>
#include <vigra/sized_int.hxx>
#include <vigra/transformimage.hxx>

Include dependency graph for pyramid2.h:

Include dependency graph

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Namespaces

namespace  enblend

Classes

struct  enblend::FromPromotePlusFunctorWrapper< T1, T2, T3 >

Defines

#define IMUL6(A)   (A * SKIPSMImagePixelType(6))
#define IMUL5(A)   (A * SKIPSMImagePixelType(5))
#define IMUL11(A)   (A * SKIPSMImagePixelType(11))
#define AMUL6(A)   (A * SKIPSMAlphaPixelType(6))
#define SKIPSM_EXPAND(SCALE_OUT00, SCALE_OUT10, SCALE_OUT01, SCALE_OUT11)
#define SKIPSM_EXPAND_SHIFT
#define SKIPSM_EXPAND_ROW_END(SCALE_OUT00, SCALE_OUT10, SCALE_OUT01, SCALE_OUT11)
#define SKIPSM_EXPAND_COLUMN_END(SCALE_OUT00, SCALE_OUT10, SCALE_OUT01, SCALE_OUT11)
#define SKIPSM_EXPAND_COLUMN_END_WRAPAROUND(SCALE_OUT00, SCALE_OUT10, SCALE_OUT01, SCALE_OUT11)
#define SKIPSM_EXPAND_ROW_COLUMN_END(SCALE_OUT00, SCALE_OUT10, SCALE_OUT01, SCALE_OUT11)

Functions

template<typename ImagePixelComponentType>
unsigned int filterHalfWidth (const unsigned int levels)
 Calculate the half-width of a n-level filter.
template<typename SKIPSMImagePixelType, typename SKIPSMAlphaPixelType, typename SrcImageIterator, typename SrcAccessor, typename AlphaIterator, typename AlphaAccessor, typename DestImageIterator, typename DestAccessor, typename DestAlphaIterator, typename DestAlphaAccessor>
void reduce (bool wraparound, SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, AlphaIterator alpha_upperleft, AlphaAccessor aa, DestImageIterator dest_upperleft, DestImageIterator dest_lowerright, DestAccessor da, DestAlphaIterator dest_alpha_upperleft, DestAlphaIterator dest_alpha_lowerright, DestAlphaAccessor daa)
 The Burt & Adelson Reduce operation.
template<typename SKIPSMImagePixelType, typename SKIPSMAlphaPixelType, typename SrcImageIterator, typename SrcAccessor, typename AlphaIterator, typename AlphaAccessor, typename DestImageIterator, typename DestAccessor, typename DestAlphaIterator, typename DestAlphaAccessor>
void reduce (bool wraparound, triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, pair< AlphaIterator, AlphaAccessor > mask, triple< DestImageIterator, DestImageIterator, DestAccessor > dest, triple< DestAlphaIterator, DestAlphaIterator, DestAlphaAccessor > destMask)
template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor>
void reduce (bool wraparound, SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, DestImageIterator dest_upperleft, DestImageIterator dest_lowerright, DestAccessor da)
 The Burt & Adelson Reduce operation.
template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor>
void reduce (bool wraparound, triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, triple< DestImageIterator, DestImageIterator, DestAccessor > dest)
template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor, typename CombineFunctor>
void expand (bool add, bool wraparound, SrcImageIterator src_upperleft, SrcImageIterator src_lowerright, SrcAccessor sa, DestImageIterator dest_upperleft, DestImageIterator dest_lowerright, DestAccessor da, CombineFunctor cf)
 The Burt & Adelson Expand operation.
template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor>
void expand (bool add, bool wraparound, triple< SrcImageIterator, SrcImageIterator, SrcAccessor > src, triple< DestImageIterator, DestImageIterator, DestAccessor > dest)


Define Documentation

#define AMUL6  )     (A * SKIPSMAlphaPixelType(6))
 

Definition at line 61 of file pyramid2.h.

Referenced by enblend::reduce().

#define IMUL11  )     (A * SKIPSMImagePixelType(11))
 

Definition at line 60 of file pyramid2.h.

Referenced by enblend::reduce().

#define IMUL5  )     (A * SKIPSMImagePixelType(5))
 

Definition at line 59 of file pyramid2.h.

Referenced by enblend::reduce().

#define IMUL6  )     (A * SKIPSMImagePixelType(6))
 

Definition at line 58 of file pyramid2.h.

Referenced by enblend::expand(), and enblend::reduce().

#define SKIPSM_EXPAND SCALE_OUT00,
SCALE_OUT10,
SCALE_OUT01,
SCALE_OUT11   ) 
 

Value:

current = SKIPSMImagePixelType(sa(sx));                         \
    out00 = sc1a[srcx] + IMUL6(sc0a[srcx]);                         \
    out10 = sc1b[srcx] + IMUL6(sc0b[srcx]);                         \
    out01 = sc0a[srcx];                                             \
    out11 = sc0b[srcx];                                             \
    sc1a[srcx] = sc0a[srcx];                                        \
    sc1b[srcx] = sc0b[srcx];                                        \
    sc0a[srcx] = sr1 + IMUL6(sr0) + current;                        \
    sc0b[srcx] = (sr0 + current) * 4;                               \
    sr1 = sr0;                                                      \
    sr0 = current;                                                  \
    out00 += sc0a[srcx];                                            \
    out10 += sc0b[srcx];                                            \
    out01 += sc0a[srcx];                                            \
    out11 += sc0b[srcx];                                            \
    out00 /= SKIPSMImagePixelType(SCALE_OUT00);                     \
    out10 /= SKIPSMImagePixelType(SCALE_OUT10);                     \
    out01 /= SKIPSMImagePixelType(SCALE_OUT01);                     \
    out11 /= SKIPSMImagePixelType(SCALE_OUT11);                     \
    da.set(cf(SKIPSMImagePixelType(da(dx)), out00), dx);            \
    ++dx.x;                                                         \
    da.set(cf(SKIPSMImagePixelType(da(dx)), out10), dx);            \
    ++dx.x;                                                         \
    da.set(cf(SKIPSMImagePixelType(da(dxx)), out01), dxx);          \
    ++dxx.x;                                                        \
    da.set(cf(SKIPSMImagePixelType(da(dxx)), out11), dxx);          \
    ++dxx.x;

Definition at line 863 of file pyramid2.h.

Referenced by enblend::expand().

#define SKIPSM_EXPAND_COLUMN_END SCALE_OUT00,
SCALE_OUT10,
SCALE_OUT01,
SCALE_OUT11   ) 
 

Value:

out00 = sc1a[srcx] + IMUL6(sc0a[srcx]);                         \
    out01 = sc0a[srcx];                                             \
    out10 = sc1b[srcx] + IMUL6(sc0b[srcx]);                         \
    out11 = sc0b[srcx];                                             \
    sc1a[srcx] = sc0a[srcx];                                        \
    sc1b[srcx] = sc0b[srcx];                                        \
    sc0a[srcx] = sr1 + IMUL6(sr0);                                  \
    sc0b[srcx] = sr0 * 4;                                           \
    out00 += sc0a[srcx];                                            \
    out01 += sc0a[srcx];                                            \
    out00 /= SKIPSMImagePixelType(SCALE_OUT00);                     \
    out01 /= SKIPSMImagePixelType(SCALE_OUT01);                     \
    da.set(cf(da(dx), out00), dx);                                  \
    da.set(cf(da(dxx), out01), dxx);                                \
    if ((dst_w & 1) == 0) {                                         \
        ++dx.x;                                                     \
        ++dxx.x;                                                    \
        out10 += sc0b[srcx];                                        \
        out11 += sc0b[srcx];                                        \
        out10 /= SKIPSMImagePixelType(SCALE_OUT10);                 \
        out11 /= SKIPSMImagePixelType(SCALE_OUT11);                 \
        da.set(cf(da(dx), out10), dx);                              \
        da.set(cf(da(dxx), out11), dxx);                            \
    }

Definition at line 946 of file pyramid2.h.

Referenced by enblend::expand().

#define SKIPSM_EXPAND_COLUMN_END_WRAPAROUND SCALE_OUT00,
SCALE_OUT10,
SCALE_OUT01,
SCALE_OUT11   ) 
 

Value:

out00 = sc1a[srcx] + IMUL6(sc0a[srcx]);                         \
    out01 = sc0a[srcx];                                             \
    out10 = sc1b[srcx] + IMUL6(sc0b[srcx]);                         \
    out11 = sc0b[srcx];                                             \
    sc1a[srcx] = sc0a[srcx];                                        \
    sc1b[srcx] = sc0b[srcx];                                        \
    sc0a[srcx] = sr1 + IMUL6(sr0) + SKIPSMImagePixelType(sa(sy));   \
    sc0b[srcx] = (sr0 + SKIPSMImagePixelType(sa(sy))) * 4;          \
    out00 += sc0a[srcx];                                            \
    out01 += sc0a[srcx];                                            \
    out00 /= SKIPSMImagePixelType(SCALE_OUT00);                     \
    out01 /= SKIPSMImagePixelType(SCALE_OUT01);                     \
    da.set(cf(da(dx), out00), dx);                                  \
    da.set(cf(da(dxx), out01), dxx);                                \
    if ((dst_w & 1) == 0) {                                         \
        ++dx.x;                                                     \
        ++dxx.x;                                                    \
        out10 += sc0b[srcx];                                        \
        out11 += sc0b[srcx];                                        \
        out10 /= SKIPSMImagePixelType(SCALE_OUT10);                 \
        out11 /= SKIPSMImagePixelType(SCALE_OUT11);                 \
        da.set(cf(da(dx), out10), dx);                              \
        da.set(cf(da(dxx), out11), dxx);                            \
    }

Definition at line 974 of file pyramid2.h.

Referenced by enblend::expand().

#define SKIPSM_EXPAND_ROW_COLUMN_END SCALE_OUT00,
SCALE_OUT10,
SCALE_OUT01,
SCALE_OUT11   ) 
 

Value:

out00 = sc1a[srcx] + IMUL6(sc0a[srcx]);                         \
    out00 /= SKIPSMImagePixelType(SCALE_OUT00);                     \
    da.set(cf(da(dx), out00), dx);                                  \
    if ((dst_w & 1) == 0) {                                         \
        out10 = sc1b[srcx] + IMUL6(sc0b[srcx]);                     \
        out10 /= SKIPSMImagePixelType(SCALE_OUT10);                 \
        ++dx.x;                                                     \
        da.set(cf(da(dx), out10), dx);                              \
    }                                                               \
    if ((dst_h & 1) == 0) {                                         \
        out01 = sc0a[srcx];                                         \
        out01 /= SKIPSMImagePixelType(SCALE_OUT01);                 \
        da.set(cf(da(dxx), out01), dxx);                            \
        if ((dst_w & 1) == 0) {                                     \
            out11 = sc0b[srcx];                                     \
            out11 /= SKIPSMImagePixelType(SCALE_OUT11);             \
            ++dxx.x;                                                \
            da.set(cf(da(dxx), out11), dxx);                        \
        }                                                           \
    }

Definition at line 1002 of file pyramid2.h.

Referenced by enblend::expand().

#define SKIPSM_EXPAND_ROW_END SCALE_OUT00,
SCALE_OUT10,
SCALE_OUT01,
SCALE_OUT11   ) 
 

Value:

out00 = sc1a[srcx] + IMUL6(sc0a[srcx]);                         \
    out10 = sc1b[srcx] + IMUL6(sc0b[srcx]);                         \
    out00 /= SKIPSMImagePixelType(SCALE_OUT00);                     \
    out10 /= SKIPSMImagePixelType(SCALE_OUT10);                     \
    da.set(cf(da(dx), out00), dx);                                  \
    ++dx.x;                                                         \
    da.set(cf(da(dx), out10), dx);                                  \
    ++dx.x;                                                         \
    if ((dst_h & 1) == 0) {                                         \
        out01 = sc0a[srcx];                                         \
        out11 = sc0b[srcx];                                         \
        out01 /= SKIPSMImagePixelType(SCALE_OUT01);                 \
        out11 /= SKIPSMImagePixelType(SCALE_OUT11);                 \
        da.set(cf(da(dxx), out01), dxx);                            \
        ++dxx.x;                                                    \
        da.set(cf(da(dxx), out11), dxx);                            \
        ++dxx.x;                                                    \
    }

Definition at line 924 of file pyramid2.h.

Referenced by enblend::expand().

#define SKIPSM_EXPAND_SHIFT
 

Value:

current = SKIPSMImagePixelType(sa(sx));                         \
    out00 = sc1a[srcx] + IMUL6(sc0a[srcx]);                         \
    out10 = sc1b[srcx] + IMUL6(sc0b[srcx]);                         \
    out01 = sc0a[srcx];                                             \
    out11 = sc0b[srcx];                                             \
    sc1a[srcx] = sc0a[srcx];                                        \
    sc1b[srcx] = sc0b[srcx];                                        \
    sc0a[srcx] = sr1 + IMUL6(sr0) + current;                        \
    sc0b[srcx] = (sr0 + current) * 4;                               \
    sr1 = sr0;                                                      \
    sr0 = current;                                                  \
    out00 += sc0a[srcx];                                            \
    out10 += sc0b[srcx];                                            \
    out01 += sc0a[srcx];                                            \
    out11 += sc0b[srcx];                                            \
    out00 /= 64;                                                    \
    out10 /= 64;                                                    \
    out01 /= 16;                                                    \
    out11 /= 16;                                                    \
    da.set(cf(SKIPSMImagePixelType(da(dx)), out00), dx);            \
    ++dx.x;                                                         \
    da.set(cf(SKIPSMImagePixelType(da(dx)), out10), dx);            \
    ++dx.x;                                                         \
    da.set(cf(SKIPSMImagePixelType(da(dxx)), out01), dxx);          \
    ++dxx.x;                                                        \
    da.set(cf(SKIPSMImagePixelType(da(dxx)), out11), dxx);          \
    ++dxx.x;

Definition at line 894 of file pyramid2.h.

Referenced by enblend::expand().


Function Documentation

template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor>
void expand bool  add,
bool  wraparound,
triple< SrcImageIterator, SrcImageIterator, SrcAccessor >  src,
triple< DestImageIterator, DestImageIterator, DestAccessor >  dest
[inline]
 

Definition at line 1368 of file pyramid2.h.

template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor, typename CombineFunctor>
void expand bool  add,
bool  wraparound,
SrcImageIterator  src_upperleft,
SrcImageIterator  src_lowerright,
SrcAccessor  sa,
DestImageIterator  dest_upperleft,
DestImageIterator  dest_lowerright,
DestAccessor  da,
CombineFunctor  cf
 

The Burt & Adelson Expand operation.

Upsampling with Gaussian interpolation in one pass over the input image using SKIPSM-based algorithm. Uses only integer math, visits each pixel only once.

Explanation of algorithm:

src image pixels: a b c dst image pixels: A B C D E F G H I J d e f K L M N O P Q R S T g h i U V W X Y

Algorithm visits all src image pixels from left to right and top to bottom. At each src pixel, four dst pixels are calculated. When visiting src pixel i, dst pixels M, N, R and S are written.

State variables before visiting i: sr0 = h sr1 = g sc0a[2] = d + 6e + f sc0b[2] = 4e + 4f sc1a[2] = a + 6b + c sc1b[2] = 4b + 4c

State variables after visiting i: sr0 = i sr1 = h sc0a[2] = g + 6h + i sc0b[2] = 4h + 4i sc1a[2] = d + 6e + f sc1b[2] = 4e + 4f

M = 1 * (a + 6b + c) + 6 * (d + 6e + f) + 1 * (g + 6h + i)

N = 1 * (4b + 4c) + 6 * (4e + 4f) + 1 * (4h + 4i)

R = 4 * (d + 6e + f) + 4 * (g + 6h + i)

S = 4 * (4e + 4f) + 4 * (4h + 4i)

Updates when visiting each src image pixel: (all assignments occur in parallel) sr0 <= current sr1 <= sr0 sc0a[x] <= sr1 + 6*sr0 + current sc0b[x] <= 4*sr0 + 4*current sc1a[x] <= sc0a[x] sc1b[x] <= sc0b[x] out(-2, -2) <= sc1a[x] + 6*sc0a[x] + (new sc0a[x]) out(-1, -2) <= sc1b[x] + 6*sc0b[x] + (new sc0b[x]) out(-2, -1) <= 4*sc0a[x] + 4*(new sc0a[x]) out(-1, -1) <= 4*sc0b[x] + 4*(new sc0b[x])

Definition at line 1089 of file pyramid2.h.

References IMUL6, SKIPSM_EXPAND, SKIPSM_EXPAND_COLUMN_END, SKIPSM_EXPAND_COLUMN_END_WRAPAROUND, SKIPSM_EXPAND_ROW_COLUMN_END, SKIPSM_EXPAND_ROW_END, and SKIPSM_EXPAND_SHIFT.

template<typename ImagePixelComponentType>
unsigned int filterHalfWidth const unsigned int  levels  ) 
 

Calculate the half-width of a n-level filter.

Assumes that the input function is a left-handed function, and the last non-zero input is at location 0. Returns the location of the last non-zero output.

Definition at line 69 of file pyramid2.h.

template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor>
void reduce bool  wraparound,
triple< SrcImageIterator, SrcImageIterator, SrcAccessor >  src,
triple< DestImageIterator, DestImageIterator, DestAccessor >  dest
[inline]
 

Definition at line 853 of file pyramid2.h.

Referenced by reduceFilesToHDR(), vigra_ext::reduceROIImages(), and HuginBase::Nona::ReduceStitcher< ImageType, AlphaType >::stitch().

template<typename SKIPSMImagePixelType, typename SrcImageIterator, typename SrcAccessor, typename DestImageIterator, typename DestAccessor>
void reduce bool  wraparound,
SrcImageIterator  src_upperleft,
SrcImageIterator  src_lowerright,
SrcAccessor  sa,
DestImageIterator  dest_upperleft,
DestImageIterator  dest_lowerright,
DestAccessor  da
[inline]
 

The Burt & Adelson Reduce operation.

This version is for images that do not have alpha channels.

Definition at line 597 of file pyramid2.h.

References IMUL11, IMUL5, and IMUL6.

template<typename SKIPSMImagePixelType, typename SKIPSMAlphaPixelType, typename SrcImageIterator, typename SrcAccessor, typename AlphaIterator, typename AlphaAccessor, typename DestImageIterator, typename DestAccessor, typename DestAlphaIterator, typename DestAlphaAccessor>
void reduce bool  wraparound,
triple< SrcImageIterator, SrcImageIterator, SrcAccessor >  src,
pair< AlphaIterator, AlphaAccessor >  mask,
triple< DestImageIterator, DestImageIterator, DestAccessor >  dest,
triple< DestAlphaIterator, DestAlphaIterator, DestAlphaAccessor >  destMask
[inline]
 

Definition at line 579 of file pyramid2.h.

template<typename SKIPSMImagePixelType, typename SKIPSMAlphaPixelType, typename SrcImageIterator, typename SrcAccessor, typename AlphaIterator, typename AlphaAccessor, typename DestImageIterator, typename DestAccessor, typename DestAlphaIterator, typename DestAlphaAccessor>
void reduce bool  wraparound,
SrcImageIterator  src_upperleft,
SrcImageIterator  src_lowerright,
SrcAccessor  sa,
AlphaIterator  alpha_upperleft,
AlphaAccessor  aa,
DestImageIterator  dest_upperleft,
DestImageIterator  dest_lowerright,
DestAccessor  da,
DestAlphaIterator  dest_alpha_upperleft,
DestAlphaIterator  dest_alpha_lowerright,
DestAlphaAccessor  daa
[inline]
 

The Burt & Adelson Reduce operation.

This version is for images with alpha channels. Gaussian blur, downsampling, and extrapolation in one pass over the input image using SKIPSM-based algorithm. Uses only integer math, visits each pixel only once.

Reference: Frederick M. Waltz and John W.V. Miller. An efficient algorithm for Gaussian blur using finite-state machines. SPIE Conf. on Machine Vision Systems for Inspection and Metrology VII. November 1998.

************************************************************************************************* 1-D explanation of algorithm:

src image pixels: A B C D E F G dst image pixels: W X Y Z

Algorithm iterates over src image pixels from left to right. At even src image pixels, the output of the previous dst image pixel is calculated. For example, when visiting E, the value of X is written to the dst image.

State variables before visiting E: sr0 = C sr1 = A + 4B srp = 4D

State variables after visiting E: sr0 = E sr1 = C + 4D srp = 4D X = A + 4B + 6C + 4D + E

Updates when visiting even source pixel: (all updates occur in parallel) sr0 <= current sr1 <= sr0 + srp dst(-1) <= sr1 + 6*sr0 + srp + current

Updates when visiting odd source pixel: srp <= 4*current

************************************************************************************************* 2-D explanation:

src image pixels: A B C D E dst image pixels: a b c F G H I J K L M N O d e f P Q R S T U V W X Y g h i

Algorithm visits all src image pixels from left to right and top to bottom. When visiting src pixel Y, the value of e will be written to the dst image.

State variables before visiting Y: sr0 = W sr1 = U + 4V srp = 4X sc0[2] = K + 4L + 6M + 4N + O sc1[2] = (A + 4B + 6C + 4D + E) + 4*(F + 4G + 6H + 4I + J) scp[2] = 4*(P + 4Q + 6R + 4S + T)

State variables after visiting Y: sr0 = Y sr1 = W + 4X srp = 4X sc0[2] = U + 4V + 6W + 4X + Y sc1[2] = (K + 4L + 6M + 4N + O) + 4*(P + 4Q + 6R + 4S + T) scp[2] = 4*(P + 4Q + 6R + 4S + T) e = 1 * (A + 4B + 6C + 4D + E) + 4 * (F + 4G + 6H + 4I + J) + 6 * (K + 4L + 6M + 4N + O) + 4 * (P + 4Q + 6R + 4S + T) + 1 * (U + 4V + 6W + 4X + Y)

Updates when visiting (even x, even y) source pixel: (all updates occur in parallel) sr0 <= current sr1 <= sr0 + srp sc0[x] <= sr1 + 6*sr0 + srp + current sc1[x] <= sc0[x] + scp[x] dst(-1,-1) <= sc1[x] + 6*sc0[x] + scp + (new sc0[x])

Updates when visiting (odd x, even y) source pixel: srp <= 4*current

Updates when visiting (even x, odd y) source pixel: sr0 <= current sr1 <= sr0 + srp scp[x] <= 4*(sr1 + 6*sr0 + srp + current)

Updates when visting (odd x, odd y) source pixel: srp <= 4*current

Definition at line 178 of file pyramid2.h.

References AMUL6, IMUL6, and celeste::max().


Generated on Mon Jul 28 01:25:46 2014 for Hugintrunk by  doxygen 1.3.9.1