ViSP  2.8.0
vpImageTools Class Reference

#include <vpImageTools.h>

Static Public Member Functions

template<class Type >
static void createSubImage (const vpImage< Type > &I, unsigned int i_sub, unsigned int j_sub, unsigned int nrow_sub, unsigned int ncol_sub, vpImage< Type > &S)
 
template<class Type >
static void createSubImage (const vpImage< Type > &I, const vpRect &rect, vpImage< Type > &S)
 
template<class Type >
static void binarise (vpImage< Type > &I, Type threshold1, Type threshold2, Type value1, Type value2, Type value3)
 
static void changeLUT (vpImage< unsigned char > &I, unsigned char A, unsigned char newA, unsigned char B, unsigned char newB)
 
template<class Type >
static void undistort (const vpImage< Type > &I, const vpCameraParameters &cam, vpImage< Type > &newI)
 
template<class Type >
static void flip (const vpImage< Type > &I, vpImage< Type > &newI)
 
template<class Type >
static void flip (vpImage< Type > &I)
 
static void imageDifference (const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Idiff)
 
static void imageDifferenceAbsolute (const vpImage< unsigned char > &I1, const vpImage< unsigned char > &I2, vpImage< unsigned char > &Idiff)
 

Detailed Description

Various image tools; sub-image extraction, modification of the look up table, binarisation...

Definition at line 79 of file vpImageTools.h.

Member Function Documentation

template<class Type >
void vpImageTools::binarise ( vpImage< Type > &  I,
Type  threshold1,
Type  threshold2,
Type  value1,
Type  value2,
Type  value3 
)
static

Binarise an image.

  • Pixels whose values are less than threshold1 are set to value1
  • Pixels whose values are greater then or equal to threshold1 and less then or equal to threshold2 are set to value2
  • Pixels whose values are greater than threshold2 are set to value3
Examples:
tutorial-ibvs-4pts-ogre-tracking.cpp.

Definition at line 221 of file vpImageTools.h.

References vpImage< Type >::bitmap, vpImage< Type >::getHeight(), and vpImage< Type >::getWidth().

void vpImageTools::changeLUT ( vpImage< unsigned char > &  I,
unsigned char  A,
unsigned char  A_star,
unsigned char  B,
unsigned char  B_star 
)
static

Change the look up table (LUT) of an image. Considering pixel gray level values $ l $ in the range $[A, B]$, this method allows to rescale these values in $[A^*, B^*]$ by linear interpolation:

$ \left\{ \begin{array}{ll} l \in ]-\infty, A] \mbox{, } & l = A^* \\ l \in [B, \infty[ \mbox{, } & l = B^* \\ l \in ]A, B[ \mbox{, } & l = A^* + (l-A) * \frac{B^*-A^*}{B-A} \end{array} \right. $

Parameters
I: Image to process.
A: Low gray level value of the range to consider.
A_star: New gray level value $ A^*$ to attribute to pixel who's value was A
B: Height gray level value of the range to consider.
B_star: New gray level value $ B^*$ to attribute to pixel who's value was B
Returns
The modified image.
Exceptions
vpImageException::incorrectInitializationErrorIf $B \leq A$.

As shown in the example below, this method can be used to binarize an image. For an unsigned char image (in the range 0-255), thresholding this image at level 127 can be done by:

#include <visp/vpImageTools.h>
#include <visp/vpImage.h>
#include <visp/vpImageIo.h>
int main()
{
#ifdef UNIX
std::string filename("/local/soft/ViSP/ViSP-images/Klimt/Klimt.pgm");
#elif WIN32
std::string filename("C:/temp/ViSP-images/Klimt/Klimt.pgm");
#endif
// Read an image from the disk
vpImageIo::read(I, filename);
// Binarize image I:
// - gray level values less than or equal to 127 are set to 0,
// - gray level values greater than 128 are set to 255
vpImageTools::changeLUT(I, 127, 0, 128, 255);
vpImageIo::write(I, "Klimt.pgm"); // Write the image in a PGM P5 image file format
}

Definition at line 102 of file vpImageTools.cpp.

References vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpImageException::incorrectInitializationError, and vpERROR_TRACE.

template<class Type >
void vpImageTools::createSubImage ( const vpImage< Type > &  I,
unsigned int  i_sub,
unsigned int  j_sub,
unsigned int  nrow_sub,
unsigned int  ncol_sub,
vpImage< Type > &  S 
)
static

Extract a sub part of an image

Parameters
I: Input image from which a sub image will be extracted.
i_sub,j_sub: coordinates of the upper left point of the sub image
nrow_sub,ncol_sub: number of row, column of the sub image
S: Sub-image.
Examples:
testCreateSubImage.cpp.

Definition at line 133 of file vpImageTools.h.

References vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

Referenced by vpKeyPointSurf::buildReference(), vpFernClassifier::buildReference(), vpDisplayOpenCV::displayImageROI(), vpDisplayGTK::displayImageROI(), vpPlanarObjectDetector::matchPoint(), vpKeyPointSurf::matchPoint(), vpFernClassifier::matchPoint(), and vpMeNurbs::seekExtremitiesCanny().

template<class Type >
void vpImageTools::createSubImage ( const vpImage< Type > &  I,
const vpRect rect,
vpImage< Type > &  S 
)
static

Extract a sub part of an image

Parameters
I: Input image from which a sub image will be extracted.
rect: Rectangle area in the image I corresponding to the sub part of the image to extract.
S: Sub-image.

Definition at line 171 of file vpImageTools.h.

References vpRect::getBottom(), vpImage< Type >::getHeight(), vpRect::getLeft(), vpRect::getRight(), vpRect::getTop(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

template<class Type >
void vpImageTools::flip ( const vpImage< Type > &  I,
vpImage< Type > &  newI 
)
static

Flip vertically the input image and give the result in the output image.

Parameters
I: Input image to flip.
newI: Output image which is the flipped input image.

Definition at line 529 of file vpImageTools.h.

References vpImage< Type >::bitmap, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

template<class Type >
void vpImageTools::flip ( vpImage< Type > &  I)
static

Flip vertically the input image.

Parameters
I: Input image which is flipped and modified in output.

Definition at line 553 of file vpImageTools.h.

References vpImage< Type >::bitmap, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

void vpImageTools::imageDifference ( const vpImage< unsigned char > &  I1,
const vpImage< unsigned char > &  I2,
vpImage< unsigned char > &  Idiff 
)
static

Compute the signed difference between the two images I1 and I2 for visualization issue : Idiff = I1-I2

  • pixels with a null difference are set to 128.
  • A negative difference implies a pixel value < 128
  • A positive difference implies a pixel value > 128
Parameters
I1: The first image.
I2: The second image.
Idiff: The result of the difference.
Examples:
photometricVisualServoing.cpp.

Definition at line 143 of file vpImageTools.cpp.

References vpImage< Type >::bitmap, vpException::dimensionError, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpMath::maximum(), vpMath::minimum(), and vpImage< Type >::resize().

void vpImageTools::imageDifferenceAbsolute ( const vpImage< unsigned char > &  I1,
const vpImage< unsigned char > &  I2,
vpImage< unsigned char > &  Idiff 
)
static

Compute the difference between the two images I1 and I2

Warning
: This is NOT for visualization If you want to visualize difference images during servo, please use vpImageTools::imageDifference(..,..,..) function.
Parameters
I1: The first image.
I2: The second image.
Idiff: The result of the difference.

Definition at line 177 of file vpImageTools.cpp.

References vpImage< Type >::bitmap, vpException::dimensionError, vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), and vpImage< Type >::resize().

template<class Type >
void vpImageTools::undistort ( const vpImage< Type > &  I,
const vpCameraParameters cam,
vpImage< Type > &  undistI 
)
static

Undistort an image

Parameters
I: Input image to undistort.
cam: Parameters of the camera causing distortion.
undistI: Undistorted output image. The size of this image will be the same than the input image I. If the distortion parameter $K_d$ is null (see cam.get_kd_mp()), undistI is just a copy of I.
Warning
This function works only with Types authorizing "+,-, multiplication by a scalar" operators.
This function is time consuming :
  • On "Rhea"(Intel Core 2 Extreme X6800 2.93GHz, 2Go RAM) or "Charon"(Intel Xeon 3 GHz, 2Go RAM) : ~8 ms for a 640x480 image.
Examples:
testUndistortImage.cpp, and tutorial-undistort.cpp.

Definition at line 358 of file vpImageTools.h.

References vpImage< Type >::bitmap, vpCameraParameters::get_kud(), vpCameraParameters::get_px(), vpCameraParameters::get_py(), vpCameraParameters::get_u0(), vpCameraParameters::get_v0(), vpImage< Type >::getHeight(), vpImage< Type >::getWidth(), vpImage< Type >::resize(), and vpMath::sqr().