KJB

Classes  
class  kjb::Color_histogram 
Class to compute an RGB colour histogram over an image or a rectangular portion of it. The histogram is normalized. We use the same number of bins for each of the channels (r,g,b). It is easy to extend this class so that it computes such histogram over a segment of a shape other than rectangular. More...  
class  kjb::Colormap 
class  kjb::Filter 
Filter class. More...  
struct  kjb::PixelHSVA 
Alternative Pixel using hue, saturation, value, and opacity (alpha). More...  
class  kjb::Image 
Wrapped version of the C struct KJB_image. More...  
class  kjb::Fftw_image_convolution 
this is a simple adaptation of Fftw_convolution_2d to Image input. More...  
class  kjb::Opengl_framebuffer_image 
struct  kjb::PixelRGBA 
Wrapped version of the C struct Pixel, with Alpha (opacity). More...  
Typedefs  
typedef boost::shared_ptr< Image >  kjb::Image_ptr 
Functions  
Image  kjb::make_collage (Image const *const *input_images, int num_horizontal, int num_vertical) 
wrapper for kjb_c::make_image_collage More...  
Image  kjb::make_collage (Image const *input_img_array, int num_horizontal, int num_vertical) 
also works for an array of Image objects More...  
void  kjb::write_histograms (const std::vector< Color_histogram > &chs, const std::string &file_name) 
void  kjb::read_histograms (std::vector< Color_histogram > &chs, const std::string &file_name) 
Filter  kjb::gaussian_filter (double sigma, int size) 
Create a Gaussian filter with given sigma and size. More...  
Filter  kjb::gaussian_filter (double sigma) 
Create a Gaussian filter with given sigma. More...  
Filter  kjb::laplacian_of_gaussian_filter (int size, double sigma) 
Create a Laplacian of Gaussian filter. More...  
Image  kjb::operator* (const Image &image, const Filter &kernel) 
Convolve an image with a filter. More...  
Image  kjb::gauss_sample_image (const Image &in, int resolution, double sigma) 
this wraps C function kjb_c::gauss_sample_image (q.v.). More...  
Vector  kjb::hsluma_space (const kjb_c::Pixel &p) 
Compute the spatial coordinates of a pixel in HSY color space. More...  
kjb_c::Pixel  kjb::get_pixel_from_hsluma_space (const Vector &hsy) 
This clampfully transforms a point in HSY space to RGB. More...  
int  kjb::get_pixel_from_hsluma_space (const Vector &hsy, kjb_c::Pixel *p) 
This might transform a point in HSY space to RGB. More...  
Image  kjb::scale_image (const Image &i, double factor) 
Scale image size by factor, i.e., enlarge or shrink. More...  
Image  kjb::get_inverted (const Image &) 
Image  kjb::rgb_matrices_to_image (const Matrix &red_channel, const Matrix &green_channel, const Matrix &blue_channel) 
Contruct an image from three matrices representing red, green, blue channels. More...  
Matrix  kjb::to_grayscale_matrix (const Image &i) 
Image  kjb::operator* (const Image &op1, double op2) 
Scale an image in channel space, yielding a new image. More...  
Image  kjb::operator/ (const Image &op1, double op2) 
Scale an image in channel space, yielding a new image. More...  
Image  kjb::operator+ (const Image &op1, const Image &op2) 
Add two images. More...  
Image  kjb::operator (const Image &im1, const Image &im2) 
Subtract two images. More...  
void  kjb::enable_transparency (Image &i) 
set Image flag, to indicate that the 'alpha' channel is meaningful. More...  
void  kjb::disable_transparency (Image &i) 
clear Image flag, to indicate that the 'alpha' channel is not meaningful. More...  
bool  kjb::is_transparency_enabled (const Image &i) 
test the Image flag, returning true if the 'alpha' channel is meaningful. More...  
Image  kjb::matrix_to_max_contrast_8bit_bw_image (const kjb::Matrix &m) 
convert a matrix to a blackandwhite image, with enhanced contrast. More...  
Image  kjb::matrix_to_color_image (const kjb::Matrix &m, const kjb::Colormap &map="jet") 
Converts a matrix to a highcontrast color image, mapping values to colors using a kjb::Colormap. Equivalent to Matlab's imagesc() function. More...  
Image  kjb::imagesc (const kjb::Matrix &data, const kjb::Colormap &map="jet") 
Ported version of Matlab's "imagesc()" function; alias of matrix_to_color_image. More...  
std::string  kjb::pixel_as_hex_triplet_string (const kjb_c::Pixel *p) 
express color as HTMLstyle hex triplet, e.g., "#FFCC00," of pointer More...  
PixelRGBA  kjb::operator* (const PixelRGBA &p, const PixelRGBA &q) 
Multiply two pixels together. More...  
PixelRGBA  kjb::operator* (const PixelRGBA &p, double k) 
Scale a pixel by a floating point value on the right. More...  
PixelRGBA  kjb::operator* (double k, const PixelRGBA &p) 
Scale a pixel by a floating point value on the left. More...  
kjb_c::Pixel  kjb::abs (const kjb_c::Pixel &p) 
Take the channelwise absolute value of a kjb_c::Pixel. More...  
std::string  kjb::pixel_as_hex_triplet_string (const kjb_c::Pixel &p) 
express color as HTMLstyle hex triplet, e.g., "#FFCC00," reference More...  
template<class InputIterator >  
Vector  kjb::Image::intensity_histogram (InputIterator first, InputIterator last) const 
Computes the intensity histogram of a region – given by a range of pairs – of this image. More...  
This group include the Image class and all closelyrelated classes and functions pertaining to lowlevel operations on and manipulation of images.
typedef boost::shared_ptr<Image> kjb::Image_ptr 
Convenience typedef for boost::shared_ptr<Image>.

inline 
Take the channelwise absolute value of a kjb_c::Pixel.

inline 
clear Image flag, to indicate that the 'alpha' channel is not meaningful.

inline 
set Image flag, to indicate that the 'alpha' channel is meaningful.
Image kjb::gauss_sample_image  (  const Image &  in, 
int  resolution,  
double  sigma  
) 
this wraps C function kjb_c::gauss_sample_image (q.v.).
Filter kjb::gaussian_filter  (  double  sigma, 
int  size  
) 
Create a Gaussian filter with given sigma and size.

inline 
Create a Gaussian filter with given sigma.

inline 
kjb_c::Pixel kjb::get_pixel_from_hsluma_space  (  const Vector &  hsy  ) 
This clampfully transforms a point in HSY space to RGB.
Please see the comments for get_pixel_from_hsluma_space( const kjb::Vector&, kjb_c::Pixel* ).
If the huesaturationluma coordinates are outside the HSY polyhedron, this still returns a pixel, but the resulting R,G,B values are clamped to the range 0 to 255. Alpha (opacity) is set to the default value used by class PixelRGBA.
int kjb::get_pixel_from_hsluma_space  (  const Vector &  hsy, 
kjb_c::Pixel *  p  
) 
This might transform a point in HSY space to RGB.
Input hsy is a vector of cartesian coordinates where arctan( hsy[1] / hsy[0] ) is hue, sqrt(hsy[0]**2 + hsy[1]**2) is saturation, and hsy[2] is "luma." (Luma is a tweak to brightness to compensate for the differences in perceived brightness betwen red, green, and blue.) Valid HSY values are necessarily inside a cuboid with opposite corners (1,1,0) and (1,1,1); but being in this range is not sufficient. The HSY color space is a polyhedron inside that cuboid.
Iff input hsy is outside the polyhedron, the return value is EXIT_FAILURE.
If the input vector is not within the HSY color polyhedron, then pointer p is not touched. Otherwise, and if p is not equal to null, the resulting pixel is stored in *p. If you do not need the pixel, it is safe to pass in a null value, and this function will act like a predicate.
Vector kjb::hsluma_space  (  const kjb_c::Pixel &  p  ) 
Compute the spatial coordinates of a pixel in HSY color space.
The space I am using here is described in the Wikipedia article linked above. Please read about the HSL bicone: a bicone shape is like a top generated by revolving a diamond. This forms a 3D shape: picture yourself holding an empty ice cream cone, and on top of that you place an inverted empty ice cream cone. Lightness L runs along the central axis of rotation: the pointy bottom is black, the top tip is white. Hue H runs around the circumference, basically in a cyclical, rainbow order; 0 degrees is for reddish colors, 180 degrees is for cyanic colors. Saturation describes a point's distance from the central axis; at a radius of 0 the colors are only black, white, and grays. Farther from the axis the colors grow more vivid.
Except that I want to use NTSC 601 for lightness, instead of the more conventional I=(max{r,g,b}+min{r,g,b})/2. NTSC 601 defines "luma" Y as an uneven mix of red, green, and blue, in recognition of the fact that perceptually, green seems brighter than red, and both seem dimmer than blue, for typical computer shades of red, green, and blue. This distorts the shape from a bicone. The space remains convex.
In any case, this function returns the cartesian coordinates (not cylindrical!) of color points within this space, in the form of a vector v. If you think of hue H as an angle from 0 to 359, then H is basically arctan(v[1] / v[0]). v[2] is luma; zero luma is black, unity luma is white. Components v[0], v[1] are in the closed interval [1,1]. Component v[2] is in closed interval [0,1]. Not all points in the unit cube of that space are reachable from the RGB cube!
This is basically an invertible matrix transformation: vector (r,b,g)' times matrix [ [1 .5 .5]; [0 .866 .866]; [.3 .59 .11] ] <===(octave notation). The inverse of this matrix is hardcoded into (overloaded) functions PixelRGBA_from_HSLuma_space().

inline 
Ported version of Matlab's "imagesc()" function; alias of matrix_to_color_image.
Vector kjb::Image::intensity_histogram  (  InputIterator  first, 
InputIterator  last  
)  const 
Computes the intensity histogram of a region – given by a range of pairs – of this image.
InputIterator  An iterator whose value_type is a pair. 

inline 
test the Image flag, returning true if the 'alpha' channel is meaningful.
Filter kjb::laplacian_of_gaussian_filter  (  int  size, 
double  sigma  
) 
Create a Laplacian of Gaussian filter.
Image kjb::make_collage  (  Image const *const *  input_images, 
int  num_horizontal,  
int  num_vertical  
) 
wrapper for kjb_c::make_image_collage
Image kjb::make_collage  (  Image const *  input_img_array, 
int  num_horizontal,  
int  num_vertical  
) 
also works for an array of Image objects
Image kjb::matrix_to_color_image  (  const kjb::Matrix &  m, 
const kjb::Colormap &  map  
) 
Converts a matrix to a highcontrast color image, mapping values to colors using a kjb::Colormap. Equivalent to Matlab's imagesc() function.
Maps matrix values to [0,1], and transforms them to colors using the provided colormap. The following strings may be passed to specify preset colormaps, which are identical to those in Matlab:
 "jet" (default)  "hot"  "hsv"  "gray"  "cool"  "lines"
Using "gray" should give similar results to matrix_to_max_contast_8bit_bw_image()
Custom colormaps may also by used by passing a kjb::Colormap object instead of as string.
Image kjb::matrix_to_max_contrast_8bit_bw_image  (  const kjb::Matrix &  m  ) 
convert a matrix to a blackandwhite image, with enhanced contrast.
m  input matrix to visualize 
This wraps the C function kjb_c::matrix_to_max_contrast_8bit_bw_image().
Image kjb::operator*  (  const Image &  image, 
const Filter &  kernel  
) 
Convolve an image with a filter.

inline 
Multiply two pixels together.
This simply performs an channelwise product.

inline 
Scale a pixel by a floating point value on the right.

inline 
Scale a pixel by a floating point value on the left.

inline 
Scale an image in channel space, yielding a new image.

inline 
Add two images.

inline 
Subtract two images.

inline 
Scale an image in channel space, yielding a new image.
Divide_by_zero  if the given value is zero. 

inline 
express color as HTMLstyle hex triplet, e.g., "#FFCC00," of pointer

inline 
express color as HTMLstyle hex triplet, e.g., "#FFCC00," reference
void kjb::read_histograms  (  std::vector< Color_histogram > &  chs, 
const std::string &  file_name  
) 
Image kjb::rgb_matrices_to_image  (  const Matrix &  red_channel, 
const Matrix &  green_channel,  
const Matrix &  blue_channel  
) 
Contruct an image from three matrices representing red, green, blue channels.
KJB_error,possibly,if  matrices not the same size (see below). 
This just wraps a call to kjb_c::rgb_matrices_to_image(). If the inputs are not all identically sized, the bug handler is called. If the bug handler returns, a KJB_error is thrown.
Note that if you want your Image to behave like with 8bit channel values, then you are obliged to scale the input matrices to the range 0.0 to 255.0.
Image kjb::scale_image  (  const Image &  i, 
double  factor  
) 
Scale image size by factor, i.e., enlarge or shrink.
i  input image to scale 
factor  the enlargement factor to apply, e.g., 2 means to double the width and height. 0.5 means to halve the width and height. 
KJB_error  if the scaling fails 
If the enlargement factor is in the range 0.9999 to 1.0001, this function just returns a copy of the input, without any scaling.
Matrix kjb::to_grayscale_matrix  (  const Image &  i  ) 
void kjb::write_histograms  (  const std::vector< Color_histogram > &  chs, 
const std::string &  file_name  
) 