| Bsoft 1.9 Bernard's software package

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Functions | Variables
img_random.cpp File Reference

Functions for generating random images. More...

`#include "rwimg.h"`
`#include "img_combine.h"`
`#include "img_fourier.h"`
`#include "random_numbers.h"`
`#include "utilities.h"`

Go to the source code of this file.

## Functions
Bimage * | img_random_uniform (int nimg, Vector3< int > size, double min, double max)
| Generates an image with a uniform random distribution of densities. More...
Bimage * | img_random_gaussian (int nimg, Vector3< int > size, double avg, double std)
| Generates an image with a gaussian random distribution of densities. More...
Bimage * | img_random_poisson (int nimg, Vector3< int > size, double avg)
| Generates an image with a poisson random distribution of densities. More...
Bimage * | img_random_logistical (int nimg, Vector3< int > size, double avg, double std)
| Generates an image with a gaussian random distribution of densities. More...
Bimage * | img_spectral_noise (int nimg, Vector3< int > size, double alpha)
| Generates a noise map with a defined spectral decay. More...
int | img_add_gaussian_noise (Bimage *p, double snr)
| Adds gaussian random noise to an image. More...
int | img_add_poisson_noise (Bimage *p)
| Adds poisson random noise to an image. More...

## Variables
int | verbose

## Detailed Description

Functions for generating random images.

Author
  Bernard Heymann

Date
  Created: 19990703
  Modified: 20141218

Definition in file img_random.cpp.

## Function Documentation

int img_add_gaussian_noise | ( | Bimage * | p,
|  | double | snr
| ) |  |

Adds gaussian random noise to an image.

Parameters

  *p | image to add noise to (modified, converted to floating point).
  snr | signal_to_noise ratio.

Returns
  int 0.

      An image is generated composed of gaussian noise with an average of
      zero and a standard deviation of:
          std_noise = std_image/sqrt(snr)
      The noise image is added to the input image.
      Statistics are calculated before returning.

  Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 284 of file img_random.cpp.

int img_add_poisson_noise | ( | Bimage * | p | ) |

Adds poisson random noise to an image.

Parameters

  *p | image to add noise to (modified, converted to floating point).

Returns
  int 0.

      Each value in the image is taken as the average for generating a new
      value with a Poisson distribution.
      Values less than zero become zero.
      Values above zero become integer values varying from the original
      values according to a Poisson distribution.
      Statistics are calculated before returning.

  Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 324 of file img_random.cpp.

Bimage* img_random_gaussian | ( | int | nimg,
|  | Vector3< int > | size,
|  | double | avg,
|  | double | std
| ) |  |

Generates an image with a gaussian random distribution of densities.

Parameters

  nimg | number of sub-images to generate.
  size | 3-valued vector for the size of the image.
  avg | average.
  std | standard deviation.

Returns
  Bimage* the random image.

      An image with a given datatype, number of subimages, and size is
      generated with densities with a gaussian distribution with a given
      average and standard deviation:
          density = average + std_dev*sqrt(-2*log(random_value))*
                          cos(2*PI*random_value);
      where random_value is between 0 and 1.
      The output image is floating point.
      Statistics are calculated before returning.

Definition at line 80 of file img_random.cpp.

Bimage* img_random_logistical | ( | int | nimg,
|  | Vector3< int > | size,
|  | double | avg,
|  | double | std
| ) |  |

Generates an image with a gaussian random distribution of densities.

Parameters

  nimg | number of sub-images to generate.
  size | 3-valued vector for the size of the image.
  avg | average.
  std | standard deviation.

Returns
  Bimage* the random image.

      An image with a given datatype, number of subimages, and size is
      generated with densities with a logistical differential distribution
      with a given average and standard deviation:
          density = average + (std_dev/golden)*ln(1/random_value - 1)
      where random_value is between 0 and 1 and:
          golden  = (sqrt(5) + 1)/2
      The output image is floating point.
      Statistics are calculated before returning.

  Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 175 of file img_random.cpp.

Bimage* img_random_poisson | ( | int | nimg,
|  | Vector3< int > | size,
|  | double | avg
| ) |  |

Generates an image with a poisson random distribution of densities.

Parameters

  nimg | number of sub-images to generate.
  size | 3-valued vector for the size of the image.
  avg | average.

Returns
  Bimage* the random image, NULL on error.

      Algorithm taken from Numerical Recipes in C.
      The poisson distribution is given for j = 0,1,... by:
                  avg^j * exp(-avg)
          P(j) = -----------------
                         j!
      Note that only positive integer values are defined for j and sum(P(j)) = 1.
      An array of floating point numbers is generated with a poisson
      distribution with a given average. The standard deviation is:
          std = sqrt(avg)
      If the average <= 0, the function exits.
      Statistics are calculated before returning.

  Reference: Press W.H. et al (1992) Numerical Recipes in C.

Definition at line 127 of file img_random.cpp.

Bimage* img_random_uniform | ( | int | nimg,
|  | Vector3< int > | size,
|  | double | min,
|  | double | max
| ) |  |

Generates an image with a uniform random distribution of densities.

Parameters

  nimg | number of sub-images to generate.
  size | 3-valued vector for the size of the image.
  min | minimum density value.
  max | maximum density value.

Returns
  Bimage* the random image.

      An image with a given datatype, number of subimages, and size is
      generated with densities distributed uniformly in the range of the
      given minimum and maximum:
          density = random_value*(max - min) + min
      where random_value is between 0 and 1.
      The average and standard deviation are:
          average = (max + min)/2
          standard deviation = 0.5*sqrt(1/3)*(max - min).
      The output image is floating point.
      Statistics are calculated before returning.

Definition at line 38 of file img_random.cpp.

Bimage* img_spectral_noise | ( | int | nimg,
|  | Vector3< int > | size,
|  | double | alpha
| ) |  |

Generates a noise map with a defined spectral decay.

Parameters

  nimg | number of sub-images.
  size | image size.
  alpha | spectral decay.

Returns
  Bimage* new noise image.

      Uniform random phases are generated and the amplitudes are set to:
          amp = s^(-alpha/2).

Definition at line 210 of file img_random.cpp.

## Variable Documentation

int verbose