Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends
jafar::image::Image Class Reference

Detailed Description

Image class.

Definition at line 55 of file Image.hpp.

#include <Image.hpp>

List of all members.

Public Member Functions

 Image (int width, int height, int depth, JfrImage_TypeColorSpace colorSpace)
 Construct a new Image.
 Image (Image const &img)
 copy constructor from Image
Imageoperator= (Image const &img)
 copy constructor from Image
Imageoperator= (const cv::Mat &matrix)
 copy constructor from cv::Mat affects only the data, the header is kept
 Image (const CvImage &img)
 Override copy constructor of CvImage.
 Image (IplImage *img)
 Override constructor from IplImage.
 Image (const cv::Mat &matrix)
 Override constructor from cv::Mat.
 Image (const Image &img, const cv::Rect &roi)
 copy constructor with relative ROI, without reallocation
Image clone () const
 clone Image (ie copy data)
void copyTo (image::Image &dst, const image::Image &mask=image::Image()) const
 Copies an image into another applying a mask.
void create (int width, int height, int depth, JfrImage_TypeColorSpace colorSpace)
bool load (const std::string &filename, int iscolor=-1)
 Load an image.
void save (const std::string &filename) const
 OpenCV save function.
void save (const std::string &filename, const std::string &imgname)
void save (const std::string &filename, const std::vector< int > &params)
void print ()
void convertColorMode (jafar::image::Image &dst_) const
 Convert Color space of a JfrImage.
void convertDepth (jafar::image::Image &dst_, double scale=1.0, double offset=0.0, bool _abs=false) const
 Change the depth of the image.
void resize (Image &resizedImage, int interpolation=CV_INTER_LINEAR) const
 Resize the current image in resizedImage.
Imageresize (double scale, int interpolation=CV_INTER_LINEAR) const
 Resize the current image in a newly allocated image.
Imageresize (int newWidth, int newHeight, int interpolation=CV_INTER_LINEAR) const
 Resize the current image in a newly allocated image.
void resize (int newWidth, int newHeight, int interpolation=CV_INTER_LINEAR)
 In-place resize of the current image.
int imageSize () const
JfrImage_TypeColorSpace colorSpace () const
void setColorSpace (JfrImage_TypeColorSpace cs)
uchar * data (int line=0)
const uchar * data (int line=0) const
void copy (jafar::image::Image &dst, int x_src=0, int y_src=0, int x_dst=0, int y_dst=0, int width=-1, int height=-1) const
 Copy the image in the destination.
bool robustCopy (jafar::image::Image &dst, int x_src=0, int y_src=0, int x_dst=0, int y_dst=0, int width=-1, int height=-1) const
 Same as copy, but deals correctly with parts outside of images (fills black in dst)
bool extractPatch (image::Image &dst, int x, int y, int width, int height) const
cv::Rect getROI () const
 Get the absolute Region Of Interest of the image.
cv::Rect getROI (cv::Size &size) const
 Get the absolute Region Of Interest and full size of the image.
void setROI (const cv::Rect &rect)
 Set the absolute Region Of Interest of the image.
void setROI (int x, int y, int w, int h)
 Set the absolute Region Of Interest of the image.
void resetROI ()
 Reset the Region Of Interest of the image to the full image.
std::string name () const
void setName (const std::string &_name)
 image file name.
template<typename channeltype >
channeltype getPixelValue (int x_, int y_, int channel_=0) const
template<typename channeltype >
double getSubPixelValue (double x_, double y_, int channel_=0, JfrImage_InterpolationType _interpolation=JfrImage_INTERP_BILINEAR) const
 This function return the subvalue of a pixel with linear interpolation.
template<typename channeltype >
void setPixelValue (channeltype val_, int x_, int y_, int channel_=0)
 Set the value of a pixel.
double computeZncc (Image const *im2) const
 This function compute the ZNCC between two images of the same depth and size.
double computeZnccRoisWeight (Image const *im2, cv::Rect const *roi1_=NULL, cv::Rect const *roi2_=NULL, float const *weightMatrix=NULL) const
 This function computes the ZNCC between two images of the same depth in two regions of interest that must have the same size, and can apply a spatially distributed weight.
double computeZnccRoi (Image const *im2, cv::Rect const *rectRoi) const
 This function computes the ZNCC between two images of the same depth in the given region of interest only.
double computeRotatingZncc (Image const *im2, int rotationStep) const
 This function return the best ZNCC between two images, the second images get rotated.
ImagerankTransform (const int radius)
 Apply rank transform in a newly allocated image.
void rotateScale (double angle, double factor, Image &dest) const
 This function rotates and scales the image.
double orientation (double sigma=1.5)
bool compHeader (Image const &img) const
 operator cv::Mat & ()
 convert to cv::Mat reference
 operator const cv::Mat & () const
 convert to const cv::Mat reference
 operator const IplImage () const
 convert to const IplImage
 operator IplImage ()
 convert to IplImage
 operator const CvMat () const
 convert to const CvMat
 operator CvMat ()
 convert to CvMat
cv::Size size () const
bool empty () const
int width () const
int height () const
size_t step () const
size_t step1 () const
int depth () const
int channels () const
int type () const
cv::Mat mat () const
void detach ()
 detaches image
size_t pix_size ()
 pixel size
void setTo (const cv::Scalar &s, const image::Image &mask=image::Image())
 set the matrix elements to the given value
void convertTo (image::Image &dst, double alpha=1, double beta=0) const
 convert image to another one, it is a wrapping to cv::Mat::converTo

Static Public Member Functions

static ImageloadImage (const char *filename, int iscolor=-1)
 Allocate and load an image.

Private Member Functions

void initImageHeader ()
template<class Archive >
void save (Archive &ar, const unsigned int version) const
template<class Archive >
void load (Archive &ar, const unsigned int version)
double cubicKernel (int t, double dt) const
 Call as t - dt.
double cubicKernelI (int t, int idx) const

Private Attributes

cv::Mat m_matrix
 OpenCV matrix that holds image data.
JfrImage_ImageHeader header
std::string m_name

Static Private Attributes

static const int cubicKernelResolution = 255
static const double cubicKernel1 [256]
static const double cubicKernel2 [256]

Friends

class boost::serialization::access

Constructor & Destructor Documentation

jafar::image::Image::Image ( int  width,
int  height,
int  depth,
JfrImage_TypeColorSpace  colorSpace 
)

Construct a new Image.

Parameters:
widththe image width
heightthe image height
depththe image depth
colorSpacethe color space of the image
Precondition:
width_ > 0
height_ > 0
depth_ is one supported by OpenCV (CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F)
jafar::image::Image::Image ( const Image img,
const cv::Rect &  roi 
)

copy constructor with relative ROI, without reallocation

Warning:
if img already has a ROI defined, the two ROIs will be composed

Member Function Documentation

int jafar::image::Image::channels ( ) const [inline]
Returns:
the image's channels number

Definition at line 478 of file Image.hpp.

References m_matrix.

Referenced by getPixelValue(), getSubPixelValue(), setPixelValue(), jafar::camera::univReprojectionCylindric(), and jafar::camera::univReprojectionPerspective().

Returns:
the colorspace of the image

Definition at line 221 of file Image.hpp.

Referenced by compHeader(), jafar::image::extractPatch(), jafar::hpm::TrackingEngine::initTracking(), and jafar::hpm::TrackingEngine::track().

bool jafar::image::Image::compHeader ( Image const &  img) const [inline]
Returns:
true if img has the same characteristics than this

Definition at line 433 of file Image.hpp.

References colorSpace(), depth(), height(), and width().

double jafar::image::Image::computeRotatingZncc ( Image const *  im2,
int  rotationStep 
) const

This function return the best ZNCC between two images, the second images get rotated.

Parameters:
im2the second image
rotationStepthe step used for the applied rotation
double jafar::image::Image::computeZncc ( Image const *  im2) const

This function compute the ZNCC between two images of the same depth and size.

Parameters:
im2the second image
double jafar::image::Image::computeZnccRoi ( Image const *  im2,
cv::Rect const *  rectRoi 
) const

This function computes the ZNCC between two images of the same depth in the given region of interest only.

Parameters:
im2the second image
rectRoidefines the roi
double jafar::image::Image::computeZnccRoisWeight ( Image const *  im2,
cv::Rect const *  roi1_ = NULL,
cv::Rect const *  roi2_ = NULL,
float const *  weightMatrix = NULL 
) const

This function computes the ZNCC between two images of the same depth in two regions of interest that must have the same size, and can apply a spatially distributed weight.

It ignores pixels with extremum value (eg 0 and 255 for char), and ignores parts outside of images, but requires at least half of pixels not ignored to return non 0.

Parameters:
im2the second image
roi1_the region of interest in this image
roi2_the region of interest in the second image (that must have the same size than roi1_)
weightMatrixthe weight matrix that must have the same size than the regions of interest
Returns:
correlation score between 0 and 1

Convert Color space of a JfrImage.

Parameters:
dst_destination image
colorCode_type of conversion.
Precondition:
dst_ exists
Bug:
Does not update colorSpace attribute.
void jafar::image::Image::convertDepth ( jafar::image::Image dst_,
double  scale = 1.0,
double  offset = 0.0,
bool  _abs = false 
) const

Change the depth of the image.

Precondition:
dst_ and this have the same color mode
void jafar::image::Image::copy ( jafar::image::Image dst,
int  x_src = 0,
int  y_src = 0,
int  x_dst = 0,
int  y_dst = 0,
int  width = -1,
int  height = -1 
) const

Copy the image in the destination.

Parameters:
dstdestination
x_srcx coordinate in the source
y_srcy coordinate in the source
x_dstx coordinate in the destination
y_dsty coordinate in the destination

Referenced by jafar::image::extractPatch().

void jafar::image::Image::create ( int  width,
int  height,
int  depth,
JfrImage_TypeColorSpace  colorSpace 
)

create data (check if allocation or reallocation is needed)

Parameters:
widththe image width
heightthe image height
depththe image depth
colorSpacethe color space of the image
Precondition:
width_ > 0
height_ > 0
depth_ is one supported by OpenCV (CV_8U, CV_8S, CV_16U, CV_16S, CV_32S, CV_32F, CV_64F)
double jafar::image::Image::cubicKernel ( int  t,
double  dt 
) const [inline, private]

Call as t - dt.

Parameters:
t
dt

Definition at line 584 of file Image.hpp.

uchar* jafar::image::Image::data ( int  line = 0) [inline]
const uchar* jafar::image::Image::data ( int  line = 0) const [inline]
Parameters:
linethe line number
Returns:
a pointer to the data of the image

Definition at line 237 of file Image.hpp.

References m_matrix.

int jafar::image::Image::depth ( ) const [inline]
bool jafar::image::Image::empty ( ) const [inline]
Returns:
whether the image is empty or not

Definition at line 466 of file Image.hpp.

References m_matrix.

template<typename channeltype >
channeltype jafar::image::Image::getPixelValue ( int  x_,
int  y_,
int  channel_ = 0 
) const [inline]
Returns:
the value of a pixel
Parameters:
channeltypethe channeltype of the image
x_x-coord of the pixel
y_y-coord of the pixel
channel_required channel (default 0)
Precondition:
channeltype must be the real channel type of the image
x_ and y_ must be inside the image

Definition at line 561 of file Image.hpp.

References channels(), data(), height(), JFR_PRECOND, and width().

Referenced by jafar::quasidense::imgDataZncc::imgDataZncc(), jafar::camera::univReprojectionCylindric(), and jafar::camera::univReprojectionPerspective().

cv::Rect jafar::image::Image::getROI ( ) const [inline]

Get the absolute Region Of Interest of the image.

Note:
{General information about ROI since Opencv 2: With opencv 2, ROIs are implicit. It means that once you have set the ROI of an image, the image appears as if it is only the ROI area, so by manipulating what appears to be the whole image you only manipulate the ROI area.}
Warning:
This function is only informative, it should not be used to take into account the processed area.

Definition at line 269 of file Image.hpp.

References size().

Referenced by jafar::correl::Explorer< Correl >::exploreTranslation().

cv::Rect jafar::image::Image::getROI ( cv::Size &  size) const [inline]

Get the absolute Region Of Interest and full size of the image.

Parameters:
sizethe full size of the image

Definition at line 278 of file Image.hpp.

References m_matrix.

template<typename channeltype >
double jafar::image::Image::getSubPixelValue ( double  x_,
double  y_,
int  channel_ = 0,
JfrImage_InterpolationType  _interpolation = JfrImage_INTERP_BILINEAR 
) const

This function return the subvalue of a pixel with linear interpolation.

Returns:
the subvalue of a pixel
Parameters:
channeltypethe channeltype of the image
x_x-coord of the subpixel
y_y-coord of the subpixel
channel_required channel (default 0)
Precondition:
channeltype must be the real channel type of the image
x_ and y_ must be inside the image
Warning:
the coordinates are translated by 0.5, meaning that getSubPixelValue( x_, y_ ) == getPixelValue( x_, y_)

Definition at line 591 of file Image.hpp.

References channels(), data(), height(), JFR_PRECOND, and width().

Referenced by jafar::quasidense::omniDataCensus::omniDataCensus(), jafar::camera::univReprojectionCylindric(), and jafar::camera::univReprojectionPerspective().

int jafar::image::Image::height ( ) const [inline]
Returns:
the size of the image data in bytes
bool jafar::image::Image::load ( const std::string &  filename,
int  iscolor = -1 
)

Load an image.

Parameters:
filenameis the name of file to be loaded
iscolorspecifies colorness of the loaded image: if >0, the loaded image is forced to be color 3-channel image; if 0, the loaded image is forced to be grayscale; if <0, the loaded image will be loaded as is (with number of channels depends on the file).

Currently the following file formats are supported: Windows bitmaps - BMP, DIB; JPEG files - JPEG, JPG, JPE; JPEG 2000 files - JP2 Portable Network Graphics - PNG; Portable image format - PBM, PGM, PPM; Sun rasters - SR, RAS; TIFF files - TIFF, TIF.

static Image* jafar::image::Image::loadImage ( const char *  filename,
int  iscolor = -1 
) [static]

Allocate and load an image.

Parameters:
filenameis the name of file to be loaded
iscolorspecifies colorness of the loaded image: if >0, the loaded image is forced to be color 3-channel image; if 0, the loaded image is forced to be grayscale; if <0, the loaded image will be loaded as is (with number of channels depends on the file).

Currently the following file formats are supported: Windows bitmaps - BMP, DIB; JPEG files - JPEG, JPG, JPE; JPEG 2000 files - JP2 Portable Network Graphics - PNG; Portable image format - PBM, PGM, PPM; Sun rasters - SR, RAS; TIFF files - TIFF, TIF.

cv::Mat jafar::image::Image::mat ( ) const [inline]
Returns:
the image's data organized in cv::Mat

Definition at line 482 of file Image.hpp.

References m_matrix.

std::string jafar::image::Image::name ( ) const [inline]
Returns:
the image file name.

Definition at line 329 of file Image.hpp.

double jafar::image::Image::orientation ( double  sigma = 1.5)
Returns:
the orientation of the image, computed from the gradients.
Image* jafar::image::Image::rankTransform ( const int  radius)

Apply rank transform in a newly allocated image.

Parameters:
radiusradius of the window used to compute rank
Returns:
the filtered image

Referenced by jafar::quasidense::imgDataRank::imgDataRank().

Image* jafar::image::Image::resize ( double  scale,
int  interpolation = CV_INTER_LINEAR 
) const

Resize the current image in a newly allocated image.

Parameters:
scalescale factor
interpolationinterpolation mode
Returns:
the resized image
Image* jafar::image::Image::resize ( int  newWidth,
int  newHeight,
int  interpolation = CV_INTER_LINEAR 
) const

Resize the current image in a newly allocated image.

Parameters:
widthnew width
heightnew height
interpolationinterpolation mode
Returns:
the resized image
void jafar::image::Image::resize ( int  newWidth,
int  newHeight,
int  interpolation = CV_INTER_LINEAR 
)

In-place resize of the current image.

Parameters:
widthnew width
heightnew height
interpolationinterpolation mode
bool jafar::image::Image::robustCopy ( jafar::image::Image dst,
int  x_src = 0,
int  y_src = 0,
int  x_dst = 0,
int  y_dst = 0,
int  width = -1,
int  height = -1 
) const

Same as copy, but deals correctly with parts outside of images (fills black in dst)

Returns:
true if there isn't any hole in dst (no area filled in black)
void jafar::image::Image::rotateScale ( double  angle,
double  factor,
Image dest 
) const

This function rotates and scales the image.

Parameters:
anglethe rotation angle (degrees)
factorthe scaling factor
destthe destination image
void jafar::image::Image::save ( const std::string &  filename) const [inline]

OpenCV save function.

Parameters:
filenamename of the file where to save the image (for instance "myimage.png" or "myimage.tiff"...)

Definition at line 152 of file Image.hpp.

References m_matrix.

Referenced by jafar::quasidense::omniMask::omniMask().

void jafar::image::Image::save ( const std::string &  filename,
const std::string &  imgname 
) [inline]
Parameters:
imgnameit's the name of the image, and is only usefull when saving to opencv's specific file format (no extension)

Definition at line 160 of file Image.hpp.

References m_matrix.

void jafar::image::Image::save ( const std::string &  filename,
const std::vector< int > &  params 
) [inline]
Parameters:
paramsopencv save parameters

Definition at line 168 of file Image.hpp.

References m_matrix.

void jafar::image::Image::setName ( const std::string &  _name) [inline]

image file name.

Parameters:
_namefile name of the image

Definition at line 337 of file Image.hpp.

template<typename channeltype >
void jafar::image::Image::setPixelValue ( channeltype  val_,
int  x_,
int  y_,
int  channel_ = 0 
)

Set the value of a pixel.

Parameters:
channeltypethe channeltype of the image
val_the new value
x_x-coord of the pixel
y_y-coord of the pixel
channel_required channel (default 0)
Precondition:
channeltype must be the real channel type of the image
x_ and y_ must be inside the image

Definition at line 661 of file Image.hpp.

References channels(), data(), height(), JFR_PRECOND, and width().

Referenced by jafar::quasidense::omniMask::omniMask(), jafar::camera::univReprojectionCylindric(), and jafar::camera::univReprojectionPerspective().

void jafar::image::Image::setROI ( const cv::Rect &  rect) [inline]

Set the absolute Region Of Interest of the image.

Do not forget that you can also create a new image with a relative ROIs without reallocation

Definition at line 293 of file Image.hpp.

cv::Size jafar::image::Image::size ( ) const [inline]
size_t jafar::image::Image::step ( ) const [inline]
Returns:
the image's step in bytes

Definition at line 472 of file Image.hpp.

References m_matrix.

Referenced by jafar::quasidense::imgDataCensus::imgDataCensus(), and jafar::quasidense::imgDataRank::imgDataRank().

size_t jafar::image::Image::step1 ( ) const [inline]
Returns:
the image's step in number of elements

Definition at line 474 of file Image.hpp.

References m_matrix.

int jafar::image::Image::type ( ) const [inline]
Returns:
the image's matrix type

Definition at line 480 of file Image.hpp.

References m_matrix.

Referenced by convertTo(), jafar::camera::univReprojectionCylindric(), and jafar::camera::univReprojectionPerspective().

int jafar::image::Image::width ( ) const [inline]

The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:39 for Jafar by doxygen 1.7.6.1
LAAS-CNRS