code::Image< T > Class Template Reference

Inheritance diagram for code::Image< T >:

code::Dim2D< T > List of all members.

Detailed Description

template<class T>
class code::Image< T >

A reference-counting method to store 2D raster data efficiently.

This adds image-specific operations to a Dim2D of raster information. When copying via the assignment operator or copy constructor, a counter is incremented. The Image's 2D data is shared between the original and new copy, and will only be freed when the last Image sharing that 2D data is destroyed.

If you want to make a separate copy of an object's data, rather than sharing its data, call clone() instead of using the assignment operator or copy constructor.

It is templatized to create 2D arrays of ints, floats and doubles. You may need to instantiate additional datatypes if needed.

The orientation is such that the origin is at the top-left corner; The vertical direction is x (increasing downwards) and the horizontal direction is y (increasing to the right.) This gives us a right-handed co-ordinate system akin to matrix algebra.

Author:
Lakshman, NSSL
Version:
:
Id
code_Image.h,v 1.14 2009/06/02 20:17:37 lakshman Exp
See also:
CartesianGrid


Public Types

typedef __normal_iterator< T > iterator
typedef __normal_iterator<
const T > 
const_iterator

Public Member Functions

 Image (const T **input_data, int x, int y)
 Creates an X x Y object and copies input_data into it.
 Image (int x=0, int y=0, const T &value=T())
 Creates an X x Y object and fills with `value', which by default is the default value for type T.
 Image (const Dim2D< T > &values)
 Creates a new object which shares the `values' 2d's elements.
virtual ~Image ()
 Releases its hold on the data.
Image clone () const
 Create a completely separate copy of this image.
int write_pgm (const char *filename, int scaleValues=0) const
 Writes the data out to a pgm (portable gray map) file.
void showImage (const char *filename, bool inBackground) const
 Shows image by using the "xv" command found in your search path.
int dim_x () const
 Number of rows.
int dim_y () const
 Number of cols.
void incr (int x, int y, T incr_val=1)
 Increment pixel at x,y by incr_val, which is by default 1.0.
bool is_valid (int x, int y) const
 Returns true if the pixel is within the bounds of the image.
XImage * create_ximage (Display *display, Visual *visual, XColor *colors) const
 Creates an XImage out of the data .
char mapped_color (T data_value, XColor *colors) const
 Overlad this call to get a new color mapping.
Image< int > roundOff () const
 Will round off all the values in a Image<double>, for example.
Image< T > crop (unsigned int x1, unsigned int y1, unsigned int x2, unsigned int y2) const
 Crop the image to the top-left and bottom-right location given.
Image< T > zeropad (int newSize) const
 Zeropad and return a square object of size newSize,newSize.
Image< T > removezeropad (int newSize) const
 Crop the image around the edges to get a square object of size newSize, newSize.
Image< T > resize (int newSize) const
 Resize the given image to be the new size, zeropadding or removing the zeropad as needed.
void convolve (const Image< double > &kernel)
 Convolve this data using the kernel provided.
void convolve (const Image< T > &kernel)
 Convolve this data using the kernel provided.
Image< float > convolve (const std::vector< float > &row_filter, const std::vector< float > &col_filter) const
 Convolve using the separable kernels provided.
Image< float > localVariance (size_t kernel_size) const
 Find the local variance at each pixel.
Image< float > localVariance (size_t kernel_size, const Image< float > &local_mean) const
 Find the local variance at each pixel.
Image< float > localMean (size_t kernel_size) const
 Find the local mean at each pixel.
void minThreshold (T minThresh, T newValue)
 Thresholds so that all values below the minimum threshold are set to be the new value.
void maxThreshold (T maxThresh, T newValue)
 Thresholds so that all values above the maximum threshold are set to be the new value.
getMax () const
 Returns the maximum value in the image.
getMax (size_t &eye, size_t &jay) const
 Returns the maximum value in the image, & the image i,j of the max.
getMin () const
 Returns the minimum value in the image.
getMin (size_t &eye, size_t &jay) const
 Returns the minimum value in the image, & the image i,j of the min.
filterValue (const Image< T > &filter, int x, int y) const
 Returns the result of convolving the filter at the passed in pixel location.
Image operator- (const Image &a) const
 Does pixel-by-pixel subtraction.
void print_out () const
 prints, to standard output, the elements of the array as a table
void print_out (const char *format) const
 prints, to standard output, the elements of the array as a table
void surface_print_out () const
 prints, to standard output, the elements of the array for inpuy into a surface plot.
iterator begin ()
const_iterator begin () const
iterator end ()
const_iterator end () const
iterator get_iterator (size_t row, size_t col)
const_iterator get_iterator (size_t row, size_t col) const
T & cell_ref (size_t row, size_t col)
 Deprecated alternative to dim2d[row][col].
const T & cell_ref (size_t row, size_t col) const
 Deprecated alternative to dim2d[row][col].
get_val (size_t row, size_t col) const
 Return a copy of the element in the specified coordinate.
void set_val (size_t row, size_t col, const T &value)
 Slightly more efficient form of dim2d[row][col] = value.
T * operator[] (size_t row)
const T * operator[] (size_t row) const
void get_1d_bounds (size_t row, T *&setme_begin, T *&setme_end)
void get_1d_bounds (size_t row, const T *&setme_begin, const T *&setme_end) const
void push_back (const T *begin, const T *end)
 Add a row of elements.
void push_back (const std::vector< T > &v)
 Add a row of elements.
void replace_1d (size_t row, const T *first, const T *last)
 Overwrite a 'row' of elements.
void replace_1d (int row, const std::vector< T > &v)
 Overwrite a 'row' of elements.
void replace_2d (const Dim2D< T > &d)
 Overwrite the entire 2D.
void set_2d (size_t x, size_t y, const T **values)
 Repopulate the grid as an X x Y grid with a copy of `values'.
void fill (const T &val)
 Set the entire grid to a value.
void fill (const T &val, size_t row_begin, size_t row_end, size_t col_begin, size_t col_end)
 Fill a 2D range with the specified value.
void clear ()
 resets this object to a 0x0 matrix
void reserve (size_t rows, size_t cols)
 ensure enough memory is allocated to populate an ROW x COL matrix.
void resize (size_t rows, size_t cols, const T &value=T())
 resizes to a ROW x COL grid and sets each cell to `value'
void replace (const T &old_value, const T &new_value)
 replace every instance of old_value with new_value
size_t size_d () const
 number of rows.
size_t size_d (size_t row) const
 number of columns.
Coord size () const

Static Public Member Functions

static Image< int > read_pgm (const char *filename)
 Reads a 2D Image from a pgm file.

Protected Member Functions

virtual void shallow_copy (const Dim2D< T > &source)
virtual void deep_copy (const Dim2D< T > &source)

Protected Attributes

InitSmartPtr< Impl > _impl
 The array of 1D types that is held.


Member Typedef Documentation

typedef __normal_iterator<const T > code::Dim2D< T >::const_iterator [inherited]

typedef __normal_iterator<T > code::Dim2D< T >::iterator [inherited]


Constructor & Destructor Documentation

template<class T>
code::Image< T >::Image ( const T **  input_data,
int  x,
int  y 
) [inline]

Creates an X x Y object and copies input_data into it.

If sx or sy are zero, a "null" object is created. To test for "null", use "if (image.dim_x() * image.dim_y())"

template<class T>
code::Image< T >::Image ( int  x = 0,
int  y = 0,
const T &  value = T() 
) [inline]

Creates an X x Y object and fills with `value', which by default is the default value for type T.

template<class T>
code::Image< T >::Image ( const Dim2D< T > &  values  )  [inline]

Creates a new object which shares the `values' 2d's elements.

template<class T>
virtual code::Image< T >::~Image (  )  [inline, virtual]

Releases its hold on the data.

The resources are not released until the last hold is released.


Member Function Documentation

const_iterator code::Dim2D< T >::begin (  )  const [inline, inherited]

iterator code::Dim2D< T >::begin (  )  [inline, inherited]

const T & code::Dim2D< T >::cell_ref ( size_t  row,
size_t  col 
) const [inline, inherited]

Deprecated alternative to dim2d[row][col].

T & code::Dim2D< T >::cell_ref ( size_t  row,
size_t  col 
) [inline, inherited]

Deprecated alternative to dim2d[row][col].

void code::Dim2D< T >::clear (  )  [inline, inherited]

resets this object to a 0x0 matrix

template<class T>
Image code::Image< T >::clone (  )  const [inline]

Create a completely separate copy of this image.

To create a copy that shares this data, use operator=

Reimplemented from code::Dim2D< T >.

template<class T>
Image<float> code::Image< T >::convolve ( const std::vector< float > &  row_filter,
const std::vector< float > &  col_filter 
) const

Convolve using the separable kernels provided.

template<class T>
void code::Image< T >::convolve ( const Image< T > &  kernel  ) 

Convolve this data using the kernel provided.

See FFTObj for a more efficient implementation.

template<class T>
void code::Image< T >::convolve ( const Image< double > &  kernel  ) 

Convolve this data using the kernel provided.

See FFTObj for a more efficient implementation.

template<class T>
XImage* code::Image< T >::create_ximage ( Display *  display,
Visual *  visual,
XColor *  colors 
) const

Creates an XImage out of the data .

.. This uses Xlib calls. Remember to destroy using XDestroyImage ... Overload the mapped color call to get a new color mapping ...

template<class T>
Image<T> code::Image< T >::crop ( unsigned int  x1,
unsigned int  y1,
unsigned int  x2,
unsigned int  y2 
) const

Crop the image to the top-left and bottom-right location given.

virtual void code::Dim2D< T >::deep_copy ( const Dim2D< T > &  source  )  [inline, protected, virtual, inherited]

template<class T>
int code::Image< T >::dim_x (  )  const [inline]

Number of rows.

Reimplemented from code::Dim2D< T >.

template<class T>
int code::Image< T >::dim_y (  )  const [inline]

Number of cols.

Reimplemented from code::Dim2D< T >.

const_iterator code::Dim2D< T >::end (  )  const [inline, inherited]

iterator code::Dim2D< T >::end (  )  [inline, inherited]

void code::Dim2D< T >::fill ( const T &  val,
size_t  row_begin,
size_t  row_end,
size_t  col_begin,
size_t  col_end 
) [inline, inherited]

Fill a 2D range with the specified value.

Equivalent, but more efficient, form of "for (i=ibegin; i<iend; ++i) for (j=jbegin; j<jend; ++j) d[i][j]=val;"

void code::Dim2D< T >::fill ( const T &  val  )  [inline, inherited]

Set the entire grid to a value.

template<class T>
T code::Image< T >::filterValue ( const Image< T > &  filter,
int  x,
int  y 
) const

Returns the result of convolving the filter at the passed in pixel location.

void code::Dim2D< T >::get_1d_bounds ( size_t  row,
const T *&  setme_begin,
const T *&  setme_end 
) const [inline, inherited]

void code::Dim2D< T >::get_1d_bounds ( size_t  row,
T *&  setme_begin,
T *&  setme_end 
) [inline, inherited]

const_iterator code::Dim2D< T >::get_iterator ( size_t  row,
size_t  col 
) const [inline, inherited]

iterator code::Dim2D< T >::get_iterator ( size_t  row,
size_t  col 
) [inline, inherited]

T code::Dim2D< T >::get_val ( size_t  row,
size_t  col 
) const [inline, inherited]

Return a copy of the element in the specified coordinate.

template<class T>
T code::Image< T >::getMax ( size_t &  eye,
size_t &  jay 
) const

Returns the maximum value in the image, & the image i,j of the max.

template<class T>
T code::Image< T >::getMax (  )  const

Returns the maximum value in the image.

template<class T>
T code::Image< T >::getMin ( size_t &  eye,
size_t &  jay 
) const

Returns the minimum value in the image, & the image i,j of the min.

template<class T>
T code::Image< T >::getMin (  )  const

Returns the minimum value in the image.

template<class T>
void code::Image< T >::incr ( int  x,
int  y,
incr_val = 1 
) [inline]

Increment pixel at x,y by incr_val, which is by default 1.0.

template<class T>
bool code::Image< T >::is_valid ( int  x,
int  y 
) const [inline]

Returns true if the pixel is within the bounds of the image.

template<class T>
Image<float> code::Image< T >::localMean ( size_t  kernel_size  )  const

Find the local mean at each pixel.

The size of the neighborhood is determined by the kernel size.

template<class T>
Image<float> code::Image< T >::localVariance ( size_t  kernel_size,
const Image< float > &  local_mean 
) const

Find the local variance at each pixel.

The size of the neighborhood is determined by the kernel size and the local mean has been computed (with the same kernel size) using the localMean() function.

template<class T>
Image<float> code::Image< T >::localVariance ( size_t  kernel_size  )  const

Find the local variance at each pixel.

The size of the neighborhood is determined by the kernel size.

template<class T>
char code::Image< T >::mapped_color ( data_value,
XColor *  colors 
) const

Overlad this call to get a new color mapping.

template<class T>
void code::Image< T >::maxThreshold ( maxThresh,
newValue 
)

Thresholds so that all values above the maximum threshold are set to be the new value.

template<class T>
void code::Image< T >::minThreshold ( minThresh,
newValue 
)

Thresholds so that all values below the minimum threshold are set to be the new value.

template<class T>
Image code::Image< T >::operator- ( const Image< T > &  a  )  const

Does pixel-by-pixel subtraction.

this - passed in image

const T * code::Dim2D< T >::operator[] ( size_t  row  )  const [inline, inherited]

T * code::Dim2D< T >::operator[] ( size_t  row  )  [inline, inherited]

template<class T>
void code::Image< T >::print_out ( const char *  format  )  const

prints, to standard output, the elements of the array as a table

template<class T>
void code::Image< T >::print_out (  )  const

prints, to standard output, the elements of the array as a table

void code::Dim2D< T >::push_back ( const std::vector< T > &  v  )  [inline, inherited]

Add a row of elements.

void code::Dim2D< T >::push_back ( const T *  begin,
const T *  end 
) [inline, inherited]

Add a row of elements.

template<class T>
static Image<int> code::Image< T >::read_pgm ( const char *  filename  )  [static]

Reads a 2D Image from a pgm file.

Won't work if the file has ridiculously long comments (>1950 char)

template<class T>
Image<T> code::Image< T >::removezeropad ( int  newSize  )  const

Crop the image around the edges to get a square object of size newSize, newSize.

void code::Dim2D< T >::replace ( const T &  old_value,
const T &  new_value 
) [inline, inherited]

replace every instance of old_value with new_value

void code::Dim2D< T >::replace_1d ( int  row,
const std::vector< T > &  v 
) [inline, inherited]

Overwrite a 'row' of elements.

The number of new and old elements must match.

void code::Dim2D< T >::replace_1d ( size_t  row,
const T *  first,
const T *  last 
) [inline, inherited]

Overwrite a 'row' of elements.

The number of old and new elements must match.

void code::Dim2D< T >::replace_2d ( const Dim2D< T > &  d  )  [inline, inherited]

Overwrite the entire 2D.

This copies the elements from d, rather than sharing them. If you want to share them, use the assignment operator instead.

void code::Dim2D< T >::reserve ( size_t  rows,
size_t  cols 
) [inline, inherited]

ensure enough memory is allocated to populate an ROW x COL matrix.

void code::Dim2D< T >::resize ( size_t  rows,
size_t  cols,
const T &  value = X() 
) [inline, inherited]

resizes to a ROW x COL grid and sets each cell to `value'

template<class T>
Image<T> code::Image< T >::resize ( int  newSize  )  const

Resize the given image to be the new size, zeropadding or removing the zeropad as needed.

Based on the number of rows only, so will not zeropad in one dimension and removezeropad in another.

template<class T>
Image<int> code::Image< T >::roundOff (  )  const

Will round off all the values in a Image<double>, for example.

void code::Dim2D< T >::set_2d ( size_t  x,
size_t  y,
const T **  values 
) [inline, inherited]

Repopulate the grid as an X x Y grid with a copy of `values'.

void code::Dim2D< T >::set_val ( size_t  row,
size_t  col,
const T &  value 
) [inline, inherited]

Slightly more efficient form of dim2d[row][col] = value.

virtual void code::Dim2D< T >::shallow_copy ( const Dim2D< T > &  source  )  [inline, protected, virtual, inherited]

template<class T>
void code::Image< T >::showImage ( const char *  filename,
bool  inBackground 
) const

Shows image by using the "xv" command found in your search path.

This is useful in debugging ...

class Coord code::Dim2D< T >::size (  )  const [inline, inherited]

size_t code::Dim2D< T >::size_d ( size_t  row  )  const [inline, inherited]

number of columns.

size_t code::Dim2D< T >::size_d (  )  const [inline, inherited]

number of rows.

template<class T>
void code::Image< T >::surface_print_out (  )  const

prints, to standard output, the elements of the array for inpuy into a surface plot.

template<class T>
int code::Image< T >::write_pgm ( const char *  filename,
int  scaleValues = 0 
) const

Writes the data out to a pgm (portable gray map) file.

The default is to not modify the data in any way. If your data can be > 255, you could scale it for viewing. Negative numbers are always written out as zero.

template<class T>
Image<T> code::Image< T >::zeropad ( int  newSize  )  const

Zeropad and return a square object of size newSize,newSize.

A rectangular version is not provided because I've never needed it.


Member Data Documentation

InitSmartPtr< Impl > code::Dim2D< T >::_impl [protected, inherited]

The array of 1D types that is held.


Generated on Fri May 4 13:40:11 2012 for WDSS-IIw2 by  doxygen 1.4.7