Maria GDK 5.0.0.737
Documentation of native code in develop branch
Loading...
Searching...
No Matches
STK::Image Class Reference

#include <StkImage.h>

Classes

struct  FmtStruct
 

Public Types

enum  Format {
  UNDEF = 0 , RGB_16 , RGB_24 , RGBA_32 ,
  RGBA_16 , MONO_8 , MONO_8s , MONO_16 ,
  MONO_16s , MONO_32 , MONO_32s , RGBA_DXT1 ,
  RGBA_DXT3 , RGBA_DXT5 , MONOA_16 , MONO_FLOAT_32 ,
  RGB_FLOAT_96 , RGB_FLOAT_48 , RGBA_FLOAT_64 , ARGB_32 ,
  BGRA_32 , NUM_FORMATS
}
 Image internal formats. More...
 

Public Member Functions

 Image ()
 
 Image (ImageIO &loader)
 
 Image (const std::vector< uint8_t > &imageBuffer)
 
 Image (std::string filename)
 
 Image (const Image &c)
 
 Image (int width, int height, Format fmt, const char *data=nullptr)
 
bool isNull () const
 
bool isCompressed () const
 
bool load (ImageIO &loader)
 
bool load (std::string filename)
 
bool load (const std::vector< uint8_t > &imgBuffer)
 
bool save (ImageIO &saver) const
 
bool save (const std::string &filename) const
 
virtual bool transform (ImageTransform &trans)
 
bool transform (ImageTransform &trans, Image &dest) const
 
bool hasAlphaChannel () const
 
bool isFloat () const
 
void setAlpha (unsigned char r, unsigned char g, unsigned char b, unsigned char val)
 
bool convert (Format fmt, Image &dst) const
 
bool convert (Format fmt)
 
void compose (const Image &r, const Image &g, const Image &b)
 
void compose (const Image &r, const Image &g, const Image &b, const Image &a)
 
void decompose (Image &r, Image &g, Image &b) const
 
void decomposeHSV (Image &h, Image &s, Image &v) const
 
void decompose (Image &r, Image &g, Image &b, Image &a) const
 
virtual bool getSubImage (int startx, int starty, int width, int height, Image &dst)
 
int * histogram () const
 
void histogram (std::vector< int > &hist) const
 
double * histogramNorm () const
 
void histogramNorm (std::vector< double > &hist) const
 
double * CDF () const
 
void CDF (std::vector< double > &cdf) const
 
virtual void calcMemSize ()
 
int getWidth () const
 Get image width in pixels.
 
int getHeight () const
 Get image height in pixels.
 
int getNumPixels () const
 
int getPixelSize () const
 Get number of bytes per pixel.
 
int getDepth () const
 Get number of bits per pixel.
 
int getBPP () const
 
int getMemSize () const
 Get total size of image in bytes.
 
Format getFormat () const
 Get the image format.
 
int getNumBands () const
 Get the number of bands (channels) in the image.
 
int getNumLevels () const
 Get number of mipmap levels.
 
int getNodataValue () const
 
void setNodataValue (int nodata)
 
unsigned char * getData () const
 
virtual unsigned char * getData (int level) const
 
unsigned char * getVal (int x, int y) const
 
unsigned char * getVal (int x, int y, int l) const
 
unsigned char * getVal (unsigned int idx) const
 
Color4i getPixel (int x, int y) const
 
Color4i getPixel (int x, int y, int l) const
 
Color4d getPixel4d (int x, int y) const
 
Color4d getPixel4d (int x, int y, int l) const
 
Color4i getPixel (int idx) const
 
Color4d getPixel4d (int idx) const
 
double getValue (int idx) const
 
double getValue (int x, int y) const
 
bool isNodata (double val) const
 
bool setPixel (int x, int y, const Color4i &color)
 
bool setPixel (int x, int y, int l, const Color4i &color)
 
bool setPixel4d (int x, int y, const Color4d &color)
 
bool setPixel4d (int x, int y, int l, const Color4d &color)
 
bool setPixel (int idx, const Color4i &color)
 
bool setPixel4d (int idx, const Color4d &color)
 
bool setValue (int x, int y, double val)
 
bool setValue (int idx, double val)
 
void setWidth (int width)
 
void setHeight (int height)
 
void setNumLevels (int num_levels)
 
void setFormat (Format format)
 
void setDataPtr (unsigned char *data)
 
void allocMem ()
 
bool setMipmap (const Image &img, int l)
 
bool setMipmap (unsigned char *src, int memsize, int level)
 
virtual void clear ()
 
virtual void copyHeader (const Image &src)
 
virtual void moveData (Image &img)
 
const Imageoperator= (const Image &c)
 
void flipVertical ()
 
void flipHorizontal ()
 
void fill (double val)
 Fill image with the given elevation value.
 
void fill (const STK::Color4d &val)
 Fill image with the given pixel value.
 
void fill (const STK::Color4i &val)
 Fill image with the given pixel value.
 

Static Public Member Functions

static std::string formatToString (Format f)
 
static Format stringToFormat (std::string s)
 
static int pixelSize (Format fmt)
 

Protected Member Functions

bool getPixel (void *val, Color4i &ret) const
 
bool setPixel (void *val, const Color4i &col)
 
bool getPixel4d (void *val, Color4d &ret) const
 
bool setPixel4d (void *val, const Color4d &col)
 
void copy (const Image &c)
 
Color4d convertToColor4d (const Color4i &c) const
 
Color4i convertToColor4i (const Color4d &c) const
 

Static Protected Member Functions

static void initFmtInfo ()
 

Protected Attributes

unsigned int memsize_
 
int width_
 
int height_
 
int num_levels_
 
int npix_
 
unsigned char * data_
 
Format format_
 
int nodata_
 

Static Protected Attributes

static FmtStruct fmt_info_ [NUM_FORMATS]
 

Detailed Description

Image - 2D raster image.

Member Enumeration Documentation

◆ Format

Image internal formats.

Enumerator
UNDEF 

Undefined pixel format.

RGB_16 

16-bits RGB. 5 bits red, 6 bits green and 5 bits blue.

RGB_24 

24-bits RGB. 8 bits each of red, green and blue.

RGBA_32 

32-bits RGBA. As above with an 8-bits alpha channel.

RGBA_16 

16-bits RGBA. 5 bits each of R, G and B, and 1 bit alpha.

MONO_8 

8-bit gray scale image

MONO_8s 

Signed 8-bit values.

MONO_16 

Unsigned 16-bit values.

MONO_16s 

Signed 16-bit values.

MONO_32 

Unsigned 32-bit values.

MONO_32s 

Signed 32-bit values.

RGBA_DXT1 

DXT1 compressed RGBA values.

RGBA_DXT3 

DXT3 compressed RGBA values.

RGBA_DXT5 

DXT5 compressed RGBA values.

MONOA_16 

8-bit gray-scale with alpha

MONO_FLOAT_32 

32 bit floating point numbers

RGB_FLOAT_96 

Three 32 bit floating point numbers for each pixel.

RGB_FLOAT_48 

16-bits float components

RGBA_FLOAT_64 

16-bits float components

ARGB_32 

32 bits ARGB

BGRA_32 

32 bits BGRA

Constructor & Destructor Documentation

◆ Image() [1/6]

Image::Image ( )

Default constructor. This constructor creates an empty image with UNDEF pixel format.

◆ Image() [2/6]

Image::Image ( ImageIO loader)

Constructor. This constructor creates an image and loads it with data from the given ImageIO object.

◆ Image() [3/6]

Image::Image ( const std::vector< uint8_t > &  imageBuffer)

Constructor. This constructor creates an image and creates it with data from imageBuffer.

◆ Image() [4/6]

STK::Image::Image ( std::string  filename)

Constructor. This constructor creates an image and loads it with data from the given file name.

◆ Image() [5/6]

Image::Image ( const Image c)

Copy constructor. This method initializes an image with a copy of the given image object.

◆ Image() [6/6]

Image::Image ( int  width,
int  height,
Image::Format  fmt,
const char *  data = nullptr 
)

Create image from raw data. This constructor creates an image object from a chunk of bytes. The data is copied from the given pointer.

Member Function Documentation

◆ calcMemSize()

virtual void STK::Image::calcMemSize ( )
inlinevirtual

Calculate image size. This method calculates the image size in bytes based on the width and height of the image and bits per pixel based on the image format. This method is called each time any of these parameters are changed.

◆ CDF() [1/2]

double * Image::CDF ( ) const

Create cumulative distribution function (obsolete). This method creates a cumulative distribution function (CDF) for the image, which is simply a one-dimensional vector where each element is that fraction of the pixels in the image with intensity values less than or equal to the number of the element where the index starts at zero, i.e:

\[
   \mbox{CDF}_n = \sum_{i=0}^n\mbox{HIS}'(i).
\]

where $\mbox{HIS}'$ is the normalized histogram of the input image.

The return value is an array which is ordered such that the 256 CDF values of channel 0 comes first, then the 256 levels of channel 1, and so forth.

Warning
The returned array must be deleted after use!
This method is obsolete, use the STL vector version instead!

◆ CDF() [2/2]

void Image::CDF ( std::vector< double > &  cdf) const

Create cumulative distribution function. This method creates a cumulative distribution function (CDF) for the image, which is simply a one-dimensional vector where each element is that fraction of the pixels in the image with intensity values less than or equal to the number of the element where the index starts at zero, i.e:

\[
   \mbox{CDF}_n = \sum_{i=0}^n\mbox{HIS}'(i).
\]

where $\mbox{HIS}'$ is the normalized histogram of the input image.

The return value is an array which is ordered such that the 256 CDF values of channel 0 comes first, then the 256 levels of channel 1, and so forth.

◆ clear()

void Image::clear ( )
virtual

Clear image data. This method deletes the image data and resets all other parameters to zero or undefined.

◆ compose() [1/2]

void Image::compose ( const Image r,
const Image g,
const Image b 
)

Compose image channels. This method joins the given intensity channels into an RGB_24 image. This method assumes that all input bands are MONO_8 and that they have equal dimensions.

See also
decompose()

◆ compose() [2/2]

void Image::compose ( const Image r,
const Image g,
const Image b,
const Image a 
)

Compose image channels. This method joins the given intensity channels into an RGBA_32 image. This method assumes that all input bands are MONO_8 and that they have equal dimensions.

See also
decompose()

◆ convert() [1/2]

bool Image::convert ( Format  fmt)

Convert image pixel format. This function converts the image pixel format of the current image to fmt.

◆ convert() [2/2]

bool Image::convert ( Format  fmt,
Image dst 
) const

Convert image pixel format. This method converts the image to the given pixel format storing the output in the image dst.

◆ copyHeader()

void Image::copyHeader ( const Image src)
virtual

Copy header info from another image. This method copies the header info from the image 'src', such as width, height format, etc.

◆ decompose() [1/2]

void Image::decompose ( Image r,
Image g,
Image b 
) const

Decompose image channels. This method decomposes the image into 3 or 4 mono images containing each of the red, green, blue, and possibly alpha channels of the original image.

◆ decompose() [2/2]

void Image::decompose ( Image r,
Image g,
Image b,
Image a 
) const

Decompose image channels. This method decomposes the image into 3 or 4 mono images containing each of the red, green, blue, and possibly alpha channels of the original image.

◆ decomposeHSV()

void Image::decomposeHSV ( Image h,
Image s,
Image v 
) const

Decompose image channels (HSV). This method decomposes the image into 3 mono images containing each of the hue, saturation, and value channels of the original image.

◆ formatToString()

std::string Image::formatToString ( Format  f)
static

Convert format type to a string.

◆ getData() [1/2]

unsigned char * STK::Image::getData ( ) const
inline

Get pointer to pixel data. This method returns a pointer to the pixel data contained in the image. Note that the return value is a pointer to unsigned char, so for 16-bits image formats it may be convenient to cast this to unsigned short.

◆ getData() [2/2]

virtual unsigned char * STK::Image::getData ( int  level) const
inlinevirtual

Get pointer to mipmap level.

◆ getNodataValue()

int STK::Image::getNodataValue ( ) const
inline

Get nodata value. This value is used for missing data for example in elevation data files. Default value is -32767

◆ getPixel() [1/2]

Color4i STK::Image::getPixel ( int  idx) const
inline

Get pixel object by index. This method returns a Color4i object with the pixel data at index idx in the raster. See getVal(int) for an explanation ofthe pixel ordering. For mono images, all components of the returned pixel are equal.

See also
Color4i
getPixel(int,int)

XXX: This interface should be updated to fit the other pixel access functions...

◆ getPixel() [2/2]

Color4i STK::Image::getPixel ( int  x,
int  y 
) const
inline

Get Pixel object by coordinates. This method returns a Color4i object with the pixel data at location $(x, y)$ in the raster. The color components are scaled to the interval $[0,255]$ regardless of pixel format.

See also
Color4i
getPixel(int)
getVal
getData

XXX: This interface should be updated to fit the other pixel access functions...

◆ getSubImage()

bool Image::getSubImage ( int  startx,
int  starty,
int  width,
int  height,
Image dst 
)
virtual

Get subimage. This method extracts the pixels from (startx, starty) with dimensions (height, width) and puts it in the image object given by 'dst'.

Returns
true on success, false on failure, (e.g wrong dimensions).

◆ getVal() [1/2]

unsigned char * STK::Image::getVal ( int  x,
int  y 
) const
inline

Get data by coordinates. This method returns a pointer to the pixel data located at coordinates $(x, y)$ in the raster.

See also
getData().

◆ getVal() [2/2]

unsigned char * STK::Image::getVal ( unsigned int  idx) const
inline

Get data by pixel index. This method returns a pointer to the pixel data located at index idx in the raster. Note that the data is stored row-wise, so that index $[0,\dots\mbox{width}-1]$ is the first row, $[\mbox{width},\dots , 2\cdot \mbox{width}-1]$ is the second etc.

See also
getVal(int,int).

◆ getValue() [1/2]

double STK::Image::getValue ( int  idx) const
inline

Convenience function for elevation data.

◆ getValue() [2/2]

double STK::Image::getValue ( int  x,
int  y 
) const
inline

Convenience function for elevation data.

◆ hasAlphaChannel()

bool STK::Image::hasAlphaChannel ( ) const
inline

Returns true if the pixel format has an alpha channel. Note that this does not include texture compression formats even though they also have alpha.

◆ histogram() [1/2]

int * Image::histogram ( ) const

Create histogram (obsolete). This method returns the histograms of the image bands as an integer array of length 256*<number of bands>, with number of samples per intensity level per band.

The array is ordered such that the 256 histogram levels of channel 0 comes first, then the 256 levels of channel 1, and so forth.

Warning
The returned array must be deleted after use!
This method is obsolete, use the STL vector version instead!

◆ histogram() [2/2]

void Image::histogram ( std::vector< int > &  hist) const

Create histogram. This method returns the histograms of the image bands as an integer array of length 256*<number of bands>, with number of samples per intensity level per band.

The array is ordered such that the 256 histogram levels of channel 0 comes first, then the 256 levels of channel 1, and so forth.

◆ histogramNorm() [1/2]

double * Image::histogramNorm ( ) const

Create normalized histogram (obsolete). This method returns a normalized histogram of the image. i.e each pixel count is divided by the total number of pixels, so that each element in the histogram is a value in the range [0.0, 1.0].

The array is ordered such that the 256 histogram levels of channel 0 comes first, then the 256 levels of channel 1, and so forth.

See also
histogram()
Warning
The returned array must be deleted after use!
This method is obsolete, use the STL vector version instead!

◆ histogramNorm() [2/2]

void Image::histogramNorm ( std::vector< double > &  hist) const

Create normalized histogram This method returns a normalized histogram of the image. i.e each pixel count is divided by the total number of pixels, so that each element in the histogram is a value in the range [0.0, 1.0].

The array is ordered such that the 256 histogram levels of channel 0 comes first, then the 256 levels of channel 1, and so forth.

See also
histogram()

◆ isCompressed()

bool STK::Image::isCompressed ( ) const
inline

Check if image is compressed. Returns true if the image contains compressed pixel data.

◆ isFloat()

bool STK::Image::isFloat ( ) const
inline

Returns true if the image contains floating point data.

◆ load() [1/3]

bool Image::load ( const std::vector< uint8_t > &  imgBuffer)

Load image. This method loads the image from the given buffer.

◆ load() [2/3]

bool Image::load ( ImageIO loader)

Load image. This method loads the image with data from the given ImageIO object. Any previous data in the image object is deleted.

◆ load() [3/3]

bool STK::Image::load ( std::string  filename)

Load image. This method loads the image from the given file name. A suitable ImageIO object is created from the filename suffix.

◆ pixelSize()

int Image::pixelSize ( Format  fmt)
static

Get pixel size from format. This static method returns the size in bytes of a pixel in the given pixel format.

◆ save()

bool Image::save ( ImageIO saver) const

Save image. This method stores the image on disk using the given ImageIO object.

◆ setAlpha()

void Image::setAlpha ( unsigned char  r,
unsigned char  g,
unsigned char  b,
unsigned char  val 
)

Set alpha value. With this method you may set an alpha value for all pixels with the given color. For example if you want to set all black pixels to be semi-transparent you would say:

img.setAlpha(0, 0, 0, 128);

Note that this method may change the pixel format of the image, if the current format does not contain an alpha channel. If the format is RGB_24 it is converted to RGBA_32 and if the format is RGB_16 it is converted to RGBA_16.

See also
convert()

◆ setMipmap()

bool Image::setMipmap ( const Image img,
int  l 
)

Set mipmap level. Use this method to set data for mipmap level l. If image has less mipmap levels than l, the method fails and returns false.

◆ setNodataValue()

void STK::Image::setNodataValue ( int  nodata)
inline

Set nodata value. This value is used for missing data for example in elevation data files. Default value is -32767

◆ setPixel() [1/2]

bool STK::Image::setPixel ( int  idx,
const Color4i color 
)
inline

Set pixel value by index. This method sets the pixel at index idx to the value given in color. The Color4i object is explected to be scaled to have components in the range $[0,255]$. For grayscale images, only the red component of the image is used.

See also
getVal(int)
setPixel(int)
Color4i

◆ setPixel() [2/2]

bool STK::Image::setPixel ( int  x,
int  y,
const Color4i color 
)
inline

Set pixel value by coordinates. This method sets the pixel at position $(x, y)$ to the value given in color. The Color4i object is expected to be scaled to have components in the range $[0,255]$. For grayscale images, only the red component of the image is used.

See also
getPixel
setPixel(int)
Color4i

◆ setValue() [1/2]

bool STK::Image::setValue ( int  idx,
double  val 
)
inline

Convenience function for elevation data.

◆ setValue() [2/2]

bool STK::Image::setValue ( int  x,
int  y,
double  val 
)
inline

Convenience function for elevation data.

◆ stringToFormat()

Image::Format Image::stringToFormat ( std::string  s)
static

Convert format type to a string.

◆ transform() [1/2]

bool Image::transform ( ImageTransform trans)
virtual

Generalized image transform. This method performs the transform operation(s) defined by the given ImageTransform object on the current image.

◆ transform() [2/2]

bool Image::transform ( ImageTransform trans,
Image dest 
) const

Generalized image transform. This method performs the transform operation(s) defined by the given ImageTransform and places the results in the dst Image object.


The documentation for this class was generated from the following files: