Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ColorOps.H File Reference


Detailed Description

Color operations on Image

Definition in file ColorOps.H.

#include "Image/Image.H"
#include "Util/Assert.H"
#include "Util/Promotions.H"

Include dependency graph for ColorOps.H:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

template<class T>
Image< PixRGB< T > > makeRGB (const Image< T > &red, const Image< T > &green, const Image< T > &blue)
 Set the red, green and blue components from 3 monochromatic images.
Image< PixRGB< byte > > colorize (const Image< byte > &img, const ColorMap &cmap)
 Colorize a greyscale byte image using a colormap.
void inplaceColorSpeckleNoise (Image< PixRGB< byte > > &dest, const int num)
 Add color speckle noise to array; faster version, draws 'num' dots.
template<class T>
void getComponents (const Image< PixRGB< T > > &src, Image< T > &red, Image< T > &green, Image< T > &blue)
 Get the red, green and blue components as 3 monochromatic images.
template<class PixT>
Image< typename PixT::ScalarType > getPixelComponentImage (const Image< PixT > &in, const size_t i)
 Split out a single pixel component image from a multispectral pixel input image.
Image< PixRGB< float > > normalizeRGPolar (const Image< float > &src, const float max, const float min)
Image< PixRGB< float > > normalizeRGPolarAuto (const Image< float > &src)
Image< PixRGB< float > > normalizeWithScale (const Image< float > &src, const float min, const float max, const float clamp, const char baseColor, const char normColor)
 Normalize a grey scale image, with some idea for scale.
Image< PixRGB< float > > normalizeScaleRainbow (const Image< float > &src, const float min, const float max)
 Normalize a grey scale image, with some idea for scale.
template<class T>
Image< PixRGB< T > > stain (const Image< T > &src, PixRGB< float > color)
 Create a color image by staining a monochrome image.
Image< PixRGB< float > > stainPosNeg (const Image< float > &src, const float maxval, const PixRGB< float > &background, const PixRGB< float > &pos_stain, const PixRGB< float > &neg_stain)
 Create a color image from src by tinting positive and negative values.
Image< PixRGB< float > > overlayStain (const Image< float > &top, const Image< float > &bottom, const float trans, const char channel)
 Overlay an image over another, however, stain the top image.
template<class T>
void getMinMaxC (const Image< PixRGB< T > > &src, T &mi, T &ma)
 Get min and max of the components.
template<class T, class T2>
void normalizeC (Image< PixRGB< T > > &src, const T2 nmin, const T2 nmax)
 Normalize values between nmin and nmax.
template<class T>
Image< T > luminance (const Image< PixRGB< T > > &src)
 Compute luminance of a color image.
template<class T>
Image< T > luminance (const Image< T > &src)
 Compute luminance of a greyscale image (no-op).
template<class T>
Image< T > luminanceNTSC (const Image< PixRGB< T > > &src)
 Compute luminance in NTSC coordinates.
template<class T>
Image< PixRGB< T > > toRGB (const Image< T > &src)
 Convert grayscale image to RGB.
template<class T>
Image< PixRGB< T > > toRGB (const Image< PixRGB< T > > &src)
 Convert RGB image to RGB (no-op).
template<class T>
Image< float > infoMeasure (const Image< PixRGB< T > > &src, const float eps, const int size)
 Compute color information measure based in infoFFT.
template<class T>
void getYIQ (const Image< PixRGB< T > > &src, Image< T > &y, Image< T > &i, Image< T > &q)
 Get YIQ color components.
template<class T>
void getJpegYUV (const Image< PixRGB< T > > &src, Image< T > &y, Image< T > &u, Image< T > &v)
 Get YUV color components from an RGB image.
template<class T>
Image< PixRGB< T > > luminanceNormalize (const Image< PixRGB< T > > &src, const T thresh)
 Normalize my values by those in the lum image.
template<class T>
void getRGBY (const Image< PixRGB< T > > &src, Image< typename promote_trait< T, float >::TP > &rg, Image< typename promote_trait< T, float >::TP > &by, const typename promote_trait< T, float >::TP thresh)
 Compute R/G and B/Y channels from a luminanceNormalized color image.
template<class T>
void getRGBYsimple (const Image< PixRGB< T > > &src, Image< typename promote_trait< T, float >::TP > &rg, Image< typename promote_trait< T, float >::TP > &by, const typename promote_trait< T, float >::TP thresh)
 Compute R/G and B/Y channels in a simpler way.
template<class T>
void getRGBY (const Image< PixRGB< T > > &src, Image< T > &r, Image< T > &g, Image< T > &b, Image< T > &y, const T thresh)
 Compute R, G, B, Y channels from a luminanceNormalized color image.
template<class T>
void getRGBY (const Image< PixRGB< T > > &src, Image< T > &rg, Image< T > &by, Image< T > &sat, Image< T > &val, const ushort H2SVtype=2)
 Compute R/G and B/Y via computation of H2SV2 color space.
template<class T>
void getDKL (const Image< PixRGB< T > > &src, Image< typename promote_trait< T, float >::TP > &dimg, Image< typename promote_trait< T, float >::TP > &kimg, Image< typename promote_trait< T, float >::TP > &limg)
 Compute D, K, L color components from an RGB image.
Image< PixRGB< byte > > contrastModulate (const Image< PixRGB< byte > > &img, const Image< float > &mask, float baseContrast=0.05, byte baseBright=255)
 contrast-modulate an RGB image with a mask
template<class T>
double pSNRcolor (const Image< PixRGB< T > > &img1, const Image< PixRGB< T > > &img2)
 Compute peak signal-to-noise ratio between two color images.
template<class T>
double pSNRcolor (const Image< PixRGB< T > > &img1, const Image< PixRGB< T > > &img2, const Image< float > &weight)
 Compute weighted peak signal-to-noise ratio between two color images.
template<class T>
Image< PixRGB< T > > normalizeRGB (const Image< PixRGB< T > > &img, PixRGB< T > min, PixRGB< T > max)
 Normalize each component of the RGB image separately.
template<class T>
Image< T > maxRGB (const Image< PixRGB< T > > &img)
 Return the pixel-wise maximum of the r, g and b component.
template<class T>
Image< PixRGB< T > > colorStain (const Image< T > &src, const T &min, const T &max, const PixRGB< T > &color)
 Stain a black and white image with a color.
void RGBtoCIE (const PixRGB< byte > &rgbColor, float &cr, float &cg, float &intens)
 convert RGB color values into C.I.E. coordinates
Image< float > hueDistance (const Image< PixRGB< byte > > &img, float muR, float muG, float sigR, float sigG, float rho)
 distance between hue of image pixels and a given hue


Function Documentation

Image< PixRGB<byte> > colorize const Image< byte > &  img,
const ColorMap cmap
 

Colorize a greyscale byte image using a colormap.

Note that this will throw a fatal error if the colormap does not have exactly 256 entries.

template<class T>
Image< PixRGB<T> > colorStain const Image< T > &  src,
const T &  min,
const T &  max,
const PixRGB< T > &  color
 

Stain a black and white image with a color.

Parameters:
src the black and white image to be stained
min This value will be converted to 0 (black)
max This value will be converted to color
color The color used for staining

Definition at line 918 of file ColorOps.C.

References ASSERT, Image< T >::begin(), Image< T >::beginw(), Image< T >::end(), Image< T >::getDims(), GVX_TRACE, NO_INIT, and lobot::stop().

Referenced by main().

Image< PixRGB<byte> > contrastModulate const Image< PixRGB< byte > > &  img,
const Image< float > &  mask,
float  baseContrast = 0.05,
byte  baseBright = 255
 

contrast-modulate an RGB image with a mask

template<class T>
void getComponents const Image< PixRGB< T > > &  src,
Image< T > &  red,
Image< T > &  green,
Image< T > &  blue
 

Get the red, green and blue components as 3 monochromatic images.

Definition at line 122 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), GVX_TRACE, NO_INIT, src, and lobot::stop().

Referenced by RGBConvolvePyrBuilder< T >::build(), RGBConvolvePyrBuilder< T >::build2(), ImagizeColorChannel::doInput(), SplitRgbOfilt::filterFrame(), main(), maxRGB(), normalizeRGB(), StatsOutputSeries::Impl::printStatsRGB(), pSNRcolor(), Raster_xx_img_gray_write_gray_read_rgb_xx_1(), Raster_xx_img_gray_write_rgb_read_rgb_xx_1(), and rectifyRgb().

template<class T>
void getDKL const Image< PixRGB< T > > &  src,
Image< typename promote_trait< T, float >::TP > &  dimg,
Image< typename promote_trait< T, float >::TP > &  kimg,
Image< typename promote_trait< T, float >::TP > &  limg
 

Compute D, K, L color components from an RGB image.

The DKL color space is motivated by the neurobiology of early vision in primates. D is roughly like luminance (with some neutral grey (RGB=[161 159 154]) at zero, white around 1.0, and black around -1.0), K roughly like Red-Green, and L roughly like Blue-Yellow. The images returned here have signed float values roughly in [-1,1] (but they sometimes are slightly larger that exactly that, so be sure to clamp if you ar egoing to convert).

Definition at line 809 of file ColorOps.C.

References ASSERT, PixDKL< T >::D(), GVX_TRACE, PixDKL< T >::K(), PixDKL< T >::L(), NO_INIT, p, src, and lobot::stop().

Referenced by DKLcolorChannel::doInput().

template<class T>
void getJpegYUV const Image< PixRGB< T > > &  src,
Image< T > &  y,
Image< T > &  u,
Image< T > &  v
[inline]
 

Get YUV color components from an RGB image.

Definition at line 545 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), GVX_TRACE, NO_INIT, src, lobot::stop(), PixJpegYUV< T >::U(), PixJpegYUV< T >::V(), and PixJpegYUV< T >::Y().

template<class T>
void getMinMaxC const Image< PixRGB< T > > &  src,
T &  mi,
T &  ma
 

Get min and max of the components.

Definition at line 352 of file ColorOps.C.

References ASSERT, GVX_TRACE, src, lobot::stop(), and x.

Referenced by buildTitle(), normalizeC(), normalizeFloatRgb(), and Raster::VisuRGB().

template<class PixT>
Image<typename PixT::ScalarType> getPixelComponentImage const Image< PixT > &  in,
const size_t  i
[inline]
 

Split out a single pixel component image from a multispectral pixel input image.

Definition at line 77 of file ColorOps.H.

References ASSERT, Image< T >::begin(), Image< T >::beginw(), Image< T >::endw(), Image< T >::getDims(), NO_INIT, and lobot::stop().

Referenced by segmentColor().

template<class T>
void getRGBY const Image< PixRGB< T > > &  src,
Image< T > &  rg,
Image< T > &  by,
Image< T > &  sat,
Image< T > &  val,
const ushort  H2SVtype = 2
 

Compute R/G and B/Y via computation of H2SV2 color space.

In addition to returning R/G and B/Y this basically returns the full H2SV color space. the original RGB can be obtained later via conversion of rg,by, sat and val using a PixH2SV2 to RGB

Definition at line 769 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), GVX_TRACE, PixH2SV2< T >::H1(), PixH2SV1< T >::H1(), PixH2SV2< T >::H2(), PixH2SV1< T >::H2(), LFATAL, NO_INIT, PixH2SV2< T >::S(), PixH2SV1< T >::S(), src, PixH2SV2< T >::V(), and PixH2SV1< T >::V().

template<class T>
void getRGBY const Image< PixRGB< T > > &  src,
Image< T > &  r,
Image< T > &  g,
Image< T > &  b,
Image< T > &  y,
const T  thresh
 

Compute R, G, B, Y channels from a luminanceNormalized color image.

This version keeps the four channels separate so that correct results can be obtained without requiring promotion even if the input is of type PixRGB<byte>

Definition at line 709 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), GVX_TRACE, lum, NO_INIT, src, and lobot::stop().

template<class T>
void getRGBY const Image< PixRGB< T > > &  src,
Image< typename promote_trait< T, float >::TP > &  rg,
Image< typename promote_trait< T, float >::TP > &  by,
const typename promote_trait< T, float >::TP  thresh
 

Compute R/G and B/Y channels from a luminanceNormalized color image.

This version does automatic promotion on the results, so that negative values can be represented even if the input is of type PixRGB<byte>

template<class T>
void getRGBYsimple const Image< PixRGB< T > > &  src,
Image< typename promote_trait< T, float >::TP > &  rg,
Image< typename promote_trait< T, float >::TP > &  by,
const typename promote_trait< T, float >::TP  thresh
 

Compute R/G and B/Y channels in a simpler way.

Params are as in getRGBY. The computation for the RG and BY maps is: RG = (R-G)/max(R,G,B); BY = (B-min(R,G))/max(R,G,B).

template<class T>
void getYIQ const Image< PixRGB< T > > &  src,
Image< T > &  y,
Image< T > &  i,
Image< T > &  q
[inline]
 

Get YIQ color components.

Definition at line 517 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), GVX_TRACE, iptr, NO_INIT, src, and lobot::stop().

Referenced by infoMeasure().

Image<float> hueDistance const Image< PixRGB< byte > > &  img,
float  muR,
float  muG,
float  sigR,
float  sigG,
float  rho
 

distance between hue of image pixels and a given hue

Parameters:
img The color image to compare
muR the R/I coordinate of the target hue in the C.I.E. color space
muG the G/I coordinate in C.I.E.
sigR the standard deviation of a 2D Gaussian in R/I direction
sigG the standard deviation of a 2D Gaussian in G/I direction
rho the correlation between the R/I and G/I directions
Returns:
a float image coding for how close the hue in img is to the target hue - 1 for right on the mark, 0 for very different

template<class T>
Image<float> infoMeasure const Image< PixRGB< T > > &  src,
const float  eps,
const int  size
 

Compute color information measure based in infoFFT.

Definition at line 477 of file ColorOps.C.

References ASSERT, countThresh(), dct(), decXY(), getYIQ(), GVX_TRACE, i, lowPass3(), NO_INIT, Image< T >::setVal(), src, and y.

Referenced by InformationChannel::doInput().

void inplaceColorSpeckleNoise Image< PixRGB< byte > > &  dest,
const int  num
 

Add color speckle noise to array; faster version, draws 'num' dots.

template<class T>
Image<T> luminance const Image< T > &  src  ) 
 

Compute luminance of a greyscale image (no-op).

This no-op overload is provided so that luminance() can be applied to template images where it is not known whether the template argument is scalar or PixRGB.

Definition at line 421 of file ColorOps.C.

template<class T>
Image<T> luminance const Image< PixRGB< T > > &  src  ) 
 

Compute luminance of a color image.

Definition at line 401 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), Image< T >::endw(), GVX_TRACE, NO_INIT, src, and lobot::stop().

template<class T>
Image<PixRGB<T> > luminanceNormalize const Image< PixRGB< T > > &  src,
const T  thresh
 

Normalize my values by those in the lum image.

Definition at line 572 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), GVX_TRACE, NO_INIT, src, and lobot::stop().

template<class T>
Image<T> luminanceNTSC const Image< PixRGB< T > > &  src  ) 
 

Compute luminance in NTSC coordinates.

This version performs the same function as rgb2gray() in matlab

Definition at line 427 of file ColorOps.C.

References ASSERT, Image< T >::beginw(), Image< T >::endw(), GVX_TRACE, NO_INIT, lobot::round(), src, and lobot::stop().

Referenced by GenericFrame::asGrayU8NTSCLayout(), and InferoTemporalHmax::attentionShift().

template<class T>
Image<PixRGB<T> > makeRGB const Image< T > &  red,
const Image< T > &  green,
const Image< T > &  blue
 

Set the red, green and blue components from 3 monochromatic images.

Definition at line 61 of file ColorOps.C.

References ASSERT, Image< T >::begin(), Image< T >::beginw(), Image< T >::endw(), Image< T >::getDims(), GVX_TRACE, Image< T >::isSameSize(), NO_INIT, and lobot::stop().

Referenced by RGBConvolvePyrBuilder< T >::build2(), colGreyCombo(), SimulationViewerNerdCam::drawMegaCombo(), SimulationViewerStd::drawMegaCombo(), getImage(), getSalDispImg(), greyWorldNormalize(), main(), normalizeRGB(), rectifyRgb(), and submain().

template<class T>
Image<T> maxRGB const Image< PixRGB< T > > &  img  ) 
 

Return the pixel-wise maximum of the r, g and b component.

Definition at line 908 of file ColorOps.C.

References getComponents(), GVX_TRACE, and takeMax().

Referenced by main().

template<class T, class T2>
void normalizeC Image< PixRGB< T > > &  src,
const T2  nmin,
const T2  nmax
[inline]
 

Normalize values between nmin and nmax.

Definition at line 189 of file ColorOps.H.

References ASSERT, e, getMinMaxC(), src, and lobot::stop().

Referenced by main(), and normC255().

template<class T>
Image< PixRGB<T> > normalizeRGB const Image< PixRGB< T > > &  img,
PixRGB< T >  min,
PixRGB< T >  max
 

Normalize each component of the RGB image separately.

Normalize the red component with min.red() and max.red() etc.

Definition at line 893 of file ColorOps.C.

References PixRGB< T >::blue(), getComponents(), PixRGB< T >::green(), GVX_TRACE, inplaceNormalize(), makeRGB(), and PixRGB< T >::red().

Referenced by ScaleSurpriseControl< FLOAT >::SSCgetDiffImage(), and ScaleSurpriseControl< FLOAT >::SSCgetSeperableParts().

Image<PixRGB<float> > normalizeRGPolar const Image< float > &  src,
const float  max,
const float  min
 

This method will normalize an image based upon the maximum value provided to it. This is either max or the absolute value of min. It then creates an image where all negative values are assigned a red pixel value while all postive numbers are assigned a green pixel value

Parameters:
max The maximum pixel value
min The minimum pixel value
image The image of values (positive and negative) to be processed

Image<PixRGB<float> > normalizeRGPolarAuto const Image< float > &  src  ) 
 

This method will normalize an image based upon the maximum value provided to it. This is either max or the absolute value of min. It then creates an image where all negative values are assigned a red pixel value while all postive numbers are assigned a green pixel value. This version will autmatically determine min and max and then normalize between 0 and 255 for red and green

Parameters:
image The image of values (positive and negative) to be processed

Image<PixRGB<float> > normalizeScaleRainbow const Image< float > &  src,
const float  min,
const float  max
 

Normalize a grey scale image, with some idea for scale.

Here we normalize the image using translation between RGB and HSV what we do is set the intensity as the basic normalized value of the original gray scale image. However, we use hue as the absolute scale. Saturation is constant at 100 (full).

Image<PixRGB<float> > normalizeWithScale const Image< float > &  src,
const float  min,
const float  max,
const float  clamp,
const char  baseColor,
const char  normColor
 

Normalize a grey scale image, with some idea for scale.

nromalize a grey scale image, but to give an idea of the actual scale, we leave one channel as the orignal value and set the other the new value. This way, the intensity is still normalized over once channel so that you can make out the image features, but the hue change lets you know that the real intensity was very high.

Note: the output baseColor and normColor should be 1,2 or 3. They should also not be equal. These are which channel is set as the base and normalized channel representations.

Also Note: The base color will be clamped to between 0 and clamp so that it can still be displayed

Parameters:
src The orignal grey scale image
min The low bound on the normalization, for instance 0
max The high bound on the normalization, for instance 255
clamp clamp the baseColor to no more than this value
baseColor,1,2,3 ; R,G,B : which channel to not normalize out
normColor,1,2,3 ; R,G,B : which channel to normalize out

Image<PixRGB<float> > overlayStain const Image< float > &  top,
const Image< float > &  bottom,
const float  trans,
const char  channel
 

Overlay an image over another, however, stain the top image.

This method works almost exactly like overlay except that the bottom image is stained (colored) red green or blue depending on whether char channel is set to r,g, or b

template<class T>
double pSNRcolor const Image< PixRGB< T > > &  img1,
const Image< PixRGB< T > > &  img2,
const Image< float > &  weight
 

Compute weighted peak signal-to-noise ratio between two color images.

This is like the other pSNRcolor() except that it uses the weighted version of distance() internally

template<class T>
double pSNRcolor const Image< PixRGB< T > > &  img1,
const Image< PixRGB< T > > &  img2
 

Compute peak signal-to-noise ratio between two color images.

For color images, pSNR computed from the average mean-squared-error from the red, green and blue channels

Definition at line 856 of file ColorOps.C.

References ASSERT, distance(), getComponents(), GVX_TRACE, and log10().

void RGBtoCIE const PixRGB< byte > &  rgbColor,
float &  cr,
float &  cg,
float &  intens
 

convert RGB color values into C.I.E. coordinates

Parameters:
rgbColor the color to convert from
cr returns the R/I value
cg returns the G/I value
intens returns the intensity

template<class T>
Image<PixRGB<T> > stain const Image< T > &  src,
PixRGB< float >  color
 

Create a color image by staining a monochrome image.

Each pixel in the result is given by the stain color multiplied by the corresponding pixel in the monochrome source image. This is entirely equivalent to, but more efficient than, creating a color image from the monochrome image, then multiplying the color image by the stain color.

Image<PixRGB<float> > stainPosNeg const Image< float > &  src,
const float  maxval,
const PixRGB< float > &  background,
const PixRGB< float > &  pos_stain,
const PixRGB< float > &  neg_stain
 

Create a color image from src by tinting positive and negative values.

For each pixel x in the input image, we compute ratio=x/maxval; then if the ratio is positive, the output value is ratio*pos_stain + (1-ratio)*background, and if the ratio is negative, then the output value is (-ratio)*neg_stain + (1-(-ratio))*background.

template<class T>
Image< PixRGB<T> > toRGB const Image< PixRGB< T > > &  src  ) 
 

Convert RGB image to RGB (no-op).

This no-op function is provided so that toRGB() can be applied to template images where it is not known whether the template argument is scalar or PixRGB.

Definition at line 472 of file ColorOps.C.

References src.

template<class T>
Image< PixRGB<T> > toRGB const Image< T > &  src  ) 
 

Convert grayscale image to RGB.

Definition at line 455 of file ColorOps.C.

References ASSERT, Image< T >::begin(), Image< T >::beginw(), Image< T >::endw(), Image< T >::getDims(), GVX_TRACE, Image< T >::initialized(), NO_INIT, and lobot::stop().


Generated on Mon Nov 23 15:48:23 2009 for iLab Neuromorphic Vision Toolkit by  doxygen 1.4.4