- Main Page
- Modules
- Classes
- Files

# DSP

## Enumerations
enum | CxImage::ImageOpType { CxImage::OpAdd, CxImage::OpAnd, CxImage::OpXor, CxImage::OpOr, CxImage::OpMask, CxImage::OpSrcCopy, CxImage::OpDstCopy, CxImage::OpSub, CxImage::OpSrcBlend, CxImage::OpScreen, CxImage::OpAvg }
## Functions
bool | CxImage::Contour ()
bool | CxImage::HistogramStretch (long method=0, double threshold=0)
bool | CxImage::HistogramEqualize ()
bool | CxImage::HistogramNormalize ()
bool | CxImage::HistogramRoot ()
bool | CxImage::HistogramLog ()
long | CxImage::Histogram (long *red, long *green=0, long *blue=0, long *gray=0, long colorspace=0)
bool | CxImage::Jitter (long radius=2)
bool | CxImage::Repair (float radius=0.25f, long niterations=1, long colorspace=0)
bool | CxImage::Combine (CxImage *r, CxImage *g, CxImage *b, CxImage *a, long colorspace=0)
bool | CxImage::FFT2 (CxImage *srcReal, CxImage *srcImag, CxImage *dstReal, CxImage *dstImag, long direction=1, bool bForceFFT=true, bool bMagnitude=true)
bool | CxImage::Noise (long level)
bool | CxImage::Median (long Ksize=3)
bool | CxImage::Gamma (float gamma)
bool | CxImage::GammaRGB (float gammaR, float gammaG, float gammaB)
bool | CxImage::ShiftRGB (long r, long g, long b)
bool | CxImage::Threshold (BYTE level)
bool | CxImage::Threshold (CxImage *pThresholdMask)
bool | CxImage::Threshold2 (BYTE level, bool bDirection, RGBQUAD nBkgndColor, bool bSetAlpha=false)
bool | CxImage::Colorize (BYTE hue, BYTE sat, float blend=1.0f)
bool | CxImage::Light (long brightness, long contrast=0)
float | CxImage::Mean ()
bool | CxImage::Filter (long *kernel, long Ksize, long Kfactor, long Koffset)
bool | CxImage::Erode (long Ksize=2)
bool | CxImage::Dilate (long Ksize=2)
bool | CxImage::Edge (long Ksize=2)
void | CxImage::HuePalette (float correction=1)
void | CxImage::Mix (CxImage &imgsrc2, ImageOpType op, long lXOffset=0, long lYOffset=0, bool bMixAlpha=false)
void | CxImage::MixFrom (CxImage &imagesrc2, long lXOffset, long lYOffset)
bool | CxImage::UnsharpMask (float radius=5.0f, float amount=0.5f, int threshold=0)
bool | CxImage::Lut (BYTE *pLut)
bool | CxImage::Lut (BYTE *pLutR, BYTE *pLutG, BYTE *pLutB, BYTE *pLutA=0)
bool | CxImage::GaussianBlur (float radius=1.0f, CxImage *iDst=0)
bool | CxImage::TextBlur (BYTE threshold=100, BYTE decay=2, BYTE max_depth=5, bool bBlurHorizontal=true, bool bBlurVertical=true, CxImage *iDst=0)
bool | CxImage::SelectiveBlur (float radius=1.0f, BYTE threshold=25, CxImage *iDst=0)
bool | CxImage::Solarize (BYTE level=128, bool bLinkedChannels=true)
bool | CxImage::FloodFill (const long xStart, const long yStart, const RGBQUAD cFillColor, const BYTE tolerance=0, BYTE nOpacity=255, const bool bSelectFilledArea=false, const BYTE nSelectionLevel=255)
bool | CxImage::Saturate (const long saturation, const long colorspace=1)
bool | CxImage::ConvertColorSpace (const long dstColorSpace, const long srcColorSpace)
int | CxImage::OptimalThreshold (long method=0, RECT *pBox=0, CxImage *pContrastMask=0)
bool | CxImage::AdaptiveThreshold (long method=0, long nBoxSize=64, CxImage *pContrastMask=0, long nBias=0, float fGlobalLocalBalance=0.5f)

## Detailed Description

## Enumeration Type Documentation

enum CxImage::ImageOpType`[inherited]`

Enumerator:

  OpAdd |
  OpAnd |
  OpXor |
  OpOr |
  OpMask |
  OpSrcCopy |
  OpDstCopy |
  OpSub |
  OpSrcBlend |
  OpScreen |
  OpAvg |

## Function Documentation

bool CxImage::AdaptiveThreshold | ( | long | method = `0`,
|  | long | nBoxSize = `64`,
|  | CxImage * | pContrastMask = `0`,
|  | long | nBias = `0`,
|  | float | fGlobalLocalBalance = `0.5f` |
| ) |  |  | `[inherited]`

Converts the image to B&W, using an optimal threshold mask

Parameters:

  | method,: | 0 = average all methods (default); 1 = Otsu; 2 = Kittler & Illingworth; 3 = max entropy; 4 = potential difference;
  | nBoxSize,: | the image is divided into "nBoxSize x nBoxSize" blocks, from where the threshold is computed; min = 8; default = 64.
  | pContrastMask,: | limit the computation only in regions with contrasted (!=0) pixels; default = 0.
  | nBias,: | global offset added to the threshold mask; default = 0.
  | fGlobalLocalBalance,: | balance between local and global threshold. default = 0.5 fGlobalLocalBalance can be from 0.0 (use only local threshold) to 1.0 (use only global threshold) the pContrastMask image must be grayscale with same with and height of the current image,

Returns:
  true if everything is ok.

See also:
  OptimalThreshold

bool CxImage::Colorize | ( | BYTE | hue,
|  | BYTE | sat,
|  | float | blend = `1.0f` |
| ) |  |  | `[inherited]`

Replaces the original hue and saturation values.

Parameters:

  | hue,: | hue
  | sat,: | saturation
  | blend,: | can be from 0 (no effect) to 1 (full effect)

Returns:
  true if everything is ok

bool CxImage::Combine | ( | CxImage * | r,
|  | CxImage * | g,
|  | CxImage * | b,
|  | CxImage * | a,
|  | long | colorspace = `0` |
| ) |  |  | `[inherited]`

Combines different color components into a single image

Parameters:

  | r,g,b,: | color channels
  | a,: | alpha layer, can be NULL
  | colorspace,: | 0 = RGB, 1 = HSL, 2 = YUV, 3 = YIQ, 4 = XYZ

Returns:
  true if everything is ok

bool CxImage::Contour | ( |  | ) | `[inherited]`

Enhance the variations between adjacent pixels. Similar results can be achieved using Filter(), but the algorithms are different both in Edge() and in Contour().

Returns:
  true if everything is ok

bool CxImage::ConvertColorSpace | ( | const long | dstColorSpace,
|  | const long | srcColorSpace |
| ) |  |  | `[inherited]`

Converts the RGB triplets to and from different colorspace

Parameters:

  | dstColorSpace,: | destination colorspace; 0 = RGB, 1 = HSL, 2 = YUV, 3 = YIQ, 4 = XYZ
  | srcColorSpace,: | source colorspace; 0 = RGB, 1 = HSL, 2 = YUV, 3 = YIQ, 4 = XYZ

Returns:
  true if everything is ok

bool CxImage::Dilate | ( | long | Ksize = `2` | ) | `[inherited]`

Enhance the light areas of the image

Parameters:

  | Ksize,: | size of the kernel.

Returns:
  true if everything is ok

bool CxImage::Edge | ( | long | Ksize = `2` | ) | `[inherited]`

Enhance the variations between adjacent pixels. Similar results can be achieved using Filter(), but the algorithms are different both in Edge() and in Contour().

Parameters:

  | Ksize,: | size of the kernel.

Returns:
  true if everything is ok

bool CxImage::Erode | ( | long | Ksize = `2` | ) | `[inherited]`

Enhance the dark areas of the image

Parameters:

  | Ksize,: | size of the kernel.

Returns:
  true if everything is ok

bool CxImage::FFT2 | ( | CxImage * | srcReal,
|  | CxImage * | srcImag,
|  | CxImage * | dstReal,
|  | CxImage * | dstImag,
|  | long | direction = `1`,
|  | bool | bForceFFT = `true`,
|  | bool | bMagnitude = `true` |
| ) |  |  | `[inherited]`

Computes the bidimensional FFT or DFT of the image.

- The images are processed as grayscale
- If the dimensions of the image are a power of, 2 the FFT is performed automatically.
- If dstReal and/or dstImag are NULL, the resulting images replaces the original(s).
- Note: with 8 bits there is a HUGE loss in the dynamics. The function tries to keep an acceptable SNR, but 8bit = 48dB...

Parameters:

  | srcReal,srcImag,: | source images: One can be NULL, but not both
  | dstReal,dstImag,: | destination images. Can be NULL.
  | direction,: | 1 = forward, -1 = inverse.
  | bForceFFT,: | if true, the images are resampled to make the dimensions a power of 2.
  | bMagnitude,: | if true, the real part returns the magnitude, the imaginary part returns the phase

Returns:
  true if everything is ok

bool CxImage::Filter | ( | long * | kernel,
|  | long | Ksize,
|  | long | Kfactor,
|  | long | Koffset |
| ) |  |  | `[inherited]`

2D linear filter

Parameters:

  | kernel,: | convolving matrix, in row format.
  | Ksize,: | size of the kernel.
  | Kfactor,: | normalization constant.
  | Koffset,: | bias.
      Example: the "soften" filter uses this kernel:
      	1 1 1
      	1 8 1
      	1 1 1
       the function needs: kernel={1,1,1,1,8,1,1,1,1}; Ksize=3; Kfactor=16; Koffset=0;

Returns:
  true if everything is ok

bool CxImage::FloodFill | ( | const long | xStart,
|  | const long | yStart,
|  | const RGBQUAD | cFillColor,
|  | const BYTE | nTolerance = `0`,
|  | BYTE | nOpacity = `255`,
|  | const bool | bSelectFilledArea = `false`,
|  | const BYTE | nSelectionLevel = `255` |
| ) |  |  | `[inherited]`

Flood Fill

Parameters:

  | xStart,yStart,: | starting point
  | cFillColor,: | filling color
  | nTolerance,: | deviation from the starting point color
  | nOpacity,: | can be from 0 (transparent) to 255 (opaque, default)
  | bSelectFilledArea,: | if true, the pixels in the region are also set in the selection layer; default = false
  | nSelectionLevel,: | if bSelectFilledArea is true, the selected pixels are set to nSelectionLevel; default = 255 Note: nOpacity=0 && bSelectFilledArea=true act as a "magic wand"

Returns:
  true if everything is ok

bool CxImage::Gamma | ( | float | gamma | ) | `[inherited]`

Adjusts the color balance of the image

Parameters:

  | gamma | can be from 0.1 to 5.

Returns:
  true if everything is ok

See also:
  GammaRGB

bool CxImage::GammaRGB | ( | float | gammaR,
|  | float | gammaG,
|  | float | gammaB |
| ) |  |  | `[inherited]`

Adjusts the color balance indipendent for each color channel

Parameters:

  | gammaR,gammaG,gammaB | can be from 0.1 to 5.

Returns:
  true if everything is ok

See also:
  Gamma

bool CxImage::GaussianBlur | ( | float | radius = `1.0f`,
|  | CxImage * | iDst = `0` |
| ) |  |  | `[inherited]`

Author:
  [nipper]; changes [DP]

long CxImage::Histogram | ( | long * | red,
|  | long * | green = `0`,
|  | long * | blue = `0`,
|  | long * | gray = `0`,
|  | long | colorspace = `0` |
| ) |  |  | `[inherited]`

bool CxImage::HistogramEqualize | ( |  | ) | `[inherited]`

bool CxImage::HistogramLog | ( |  | ) | `[inherited]`

bool CxImage::HistogramNormalize | ( |  | ) | `[inherited]`

bool CxImage::HistogramRoot | ( |  | ) | `[inherited]`

bool CxImage::HistogramStretch | ( | long | method = `0`,
|  | double | threshold = `0` |
| ) |  |  | `[inherited]`

HistogramStretch

Parameters:

  | method,: | 0 = luminance (default), 1 = linked channels , 2 = independent channels.
  | threshold,: | minimum percentage level in the histogram to recognize it as meaningful. Range: 0.0 to 1.0; default = 0; typical = 0.005 (0.5%);

Returns:
  true if everything is ok

Author:
  [dave] and [nipper]; changes [DP]

void CxImage::HuePalette | ( | float | correction = `1` | ) | `[inherited]`

Generates a "rainbow" palette with saturated colors

Parameters:

  | correction,: | 1 generates a single hue spectrum. 0.75 is nice for scientific applications.

bool CxImage::Jitter | ( | long | radius = `2` | ) | `[inherited]`

Adds a random offset to each pixel in the image

Parameters:

  | radius,: | maximum pixel displacement

Returns:
  true if everything is ok

bool CxImage::Light | ( | long | brightness,
|  | long | contrast = `0` |
| ) |  |  | `[inherited]`

Changes the brightness and the contrast of the image.

Parameters:

  | brightness,: | can be from -255 to 255, if brightness is negative, the image becomes dark.
  | contrast,: | can be from -100 to 100, the neutral value is 0.

Returns:
  true if everything is ok

bool CxImage::Lut | ( | BYTE * | pLutR,
|  | BYTE * | pLutG,
|  | BYTE * | pLutB,
|  | BYTE * | pLutA = `0` |
| ) |  |  | `[inherited]`

Apply an indipendent look up table for each channel

Parameters:

  | pLutR,pLutG,pLutB,pLutA,: | BYTE[256] look up tables

Returns:
  true if everything is ok

bool CxImage::Lut | ( | BYTE * | pLut | ) | `[inherited]`

Apply a look up table to the image.

Parameters:

  | pLut,: | BYTE[256] look up table

Returns:
  true if everything is ok

float CxImage::Mean | ( |  | ) | `[inherited]`

Returns:
  mean lightness of the image. Useful with Threshold() and Light()

bool CxImage::Median | ( | long | Ksize = `3` | ) | `[inherited]`

Adjusts the intensity of each pixel to the median intensity of its surrounding pixels.

Parameters:

  | Ksize,: | size of the kernel.

Returns:
  true if everything is ok

void CxImage::Mix | ( | CxImage & | imgsrc2,
|  | ImageOpType | op,
|  | long | lXOffset = `0`,
|  | long | lYOffset = `0`,
|  | bool | bMixAlpha = `false` |
| ) |  |  | `[inherited]`

Blends two images

Parameters:

  | imgsrc2,: | image to be mixed with this
  | op,: | blending method; see ImageOpType
  | lXOffset,lYOffset,: | image displacement
  | bMixAlpha,: | if true and imgsrc2 has a valid alpha layer, it will be mixed in the destination image.

Returns:
  true if everything is ok

thanks to Mwolski

void CxImage::MixFrom | ( | CxImage & | imagesrc2,
|  | long | lXOffset,
|  | long | lYOffset |
| ) |  |  | `[inherited]`

bool CxImage::Noise | ( | long | level | ) | `[inherited]`

Adds an uniform noise to the image

Parameters:

  | level,: | can be from 0 (no noise) to 255 (lot of noise).

Returns:
  true if everything is ok

int CxImage::OptimalThreshold | ( | long | method = `0`,
|  | RECT * | pBox = `0`,
|  | CxImage * | pContrastMask = `0` |
| ) |  |  | `[inherited]`

Finds the optimal (global or local) treshold for image binarization

Parameters:

  | method,: | 0 = average all methods (default); 1 = Otsu; 2 = Kittler & Illingworth; 3 = max entropy; 4 = potential difference;
  | pBox,: | region from where the threshold is computed; 0 = full image (default).
  | pContrastMask,: | limit the computation only in regions with contrasted (!=0) pixels; default = 0. the pContrastMask image must be grayscale with same with and height of the current image, can be obtained from the current image with a filter: CxImage iContrastMask(*image,true,false,false); iContrastMask.GrayScale(); long edge[]={-1,-1,-1,-1,8,-1,-1,-1,-1}; iContrastMask.Filter(edge,3,1,0); long blur[]={1,1,1,1,1,1,1,1,1}; iContrastMask.Filter(blur,3,9,0);

Returns:
  optimal threshold; -1 = error.

See also:
  AdaptiveThreshold

bool CxImage::Repair | ( | float | radius = `0.25f`,
|  | long | niterations = `1`,
|  | long | colorspace = `0` |
| ) |  |  | `[inherited]`

Smart blurring to remove small defects, dithering or artifacts.

Parameters:

  | radius,: | normally between 0.01 and 0.5
  | niterations,: | should be trimmed with radius, to avoid blurring should be (radius*niterations)<1
  | colorspace,: | 0 = RGB, 1 = HSL, 2 = YUV, 3 = YIQ, 4 = XYZ

Returns:
  true if everything is ok

bool CxImage::Saturate | ( | const long | saturation,
|  | const long | colorspace = `1` |
| ) |  |  | `[inherited]`

Changes the saturation of the image.

Parameters:

  | saturation,: | can be from -100 to 100, positive values increase the saturation.
  | colorspace,: | can be 1 (HSL) or 2 (YUV).

Returns:
  true if everything is ok

bool CxImage::SelectiveBlur | ( | float | radius = `1.0f`,
|  | BYTE | threshold = `25`,
|  | CxImage * | iDst = `0` |
| ) |  |  | `[inherited]`

Author:
  [DP],[nipper]

bool CxImage::ShiftRGB | ( | long | r,
|  | long | g,
|  | long | b |
| ) |  |  | `[inherited]`

Adjusts separately the red, green, and blue values in the image.

Parameters:

  | r,g,b,: | can be from -255 to +255.

Returns:
  true if everything is ok

bool CxImage::Solarize | ( | BYTE | level = `128`,
|  | bool | bLinkedChannels = `true` |
| ) |  |  | `[inherited]`

Solarize: convert all colors above a given lightness level into their negative

Parameters:

  | level | : lightness threshold. Range = 0 to 255; default = 128.
  | bLinkedChannels,: | true = compare with luminance, preserve colors (default) false = compare with independent R,G,B levels

Returns:
  true if everything is ok

Author:
  [Priyank Bolia] (priyank_bolia(at)yahoo(dot)com); changes [DP]

bool CxImage::TextBlur | ( | BYTE | threshold = `100`,
|  | BYTE | decay = `2`,
|  | BYTE | max_depth = `5`,
|  | bool | bBlurHorizontal = `true`,
|  | bool | bBlurVertical = `true`,
|  | CxImage * | iDst = `0` |
| ) |  |  | `[inherited]`

Author:
  [DP]

bool CxImage::Threshold | ( | CxImage * | pThresholdMask | ) | `[inherited]`

Converts the image to B&W, using a threshold mask

Parameters:

  | pThresholdMask,: | the lightness threshold mask. the pThresholdMask image must be grayscale with same with and height of the current image

Returns:
  true if everything is ok

bool CxImage::Threshold | ( | BYTE | level | ) | `[inherited]`

Converts the image to B&W. The OptimalThreshold() function can be used for calculating the optimal threshold.

Parameters:

  | level,: | the lightness threshold.

Returns:
  true if everything is ok

bool CxImage::Threshold2 | ( | BYTE | level,
|  | bool | bDirection,
|  | RGBQUAD | nBkgndColor,
|  | bool | bSetAlpha = `false` |
| ) |  |  | `[inherited]`

Filters only the pixels with a lightness less (or more) than the threshold level, and preserves the colors for the unfiltered pixels.

Parameters:

  | level | = the lightness threshold.
  | bDirection | = false: filter dark pixels, true: filter light pixels
  | nBkgndColor | = filtered pixels are set to nBkgndColor color
  | bSetAlpha | = if true, sets also the alpha component for the filtered pixels, with nBkgndColor.rgbReserved

Returns:
  true if everything is ok

Author:
  [DP], [wangsongtao]

bool CxImage::UnsharpMask | ( | float | radius = `5.0f`,
|  | float | amount = `0.5f`,
|  | int | threshold = `0` |
| ) |  |  | `[inherited]`

sharpen the image by subtracting a blurred copy from the original image.

Parameters:

  | radius,: | width in pixels of the blurring effect. Range: >0; default = 5.
  | amount,: | strength of the filter. Range: 0.0 (none) to 1.0 (max); default = 0.5
  | threshold,: | difference, between blurred and original pixel, to trigger the filter Range: 0 (always triggered) to 255 (never triggered); default = 0.

Returns:
  true if everything is ok

Author:
  [nipper]; changes [DP]