75 #ifndef SLIP_NOISE_HPP
76 #define SLIP_NOISE_HPP
80 #include <boost/random.hpp>
107 template<
typename InputIterator,
typename OutputIterator,
typename Real>
111 OutputIterator result,
112 const Real
mean = Real(0.0),
const Real var = Real(0.01))
114 assert(first != last);
115 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
116 boost::normal_distribution<> distrib(
mean,var);
117 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > deg(generator, distrib);
118 for (;first!=last;++first,++result)
120 *result = *first + deg();
148 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename MaskIterator>
152 MaskIterator mask_first,
153 OutputIterator result,
154 const Real
mean = Real(0.0),
const Real var = Real(0.01),
typename std::iterator_traits<MaskIterator>::value_type value=
typename std::iterator_traits<MaskIterator>::value_type(1))
156 assert(first != last);
157 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
158 boost::normal_distribution<> distrib(
mean,var);
159 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > deg(generator, distrib);
160 for (;first!=last;++first,++result,++mask_first)
163 if(*mask_first == value)
165 *result = *first + deg();
202 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename Predicate>
206 OutputIterator result,
208 const Real
mean = Real(0.0),
const Real var = Real(0.01))
210 assert(first != last);
211 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
212 boost::normal_distribution<> distrib(
mean,var);
213 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > deg(generator, distrib);
214 for (;first!=last;++first,++result)
219 *result = *first + deg();
253 template<
typename InputIterator,
typename OutputIterator,
typename Real>
257 OutputIterator result,
258 const Real var = 0.04)
260 assert(first != last);
261 assert (var <= Real(1));
262 assert (var >= Real(0));
263 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
264 boost::normal_distribution<> distrib(-1.0,1.0);
265 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > deg(generator, distrib);
267 for (;first!=last;++first,++result)
269 *result = *first * (1 + deg() * sqrt_value);
298 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename MaskIterator>
302 MaskIterator mask_first,
303 OutputIterator result,
304 const Real var = 0.04,
305 typename std::iterator_traits<MaskIterator>::value_type value=
typename std::iterator_traits<MaskIterator>::value_type(1))
307 assert(first != last);
308 assert (var <= Real(1));
309 assert (var >= Real(0));
310 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
311 boost::normal_distribution<> distrib(-1.0,1.0);
312 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > deg(generator, distrib);
314 for (;first!=last;++first,++result,++mask_first)
316 if(*mask_first == value)
318 *result = *first * (1 + deg() * sqrt_value);
356 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename Predicate>
360 OutputIterator result,
362 const Real var = 0.04)
364 assert(first != last);
365 assert (var <= Real(1));
366 assert (var >= Real(0));
367 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
368 boost::normal_distribution<> distrib(-1.0,1.0);
369 boost::variate_generator<boost::mt19937&, boost::normal_distribution<> > deg(generator, distrib);
371 for (;first!=last;++first,++result)
375 *result = *first * (1 + deg() * sqrt_value);
408 template<
typename InputIterator,
typename OutputIterator,
typename Real>
412 OutputIterator result,
413 const Real
min = Real(0.0),
414 const Real
max = Real(1.0))
416 assert(first != last);
417 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
418 boost::uniform_real<> distrib(
min,
max);
419 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > deg(generator, distrib);
420 for (;first!=last;++first,++result)
422 *result = *first + deg();
451 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename MaskIterator>
455 MaskIterator mask_first,
456 OutputIterator result,
457 const Real
min = Real(0.0),
458 const Real
max = Real(1.0),
459 typename std::iterator_traits<MaskIterator>::value_type value=
typename std::iterator_traits<MaskIterator>::value_type(1))
461 assert(first != last);
462 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
463 boost::uniform_real<> distrib(
min,
max);
464 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > deg(generator, distrib);
465 for (;first!=last;++first,++result,++mask_first)
467 if(*mask_first == value)
469 *result = *first + deg();
505 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename Predicate>
509 OutputIterator result,
511 const Real
min = Real(0.0),
512 const Real
max = Real(1.0))
514 assert(first != last);
515 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
516 boost::uniform_real<> distrib(
min,
max);
517 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > deg(generator, distrib);
518 for (;first!=last;++first,++result)
522 *result = *first + deg();
556 template<
typename InputIterator,
typename OutputIterator,
typename Real>
560 OutputIterator result,
561 const Real density = Real(0.05),
562 const typename std::iterator_traits<OutputIterator>::value_type salt_value =
typename std::iterator_traits<OutputIterator>::value_type(1.0),
563 const typename std::iterator_traits<OutputIterator>::value_type pepper_value =
typename std::iterator_traits<OutputIterator>::value_type(0.0))
565 assert (density <= Real(1));
566 assert (density >= Real(0));
568 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
569 boost::uniform_real<> distrib(0.0,1.0);
570 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > deg(generator, distrib);
571 for (;first!=last;++first,++result)
578 if ((2 * rand) < density)
580 *result = salt_value;
585 *result = pepper_value;
623 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename MaskIterator >
627 MaskIterator mask_first,
628 OutputIterator result,
629 const Real density = Real(0.05),
630 const Real salt_value = Real(1.0),
631 const Real pepper_value = Real(0.0),
632 typename std::iterator_traits<MaskIterator>::value_type value=
typename std::iterator_traits<MaskIterator>::value_type(1))
634 assert (density <= Real(1));
635 assert (density >= Real(0));
637 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
638 boost::uniform_real<> distrib(0.0,1.0);
639 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > deg(generator, distrib);
640 for (;first!=last;++first,++result,++mask_first)
642 if(*mask_first==value)
649 if ((2 * rand) < density)
651 *result = salt_value;
656 *result = pepper_value;
701 template<
typename InputIterator,
typename OutputIterator,
typename Real,
typename Predicate >
705 OutputIterator result,
707 const Real density = Real(0.05),
708 const Real salt_value = Real(1.0),
709 const Real pepper_value = Real(0.0))
711 assert (density <= Real(1));
712 assert (density >= Real(0));
714 boost::mt19937 generator(static_cast<unsigned int>(std::time(0)));
715 boost::uniform_real<> distrib(0.0,1.0);
716 boost::variate_generator<boost::mt19937&, boost::uniform_real<> > deg(generator, distrib);
717 for (;first!=last;++first,++result)
726 if ((2 * rand) < density)
728 *result = salt_value;
733 *result = pepper_value;
752 #endif //SLIP_NOISE_HPP
void add_speckle_noise_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const Real var=0.04)
Add a speckle noise to a container according to a predicate.
void add_salt_and_pepper_noise(InputIterator first, InputIterator last, OutputIterator result, const Real density=Real(0.05), const typename std::iterator_traits< OutputIterator >::value_type salt_value=typename std::iterator_traits< OutputIterator >::value_type(1.0), const typename std::iterator_traits< OutputIterator >::value_type pepper_value=typename std::iterator_traits< OutputIterator >::value_type(0.0))
Add a salt and pepper noise to a container.
T & min(const GrayscaleImage< T > &M1)
Returns the min element of a GrayscaleImage.
void add_uniform_noise_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator result, const Real min=Real(0.0), const Real max=Real(1.0), typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Add a uniform noise to a container according to mask sequence.
void add_uniform_noise(InputIterator first, InputIterator last, OutputIterator result, const Real min=Real(0.0), const Real max=Real(1.0))
Add a uniform noise to a container.
void add_salt_and_pepper_noise_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator result, const Real density=Real(0.05), const Real salt_value=Real(1.0), const Real pepper_value=Real(0.0), typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Add a salt and pepper noise to a container according to a mask sequence.
void add_salt_and_pepper_noise_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const Real density=Real(0.05), const Real salt_value=Real(1.0), const Real pepper_value=Real(0.0))
Add a salt and pepper noise to a container according to a predicate.
void add_gaussian_noise_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const Real mean=Real(0.0), const Real var=Real(0.01))
Add a gaussian noise to a container according to a predicate.
void add_speckle_noise_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator result, const Real var=0.04, typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Add a speckle noise to a container according to a mask sequence.
Value_T mean(InputIterator first, InputIterator last)
Computes the mean value of a range .
HyperVolume< T > sqrt(const HyperVolume< T > &M)
void add_gaussian_noise(InputIterator first, InputIterator last, OutputIterator result, const Real mean=Real(0.0), const Real var=Real(0.01))
Add a gaussian noise to a container.
void add_gaussian_noise_mask(InputIterator first, InputIterator last, MaskIterator mask_first, OutputIterator result, const Real mean=Real(0.0), const Real var=Real(0.01), typename std::iterator_traits< MaskIterator >::value_type value=typename std::iterator_traits< MaskIterator >::value_type(1))
Add a gaussian noise to a container according to a mask sequence.
void add_uniform_noise_if(InputIterator first, InputIterator last, OutputIterator result, Predicate pred, const Real min=Real(0.0), const Real max=Real(1.0))
Add a uniform noise to a container according to a predicate.
T & max(const GrayscaleImage< T > &M1)
Returns the max element of a GrayscaleImage.
void add_speckle_noise(InputIterator first, InputIterator last, OutputIterator result, const Real var=0.04)
Add a speckle noise to a container.