last update 20 Sep 2009 |
#include <cvrNoise.h>
Classes | |
class | parameters |
The parameters for the class noise. More... | |
Public Member Functions | |
noise () | |
noise (const parameters &par) | |
noise (const noise &other) | |
virtual | ~noise () |
bool | apply (fmatrix &srcdest) const |
bool | apply (dmatrix &srcdest) const |
bool | apply (imatrix &srcdest) const |
bool | apply (matrix< ubyte > &srcdest) const |
bool | apply (fvector &srcdest) const |
bool | apply (dvector &srcdest) const |
bool | apply (ivector &srcdest) const |
bool | apply (const fmatrix &src, fmatrix &dest) const |
bool | apply (const dmatrix &src, dmatrix &dest) const |
bool | apply (const imatrix &src, imatrix &dest) const |
bool | apply (const matrix< ubyte > &src, matrix< ubyte > &dest) const |
bool | apply (const fvector &src, fvector &dest) const |
bool | apply (const dvector &src, dvector &dest) const |
bool | apply (const ivector &src, ivector &dest) const |
noise & | copy (const noise &other) |
noise & | operator= (const noise &other) |
virtual const std::string & | name () const |
virtual noise * | clone () const |
virtual noise * | newInstance () const |
const parameters & | getParameters () const |
bool | updateParameters () |
bool | setNoiseGenerator (univariateContinuousDistribution &generator) |
univariateContinuousDistribution * | getNoiseGenerator () |
Protected Member Functions | |
parameters & | getParameters () |
Protected Attributes | |
univariateContinuousDistribution * | generator_ |
uniformDiscreteDistribution | uniform_ |
This class is used to add noise to an image. In its default configuration gaussian white noise is added to all pixels of the image.
The random number generators provided to this class have to be continuous distributions, which means they generate floating point values. For the fixed point types, like int
and ubyte
, the normalization constants provided by cvr::typeInfo<T>::suggestedNorm() are multiplied to the values generated by the distribution, prior to the addition to the actual value of each matrix element.
You can indicate with the parameter coverage how much of the pixels do you want to be altered with noise, where the specific pixels chosen for modification (if less than 100%) are also taken randomly.
The following example uses noise to generate a sample image with different degrees of noise.
#include "cvrViewer2D.h" #include "cvrMath.h" #include "cvrNoise.h" #include "cvrNormalDistribution.h" // ... channel chnl,chnl2,nchnl; viewer2D view("Original"); noise noiser; // create a black background with a grey square on which a // white square lies. chnl.assign(100,100,0.0f); // 100x100 with black chnl.fill(0.5f,20,20,79,79); // leave a border of 20 chnl.fill(1.0f,40,40,59,59); // the white square // a large canvas to place 5x5 images like the channel just created chnl2.allocate(chnl.rows()*5,chnl.columns()*5); // use a normal distribution normalDistribution nd; normalDistribution::parameters ndp; for (int y=0;y<5;++y) { for (int x=0;x<5;++x) { ndp.sigma = (y*5 + x)/50.0; // set the standard deviation nd.setParameters(ndp); // into the normal distribution noiser.setNoiseGenerator(nd); // which has to be used noiser.apply(chnl,nchnl); // add the noise // place the new noisy patch on the canvas chnl2.fill(nchnl,y*chnl.rows(),x*chnl.columns()); } } // show the canvas view.show(chnl2);
cvr::noise::noise | ( | ) |
Default constructor.
cvr::noise::noise | ( | const parameters & | par | ) |
Construct a functor using the given parameters.
cvr::noise::noise | ( | const noise & | other | ) |
virtual cvr::noise::~noise | ( | ) | [virtual] |
Destructor.
Operates on a copy of the given arguments.
src | ivector with the source data. | |
dest | ivector where the result will be left. |
Operates on a copy of the given arguments.
src | dvector with the source data. | |
dest | dvector where the result will be left. |
Operates on a copy of the given arguments.
src | fvector with the source data. | |
dest | fvector where the result will be left. |
Operates on a copy of the given arguments.
src | matrix<ubyte> with the source data. | |
dest | matrix<ubyte> where the result will be left. |
Implements cvr::matrixProcessingInterface< ubyte >.
Operates on a copy of the given arguments.
src | imatrix with the source data. | |
dest | imatrix where the result will be left. |
Operates on a copy of the given arguments.
src | dmatrix with the source data. | |
dest | dmatrix where the result will be left. |
Operates on a copy of the given arguments.
src | fmatrix with the source data. | |
dest | fmatrix where the result will be left. |
Implements cvr::matrixProcessingInterface< float >.
bool cvr::noise::apply | ( | ivector & | srcdest | ) | const |
Operates on the given argument.
srcdest | ivector with the source data. The result will be left here too. |
bool cvr::noise::apply | ( | dvector & | srcdest | ) | const |
Operates on the given argument.
srcdest | dvector with the source data. The result will be left here too. |
bool cvr::noise::apply | ( | fvector & | srcdest | ) | const |
Operates on the given argument.
srcdest | fvector with the source data. The result will be left here too. |
Operates on the given argument.
srcdest | matrix<ubyte> with the source data. The result will be left here too. |
Implements cvr::matrixProcessingInterface< ubyte >.
bool cvr::noise::apply | ( | imatrix & | srcdest | ) | const |
Operates on the given argument.
srcdest | imatrix with the source data. The result will be left here too. |
bool cvr::noise::apply | ( | dmatrix & | srcdest | ) | const |
Operates on the given argument.
srcdest | dmatrix with the source data. The result will be left here too. |
bool cvr::noise::apply | ( | fmatrix & | srcdest | ) | const [virtual] |
Operates on the given argument.
srcdest | fmatrix with the source data. The result will be left here too. |
Implements cvr::matrixProcessingInterface< float >.
virtual noise* cvr::noise::clone | ( | ) | const [virtual] |
univariateContinuousDistribution* cvr::noise::getNoiseGenerator | ( | ) |
Get the random number generator to be used.
The default value is a normalDistribution with zero mean and a standard deviation of 0.25.
parameters& cvr::noise::getParameters | ( | ) | [protected] |
const parameters& cvr::noise::getParameters | ( | ) | const |
virtual const std::string& cvr::noise::name | ( | ) | const [virtual] |
virtual noise* cvr::noise::newInstance | ( | ) | const [virtual] |
bool cvr::noise::setNoiseGenerator | ( | univariateContinuousDistribution & | generator | ) |
Set the random number generator to be used.
bool cvr::noise::updateParameters | ( | ) | [virtual] |
univariateContinuousDistribution* cvr::noise::generator_ [mutable, protected] |
The noise generator.
uniformDiscreteDistribution cvr::noise::uniform_ [mutable, protected] |
The generator for the coordinates.