vigra - Algorithms to Initialize Images

[ VIGRA Homepage | Function Index | Class Index | Namespaces | File List | Main Page ]

| Algorithms to Initialize Images |

## Functions
template<... >
void | initImage (...)
| Write a value to every pixel in an image or rectangular ROI. More...
template<... >
void | initImageBorder (...)
| Write value to the specified border pixels in the image. More...
template<... >
void | initImageIf (...)
| Write value to pixel in the image if mask is true. More...
template<... >
void | initImageWithFunctor (...)
| Write the result of a functor call to every pixel in an image or rectangular ROI. More...

## Detailed Description

Init images or image borders

## Function Documentation

void vigra::initImage | ( |  | ... | ) |

Write a value to every pixel in an image or rectangular ROI.

This function can be used to init the image.

The initial value can either be a constant of appropriate type (compatible with the destination's value_type), or a functor with compatible result_type. These two cases are automatically distinguished when `FunctorTraits<FUNCTOR>::isInitializer` yields `VigraTrueType`. Since the functor is passed by `const` reference, its `operator()` must be const, and its internal state may need to be `mutable`.

Function initMultiArray() implements the same functionality for arbitrary dimensional arrays. In many situations, the assignment functions of vigra::MultiArrayView offer a simpler and more readable alternative to the init functions.

Declarations:

pass 2D array views:

namespace vigra {
template <class T, class S, class VALUETYPE>
void
initImage(MultiArrayView<2, T, S> img, VALUETYPE const & v);
template <class T, class S, class FUNCTOR>
void
initImage(MultiArrayView<2, T, S> img, FUNCTOR const & v);
}

show deprecated declarations

pass Image Iterators and Data Accessors :
namespace vigra {
template <class ImageIterator, class Accessor, class VALUETYPE>
void initImage(ImageIterator upperleft, ImageIterator lowerright,
Accessor a, VALUETYPE const & v);
template <class ImageIterator, class Accessor, class FUNCTOR>
void initImage(ImageIterator upperleft, ImageIterator lowerright,
Accessor a, FUNCTOR const & v);
}

use argument objects in conjunction with Argument Object Factories :

namespace vigra {
template <class ImageIterator, class Accessor, class VALUETYPE>
void initImage(triple<ImageIterator, ImageIterator, Accessor> img, VALUETYPE const & v);
template <class ImageIterator, class Accessor, class FUNCTOR>
void initImage(triple<ImageIterator, ImageIterator, Accessor> img, FUNCTOR const & v);
}

Usage:

#include <vigra/initimage.hxx>
Namespace: vigra

Initialize with a constant:

MultiArray<2, unsigned char> img(100, 100);
// init the image with the value 128
initImage(img, 128);
// init the interior with the value 1
initImage(img.subarray(Shape2(10), Shape2(-10)), 1);
// equivalent to
img = 128;
img.init(128);
img.subarray(Shape2(10), Shape2(-10)) = 1;

Initialize with a functor:

struct Counter {
Counter() : count(0) {}
int operator()() const { return count++; }
mutable int count;
};
MultiArray<2, int> img(100, 100);
// write the current count in every pixel
initImage(img, Counter());
// equivalent to
#include <vigra/algorithm.hxx>
linearSequence(img.begin(), img.end());

show deprecated examples

vigra::BImage img(100, 100);
// init the image with the value 128
vigra::initImage(destImageRange(img), 128);
// Initialize with a functor:
struct Counter {
Counter() : count(0) {}
int operator()() const { return count++; }
mutable int count;
};
// write the current count in every pixel
vigra::initImage(destImageRange(img), Counter());

Required Interface:

ImageIterator upperleft, lowerright;
ImageIterator::row_iterator ix = upperleft.rowIterator();
Accessor accessor;
VALUETYPE v;
accessor.set(v, ix);

void vigra::initImageWithFunctor | ( |  | ... | ) |

Write the result of a functor call to every pixel in an image or rectangular ROI.

This function can be used to init the image by calling the given functor for each pixel. The functor is passed by reference, so that its internal state can be updated in each call.

Declarations:

pass 2D array views:

namespace vigra {
template <class T, class S, class FUNCTOR>
void
initImageWithFunctor(MultiArrayView<2, T, S> img, FUNCTOR & f);
}

show deprecated declarations

pass Image Iterators and Data Accessors :
namespace vigra {
template <class ImageIterator, class Accessor, class FUNCTOR>
void
initImageWithFunctor(ImageIterator upperleft, ImageIterator lowerright,
Accessor a, FUNCTOR & f);
}

use argument objects in conjunction with Argument Object Factories :

namespace vigra {
template <class ImageIterator, class Accessor, class FUNCTOR>
void
initImageWithFunctor(triple<ImageIterator, ImageIterator, Accessor> img, FUNCTOR & f);
}

Usage:

#include <vigra/initimage.hxx>
Namespace: vigra

struct Counter {
Counter() : count(0) {}
int operator()() const { return count++; }
int count;
};
MultiArray<2, int> img(100, 100);
// write the current count in every pixel
Counter counter;
initImageWithFunctor(img, counter);
// equivalent to
#include <vigra/algorithm.hxx>
linearSequence(img.begin(), img.end());

show deprecated examples

struct Counter {
Counter() : count(0) {}
int operator()() const { return count++; }
mutable int count;
};
vigra::IImage img(100, 100);
// write the current count in every pixel
Counter counter;
vigra::initImageWithFunctor(destImageRange(img), counter);

Required Interface:

ImageIterator upperleft, lowerright;
ImageIterator::row_iterator ix = upperleft.rowIterator();
Accessor accessor;
Functor f;
accessor.set(f(), ix);

void vigra::initImageIf | ( |  | ... | ) |

Write value to pixel in the image if mask is true.

This function can be used to init a region-of-interest of the image.

The initial value can either be a constant of appropriate type (compatible with the destination's value_type), or a functor with compatible result_type. These two cases are automatically distinguished when `FunctorTraits<FUNCTOR>::isInitializer` yields `VigraTrueType`. Since the functor is passed by `const` reference, its `operator()` must be const, and its internal state may need to be `mutable`.

Declarations:

pass 2D array views:

namespace vigra {
template <class T, class S,
class TM, class SM,
class VALUETYPE>
void
initImageIf(MultiArrayView<2, T, S> img,
MultiArrayView<2, TM, SM> const & mask,
VALUETYPE const & v);
template <class T, class S,
class TM, class SM,
class FUNCTOR>
void
initImageIf(MultiArrayView<2, T, S> img,
MultiArrayView<2, TM, SM> const & mask,
FUNCTOR const & v);
}

show deprecated declarations

pass Image Iterators and Data Accessors :
namespace vigra {
template <class ImageIterator, class Accessor,
class MaskImageIterator, class MaskAccessor,
class VALUETYPE>
void initImageIf(ImageIterator upperleft, ImageIterator lowerright, Accessor a,
MaskImageIterator mask_upperleft, MaskAccessor ma,
VALUETYPE const & v);
template <class ImageIterator, class Accessor,
class MaskImageIterator, class MaskAccessor,
class FUNCTOR>
void initImageIf(ImageIterator upperleft, ImageIterator lowerright, Accessor a,
MaskImageIterator mask_upperleft, MaskAccessor ma,
FUNCTOR const & v);
}

use argument objects in conjunction with Argument Object Factories :

namespace vigra {
template <class ImageIterator, class Accessor,
class MaskImageIterator, class MaskAccessor,
class VALUETYPE>
void initImageIf(triple<ImageIterator, ImageIterator, Accessor> img,
pair<MaskImageIterator, MaskAccessor> mask,
VALUETYPE const & v);
template <class ImageIterator, class Accessor,
class MaskImageIterator, class MaskAccessor,
class FUNCTOR>
void initImageIf(triple<ImageIterator, ImageIterator, Accessor> img,
pair<MaskImageIterator, MaskAccessor> mask,
FUNCTOR const & v);
}

Usage:

#include <vigra/initimage.hxx>
Namespace: vigra

MultiArray<2, RGBValue<unsigned char> > img(100, 100),
MultiArray<2, unsigned char> mask(100, 100);
... // init the ROI mask
// set the ROI to one
initImageIf(img, mask,
NumericTraits<RGBValue<unsigned char> >::one());

show deprecated examples

vigra::BImage img(100, 100);
vigra::BImage mask(100, 100);
// zero the ROI
vigra::initImageIf(destImageRange(img),
maskImage(mask),
vigra::NumericTraits<vigra::BImage::PixelType>::zero());

Required Interface:

ImageIterator upperleft, lowerright;
MaskImageIterator mask_upperleft;
ImageIterator::row_iterator ix = upperleft.rowIterator();
MaskImageIterator::row_iterator mx = mask_upperleft.rowIterator();
Accessor accessor;
MaskAccessor mask_accessor;
VALUETYPE v;
if(mask_accessor(mx)) accessor.set(v, ix);

Examples:
  voronoi.cxx.

void vigra::initImageBorder | ( |  | ... | ) |

Write value to the specified border pixels in the image.

A pixel is initialized if its distance to the border is at most 'borderwidth'.

The initial value can either be a constant of appropriate type (compatible with the destination's value_type), or a functor with compatible result_type. These two cases are automatically distinguished when `FunctorTraits<FUNCTOR>::isInitializer` yields `VigraTrueType`. Since the functor is passed by `const` reference, its `operator()` must be const, and its internal state may need to be `mutable`.

Declarations:

pass 2D array views:

namespace vigra {
template <class T, class S, class VALUETYPE>
void
initImageBorder(MultiArrayView<2, T, S> img,
int border_width, VALUETYPE const & v);
template <class T, class S, class FUNCTOR>
void
initImageBorder(MultiArrayView<2, T, S> img,
int border_width, FUNCTOR const & v);
}

show deprecated declarations

pass Image Iterators and Data Accessors :
namespace vigra {
template <class ImageIterator, class Accessor, class VALUETYPE>
void initImageBorder(ImageIterator upperleft, ImageIterator lowerright, Accessor a,
int border_width, VALUETYPE const & v);
template <class ImageIterator, class Accessor, class FUNCTOR>
void initImageBorder(ImageIterator upperleft, ImageIterator lowerright, Accessor a,
int border_width, FUNCTOR const & v);
}

use argument objects in conjunction with Argument Object Factories :

namespace vigra {
template <class ImageIterator, class Accessor, class VALUETYPE>
void initImageBorder(triple<ImageIterator, ImageIterator, Accessor> img,
int border_width, VALUETYPE const & v);
template <class ImageIterator, class Accessor, class FUNCTOR>
void initImageBorder(triple<ImageIterator, ImageIterator, Accessor> img,
int border_width, FUNCTOR const & v);
}

Usage:

#include <vigra/initimage.hxx>
Namespace: vigra

#include <vigra/random.hxx>
MultiArray<2, int> img(100, 100);
// fill a border of 5 pixels with random numbers
initImageBorder(img, 5, MersenneTwister());

show deprecated examples

vigra::BImage img(100, 100);
// zero a border of 5 pixel
vigra::initImageBorder(destImageRange(img),
5, vigra::NumericTraits<vigra::BImage::PixelType>::zero());

Required Interface:
see initImage()

© Ullrich Köthe (ullrich.koethe@iwr.uni-heidelberg.de) Heidelberg Collaboratory for Image Processing, University of Heidelberg, Germany | html generated using doxygen and Python vigra 1.11.1 (Fri May 19 2017)