27 #include <mrpt/otherlibs/do_opencv_includes.h>    30 #       include <mexplus/mxarray.h>    36 #if MRPT_HAS_WXWIDGETS    37 #       include <wx/image.h>    57 #define  IMAGE_ALLOC_PERFLOG  0    59 #if IMAGE_ALLOC_PERFLOG    69         bool                    originTopLeft ) :
    71                 m_imgIsReadOnly(false),
    72                 m_imgIsExternalStorage(false)
    83         m_imgIsReadOnly(false),
    84         m_imgIsExternalStorage(false)
    98         m_imgIsReadOnly(false),
    99         m_imgIsExternalStorage(false)
   112         if (
this==&o) 
return *
this;
   120                 ASSERTMSG_(o.
img!=NULL,
"Source image in = operator has NULL IplImage*")
   121                 img = cvCloneImage( (IplImage*)o.
img );
   170         if (
this==&o) 
return;
   203         m_imgIsReadOnly(false),
   204         m_imgIsExternalStorage(false)
   212                 img = cvCloneImage( (IplImage*) iplImage );
   241                 IplImage *ipl = 
static_cast<IplImage*
>(
img);
   242                 if (static_cast<unsigned int>(ipl->width)==
width &&
   243                     static_cast<unsigned int>(ipl->height)==
height &&
   244                     ipl->nChannels == nChannels &&
   245                     ipl->origin == ( originTopLeft ? 0:1)
   255 #       if IMAGE_ALLOC_PERFLOG   257         alloc_tims.
enter(sLog.c_str());
   260         img = cvCreateImage( cvSize(
width,
height),IPL_DEPTH_8U, nChannels );
   261         ((IplImage*)
img)->origin = originTopLeft ? 0:1;
   263 #       if IMAGE_ALLOC_PERFLOG   264         alloc_tims.
leave(sLog.c_str());
   268         THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   282         IplImage* newImg = cvLoadImage(fileName.c_str(),
isColor);
   291         THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   306     #if MRPT_OPENCV_VERSION_NUM>0x110   308         p[0] = CV_IMWRITE_JPEG_QUALITY;
   311         return (0!= cvSaveImage(fileName.c_str(),
img,
p) );
   313         return (0!= cvSaveImage(fileName.c_str(),
img) );
   316         THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   332                 img = cvCloneImage( (IplImage*)iplImage );
   334                 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   349         ASSERTMSG_(iplImage!=this->
img,
"Trying to assign read-only to itself.")
   351         img = (IplImage*)iplImage;
   354                 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   373                 img = (IplImage*)iplImage;
   375                 THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   391                         unsigned char   *rawpixels,
   401         if (
color && swapRedBlue)
   404                 unsigned char *ptr_src = rawpixels;
   405                 unsigned char *ptr_dest = 
reinterpret_cast<unsigned char*
>( ((IplImage*)
img)->imageData );
   406                 const int  bytes_per_row_out = ((IplImage*)
img)->widthStep;
   410                         for( 
unsigned int i = 0; i < 
width; i++, ptr_src += 3, ptr_dest += 3 )
   412                                 unsigned char t0 = ptr_src[0], t1 = ptr_src[1], t2 = ptr_src[2];
   413                                 ptr_dest[2] = t0; ptr_dest[1] = t1; ptr_dest[0] = t2;
   415                         ptr_dest += bytes_per_row_out - 
width*3;
   420                 if ( ((IplImage*)
img)->widthStep == ((IplImage*)
img)->
width * ((IplImage*)
img)->nChannels )
   430                         unsigned char *ptr_src = rawpixels;
   431                         unsigned char *ptr_dest = 
reinterpret_cast<unsigned char*
>( ((IplImage*)
img)->imageData );
   433                         int  bytes_per_row_out = ((IplImage*)
img)->widthStep;
   436                                 memcpy( ptr_dest, ptr_src, bytes_per_row );
   437                                 ptr_src+=bytes_per_row;
   438                                 ptr_dest+=bytes_per_row_out;
   443         THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
   454                         unsigned int    channel)
 const   458 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)   463         IplImage *ipl = ((IplImage*)
img);
   465 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)   467         if (
row>=(
unsigned int)ipl->height || col>=(
unsigned int)ipl->width || channel>=(
unsigned int)ipl->nChannels )
   472                         channel, ipl->nChannels ) );
   476         return (
unsigned char*) &ipl->imageData [ 
row * ipl->widthStep +
   477                                                                                           col * ipl->nChannels +
   479 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)   494                         unsigned int    channel)
 const   498         IplImage *ipl = ((IplImage*)
img);
   499         return (
unsigned char*) &ipl->imageData [ 
row * ipl->widthStep +
   500                                                                                           col * ipl->nChannels +
   539                         const bool hasColor = 
isColor();
   559                                 out << imageStoredAsZip;
   562                                 if (imageStoredAsZip )
   564                                         std::vector<unsigned char>      tempBuf;
   566                                                 ((IplImage*)
img)->imageData,            
   615                                         out << neg_width << neg_height;
   618                                         const IplImage *ipl = 
static_cast<const IplImage*
>(
img);
   619                                         const size_t bytes_per_row = ipl->width * 3;
   621                                         out.
WriteBuffer( &ipl->imageData[0], bytes_per_row*ipl->height );
   643                         THROW_EXCEPTION(
"[CImage] Cannot deserialize image since MRPT has been compiled without OpenCV")
   663                         in >> 
width >> 
height >> nChannels >> originTopLeft >> imgLength;
   666                         in.ReadBuffer( ((IplImage*)
img)->imageData, imgLength );
   725                                                 bool    imageIsZIP = 
true;
   744                                                         size_t  outDataActualSize;
   749                                                                 ((IplImage*)
img)->imageData,
   753                                                         ASSERT_(outDataActualSize==outDataBufferSize);
   787                                                                 const IplImage *ipl = 
static_cast<const IplImage*
>(
img);
   788                                                                 const size_t bytes_per_row = ipl->width * 3;
   789                                                                 for (
int y=0;
y<ipl->height;
y++)
   791                                                                         const size_t nRead = 
in.ReadBuffer( &ipl->imageData[
y*ipl->widthStep], bytes_per_row);
   792                                                                         if (nRead!=bytes_per_row) 
THROW_EXCEPTION(
"Error: Truncated data stream while parsing raw image?")
   834     cv::Mat cvImg = cv::cvarrToMat( this->getAs<IplImage>() );
   835         return mexplus::from( cvImg );
   847         s.x = ((IplImage*)
img)->width;
   848         s.y = ((IplImage*)
img)->height;
   860         return ((IplImage*)
img)->width;
   874         return ((IplImage*)
img)->widthStep;
   889         return ((IplImage*)
img)->height;
   903         return ((IplImage*)
img)->nChannels > 1;
   917         return static_cast<unsigned int >( ((IplImage*)
img)->nChannels );
   932         return ((IplImage*)
img)->origin == 0;
   945                         unsigned int    channel)
 const   949         return (*(*
this)(col,
row,channel)) / 255.0f;
   957                         unsigned int    row)
 const   963                 unsigned char   *
pixels = (*this)(col,
row,0);
   969                 return  (*(*
this)(col,
row,0 )) / 255.0f;
  1003         IplImage * img_dest = cvCreateImage( cvSize(img_src->width,img_src->height),IPL_DEPTH_8U, 1 );
  1004         img_dest->origin = img_src->origin;
  1009                 (img_src->width & 0xF) == 0 &&
  1010                 img_src->widthStep==img_src->width*img_src->nChannels &&
  1011                 img_dest->widthStep==img_dest->width*img_dest->nChannels )
  1020         cvCvtColor( img_src, img_dest, CV_BGR2GRAY );
  1033         const IplImage *ipl = this->getAs<const IplImage>();
  1036         if (ipl->nChannels==1)
  1056         const IplImage *ipl = this->getAs<const IplImage>();
  1058         if (ipl->nChannels==1) 
return; 
  1075         const IplImage * img_src = ((IplImage*)
img);
  1076         const int w = img_src->width;
  1077         const int h = img_src->height;
  1080         IplImage * img_dest = cvCreateImage( cvSize(
w>>1,h>>1),IPL_DEPTH_8U, img_src->nChannels );
  1081         img_dest->origin = img_src->origin;
  1082         memcpy(img_dest->colorModel,img_src->colorModel,4);
  1083         memcpy(img_dest->channelSeq,img_src->channelSeq,4);
  1084         img_dest->dataOrder=img_src->dataOrder;
  1089         if (img_src->nChannels==3 &&
  1093                 img_src->widthStep==img_src->width*img_src->nChannels &&
  1094                 img_dest->widthStep==img_dest->width*img_dest->nChannels )
  1103         if (img_src->nChannels==1 &&
  1107                 img_src->widthStep==img_src->width*img_src->nChannels &&
  1108                 img_dest->widthStep==img_dest->width*img_dest->nChannels )
  1133         const IplImage * img_src = ((IplImage*)
img);
  1134         const int w = img_src->width;
  1135         const int h = img_src->height;
  1138         IplImage * img_dest = cvCreateImage( cvSize(
w>>1,h>>1),IPL_DEPTH_8U, img_src->nChannels );
  1139         img_dest->origin = img_src->origin;
  1140         memcpy(img_dest->colorModel,img_src->colorModel,4);
  1141         memcpy(img_dest->channelSeq,img_src->channelSeq,4);
  1142         img_dest->dataOrder=img_src->dataOrder;
  1147         if (img_src->nChannels==1 &&
  1151                 img_src->widthStep==img_src->width*img_src->nChannels &&
  1152                 img_dest->widthStep==img_dest->width*img_dest->nChannels )
  1185         return ((IplImage*)
img)->channelSeq;
  1198                         unsigned int            bytesPerRow,
  1200                         unsigned char           *
green,
  1201                         unsigned char           *
blue )
  1213                 unsigned char *dest = (
unsigned char *)((IplImage*)
img)->imageData + ((IplImage*)
img)->widthStep * 
y;
  1216                 unsigned char *srcR = 
red + bytesPerRow * 
y;
  1217                 unsigned char *srcG = 
green + bytesPerRow * 
y;
  1218                 unsigned char *srcB = 
blue + bytesPerRow * 
y;
  1222             *(dest++) = *(srcB++);
  1223             *(dest++) = *(srcG++);
  1224             *(dest++) = *(srcR++);
  1241         ((IplImage*)
img)->origin =  
val ? 0:1;
  1255 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)  1261         IplImage *ipl = ((IplImage*)
img);
  1263 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)  1270                 if (ipl->nChannels==1)
  1272                         *( (
unsigned char*) &ipl->imageData     [ 
y * ipl->widthStep + 
x ] ) = (
unsigned char) 
color;
  1276 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)  1277                         ASSERT_( ipl->nChannels ==3 );
  1278                         if ( ipl->dataOrder!=0 )
  1279                                 THROW_EXCEPTION(
"Please, use interleaved images like normal people!!! :-)");
  1281                         unsigned char   *dest = (
unsigned char*) &ipl->imageData[ 
y * ipl->widthStep + 3*
x ];
  1282                         unsigned char   *
src  = (
unsigned char*) &
color;
  1291 #if defined(_DEBUG) || (MRPT_ALWAYS_CHECKS_DEBUG)  1313         IplImage *ipl = ((IplImage*)
img);
  1332         IplImage *ipl = ((IplImage*)
img);
  1343                           const unsigned int col_,
  1344                           const unsigned int row_)
  1347         IplImage *ipl_int = ((IplImage*)
img);
  1348         IplImage *ipl_ext = ((IplImage*)patch.
img);
  1356         for (
unsigned int i=0;i<patch.
getHeight();i++)
  1358                 memcpy( &ipl_int->imageData[(i+row_) * ipl_int->widthStep + col_ * ipl_int->nChannels],
  1359                         &ipl_ext->imageData[i * ipl_ext->widthStep ],
  1360                         ipl_ext->widthStep);
  1370     const unsigned int  col_,
  1371         const unsigned int      row_,
  1372         const unsigned int col_num,
  1373         const unsigned int row_num)
const  1378         IplImage *ipl_int = ((IplImage*)
img);
  1381         if ((ipl_int->width<(
int)(col_+col_num)) || (ipl_int->height<(
int)(row_+row_num)))
  1383                 THROW_EXCEPTION( 
format(
"Trying to extract patch out of image boundaries: Image size=%ix%i, Patch size=%ux%u, extraction location=(%u,%u)",ipl_int->width,ipl_int->height, col_num, row_num, col_, row_ ) )
  1386         patch.
resize(col_num,row_num,((IplImage*)
img)->nChannels,
true);
  1387         IplImage *ipl_ext = ((IplImage*)patch.
img);
  1390         for (
unsigned int i=0;i<row_num;i++)
  1392                 memcpy( &ipl_ext->imageData[i * ipl_ext->widthStep ],
  1393                                 &ipl_int->imageData[(i+row_) * ipl_int->widthStep + col_ * ipl_int->nChannels],
  1394                                 ipl_ext->widthStep);
  1409                 THROW_EXCEPTION(
"Correlation Error!, image to correlate out of bounds");
  1413         float syy=0.0f, sxy=0.0f, sxx=0.0f, m1=0.0f, m2=0.0f ,
n=(float)(img2.
getHeight()*img2.
getWidth());
  1422                         m1 += *(*this)(j+width_init,i+height_init);
  1433                         x1 = *(*this)(j+width_init,i+height_init) - m1;
  1434                         x2 = *img2(j,i) - m2;
  1441         return sxy / sqrt(sxx * syy);
  1460         CImage                          *out_corr_image)
const  1468         CvPoint         min_point,max_point;
  1470         bool entireImg = (x_search_ini<0 || y_search_ini<0 || x_search_size<0 || y_search_size<0);
  1472         const IplImage *im, *patch_im;
  1476                 const IplImage *im_ = this->getAs<IplImage>();
  1477                 const IplImage *patch_im_ = patch_img.
getAs<IplImage>();
  1479                 IplImage *aux = cvCreateImage( cvGetSize( im_ ), 8, 1 );
  1480                 IplImage *aux2 = cvCreateImage( cvGetSize( patch_im_ ), 8, 1 );
  1481                 cvCvtColor( im_, aux, CV_BGR2GRAY );
  1482                 cvCvtColor( patch_im_, aux2, CV_BGR2GRAY );
  1488                 im = this->getAs<IplImage>();
  1489                 patch_im = patch_img.
getAs<IplImage>();
  1494                 x_search_size = im->width - patch_im->width;
  1495                 y_search_size = im->height - patch_im->height;
  1499         if ((x_search_ini + x_search_size  + patch_im->width-1)>im->width)
  1500                 x_search_size -= (x_search_ini + x_search_size + patch_im->width-1) - im->width;
  1502         if ((y_search_ini + y_search_size  + patch_im->height-1)>im->height)
  1503                 y_search_size -= (y_search_ini + y_search_size  + patch_im->height-1) - im->height;
  1505         ASSERT_( (x_search_ini + x_search_size  + patch_im->width-1)<=im->width )
  1506         ASSERT_( (y_search_ini + y_search_size  + patch_im->height-1)<=im->height )
  1508         IplImage *result = cvCreateImage(cvSize(x_search_size+1,y_search_size+1),IPL_DEPTH_32F, 1);
  1510         const IplImage *ipl_ext;
  1514                 IplImage *aux= cvCreateImage(cvSize(patch_im->width+x_search_size,patch_im->height+y_search_size),IPL_DEPTH_8U, 1);
  1515                 for (
unsigned int i = 0 ; i < (
unsigned int)y_search_size ; i++)
  1517                         memcpy( &aux->imageData[i * aux->widthStep ],
  1518                                         &im->imageData[(i+y_search_ini) * im->widthStep + x_search_ini * im->nChannels],
  1519                                         aux->width * aux->nChannels ); 
  1529         cvMatchTemplate(ipl_ext,patch_im,result,CV_TM_CCORR_NORMED);
  1533         cvMinMaxLoc(result,&mini,&max_val,&min_point,&max_point,NULL);
  1534         x_max = max_point.x+x_search_ini+(
round(patch_im->width-1)/2);
  1535         y_max = max_point.y+y_search_ini+(
round(patch_im->height-1)/2);
  1539                 IplImage *aux = 
const_cast<IplImage*
>(ipl_ext);
  1540                 cvReleaseImage( &aux );
  1548                 cvReleaseImage( &result );
  1550         THROW_EXCEPTION(
"The MRPT has been compiled with MRPT_HAS_OPENCV=0 !");
  1564     IplImage *ipl = getAs<IplImage>();  
  1566         ASSERTMSG_( ipl->nChannels==1, 
"CImage::normalize() only defined for grayscale images.")
  1569         for (
int y=0;
y<ipl->height;
y++)
  1571                 const uint8_t *ptr = 
reinterpret_cast<const uint8_t*
>( ipl->imageData + 
y*ipl->widthStep );
  1572                 for (
int x=0;
x<ipl->width;
x++)
  1575                         if (min_ > 
val) min_=
val;
  1576                         if (max_ < 
val) max_=
val;
  1581         const double s=255.0/((double)max_-(
double)min_);
  1586         for (
int y=0;
y<ipl->height;
y++)
  1588                 uint8_t *ptr = 
reinterpret_cast<uint8_t*
>( ipl->imageData + 
y*ipl->widthStep );
  1589                 for (
int x=0;
x<ipl->width;
x++)
  1617         if (x_max==-1) x_max=((IplImage*)
img)->width-1;
  1618         if (y_max==-1) y_max=((IplImage*)
img)->height-1;
  1623         int             lx = (x_max-x_min+1);
  1624         int             ly = (y_max-y_min+1);
  1626         if (doResize || (
int)outMatrix.getRowCount()<ly || (int)outMatrix.getColCount()<lx)
  1627                 outMatrix.setSize( y_max-y_min+1,x_max-x_min+1 );
  1632                 for (
int y=0;
y<ly;
y++)
  1636                         for (
int x=0;
x<lx;
x++)
  1638                 aux  = *
pixels++ * 0.3f*(1.0f/255);
  1639                 aux += *
pixels++ * 0.59f*(1.0f/255);
  1640                 aux += *
pixels++ * 0.11f*(1.0f/255);
  1641                                 outMatrix.set_unsafe(
y,
x, aux);
  1647                 for (
int y=0;
y<ly;
y++)
  1650                         for (
int x=0;
x<lx;
x++)
  1651                                 outMatrix.set_unsafe(
y,
x, (*
pixels++)*(1.0f/255) );
  1680         if (x_max==-1) x_max=((IplImage*)
img)->width-1;
  1681         if (y_max==-1) y_max=((IplImage*)
img)->height-1;
  1686         int             lx = (x_max-x_min+1);
  1687         int             ly = (y_max-y_min+1);
  1689         if (doResize || (
int)outMatrixR.getRowCount()<ly || (int)outMatrixR.getColCount()<lx)
  1690                 outMatrixR.setSize( y_max-y_min+1,x_max-x_min+1 );
  1691         if (doResize || (
int)outMatrixG.getRowCount()<ly || (int)outMatrixG.getColCount()<lx)
  1692                 outMatrixG.setSize( y_max-y_min+1,x_max-x_min+1 );
  1693         if (doResize || (
int)outMatrixB.getRowCount()<ly || (int)outMatrixB.getColCount()<lx)
  1694                 outMatrixB.setSize( y_max-y_min+1,x_max-x_min+1 );
  1698                 for (
int y=0;
y<ly;
y++)
  1702                         for (
int x=0;
x<lx;
x++)
  1704                 aux = *
pixels++ * (1.0f/255);
  1705                                 outMatrixR.set_unsafe(
y,
x, aux);
  1706                 aux = *
pixels++ * (1.0f/255);
  1707                                 outMatrixG.set_unsafe(
y,
x, aux);
  1708                 aux = *
pixels++ * (1.0f/255);
  1709                                 outMatrixB.set_unsafe(
y,
x, aux);
  1716                 for (
int y=0;
y<ly;
y++)
  1719                         for (
int x=0;
x<lx;
x++)
  1721                                 outMatrixR.set_unsafe(
y,
x, (*
pixels)*(1.0f/255) );
  1722                                 outMatrixG.set_unsafe(
y,
x, (*
pixels)*(1.0f/255) );
  1723                                 outMatrixB.set_unsafe(
y,
x, (*
pixels++)*(1.0f/255) );
  1744         float                           biasInImg )
 const  1752         if (u_search_ini==-1)   u_search_ini=0;
  1753         if (v_search_ini==-1)   v_search_ini=0;
  1754         if (u_search_size==-1)  u_search_size=
getWidth();
  1755         if (v_search_size==-1)  v_search_size=
getHeight();
  1757         int     u_search_end = u_search_ini + u_search_size-1;
  1758         int     v_search_end = v_search_ini + v_search_size-1;
  1765         size_t          actual_lx = max( u_search_size,(
int)in_img.
getWidth());
  1766         size_t          actual_ly = max( v_search_size,(
int)in_img.
getHeight());
  1777         i2.fill(biasThisImg);
  1785                 u_search_ini+u_search_size-1,
  1786                 v_search_ini+v_search_size-1 );
  1792         i2.array() -= biasThisImg;
  1793         i1.array() -= biasInImg;
  1799         CMatrix         I1_R,I1_I,I2_R,I2_I,ZEROS(ly,lx);
  1807         for (
y = 0;
y<ly;
y++)
  1808                 for (
x = 0;
x<lx;
x++)
  1810                         float   r1 = I1_R.get_unsafe(
y,
x);
  1811                         float   r2 = I2_R.get_unsafe(
y,
x);
  1813                         float   ii1 = I1_I.get_unsafe(
y,
x);
  1814                         float   ii2 = I2_I.get_unsafe(
y,
x);
  1817                         I2_R.set_unsafe(
y,
x, (r1*r2+ii1*ii2)/den);
  1818                         I2_I.set_unsafe(
y,
x, (ii2*r1-r2*ii1)/den);
  1828         out_corr.setSize(actual_ly,actual_lx);
  1829         for (
y = 0;
y<actual_ly;
y++)
  1830                 for (
x = 0;
x<actual_lx;
x++)
  1849         size_t  matrix_lx = outMatrix.getColCount();
  1850         size_t  matrix_ly = outMatrix.getRowCount();
  1855                 for (
unsigned int y=0;
y<matrix_ly;
y++)
  1857                         unsigned char   *min_pixels = (*this)(0,
y % ((IplImage*)
img)->height,0);
  1858                         unsigned char   *max_pixels = min_pixels + ((IplImage*)
img)->width*3;
  1859                         unsigned char   *
pixels = min_pixels;
  1861                         for (
unsigned int x=0;
x<matrix_lx;
x++)
  1864                             aux += *
pixels++ * 0.59f;
  1865                             aux += *
pixels++ * 0.11f;
  1866                                 outMatrix.set_unsafe(
y,
x, aux);
  1874                 for (
unsigned int y=0;
y<matrix_ly;
y++)
  1876                         unsigned char   *min_pixels = (*this)(0,
y % ((IplImage*)
img)->height,0);
  1877                         unsigned char   *max_pixels = min_pixels + ((IplImage*)
img)->width;
  1878                         unsigned char   *
pixels = min_pixels;
  1879                         for (
unsigned int x=0;
x<matrix_lx;
x++)
  1881                                 outMatrix.set_unsafe(
y,
x, *
pixels++ );
  1898         m_externalFile = fileName;
  1899         m_imgIsExternalStorage = 
true;
  1917         if (
img && !m_imgIsReadOnly)
  1919                 IplImage *ptr=(IplImage*)
img;
  1920                 cvReleaseImage( &ptr );
  1923         m_imgIsReadOnly = 
false;
  1924         if (!thisIsExternalImgUnload)
  1926                 m_imgIsExternalStorage = 
false;
  1927                 m_externalFile = 
string();
  1937         if (
img!=NULL) 
return;  
  1956         else THROW_EXCEPTION(
"img is NULL in a non-externally stored image.");
  1988         IplImage *ptr=(IplImage*)
img;
  1989         int options = CV_CVTIMG_FLIP;
  1990         if(also_swapRB) options |= CV_CVTIMG_SWAP_RB;
  1991         cvConvertImage(ptr,ptr,options);
  1998         IplImage *ptr=(IplImage*)
img;
  1999         cvFlip(ptr,
nullptr,1);
  2011         IplImage *ptr=(IplImage*)
img;
  2012         cvConvertImage(ptr,ptr,CV_CVTIMG_SWAP_RB);
  2025 #if MRPT_OPENCV_VERSION_NUM<0x200  2029     IplImage *srcImg = getAs<IplImage>();       
  2030         IplImage *outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2032     cv::Mat *_mapX, *_mapY;
  2033     _mapX = 
static_cast<cv::Mat*
>(mapX);
  2034     _mapY = 
static_cast<cv::Mat*
>(mapY);
  2036     IplImage _mapXX = *_mapX;
  2037     IplImage _mapYY = *_mapY;
  2039     cvRemap(srcImg,outImg, &_mapXX,&_mapYY,CV_INTER_CUBIC);
  2056         IplImage *srcImg = getAs<IplImage>();   
  2058         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2060         double aux1[3][3], aux2[1][5];
  2063         for (
int i=0;i<3;i++)
  2064                 for (
int j=0;j<3;j++)
  2065                         aux1[i][j] = cameraMatrix(i,j);
  2066         for (
int i=0;i<5;i++)
  2067                 aux2[0][i]=cameraParams.
dist[i];
  2069         CvMat inMat =  cvMat( cameraMatrix.getRowCount(), cameraMatrix.getColCount(), CV_64F, aux1 );
  2070         CvMat distM =  cvMat( 1, 5, CV_64F, aux2 );
  2073         cvUndistort2( srcImg, outImg, &inMat, &distM );
  2092         const IplImage *srcImg = getAs<IplImage>();     
  2094         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2096         double aux1[3][3], aux2[1][5];
  2099         for (
int i=0;i<3;i++)
  2100                 for (
int j=0;j<3;j++)
  2101                         aux1[i][j] = cameraMatrix(i,j);
  2102         for (
int i=0;i<5;i++)
  2103                 aux2[0][i]=cameraParams.
dist[i];
  2105         CvMat inMat =  cvMat( cameraMatrix.getRowCount(), cameraMatrix.getColCount(), CV_64F, aux1 );
  2106         CvMat distM =  cvMat( 1, 5, CV_64F, aux2 );
  2109         cvUndistort2( srcImg, outImg, &inMat, &distM );
  2115         cvReleaseImage( &outImg );
  2129         const IplImage *srcImg = getAs<IplImage>();     
  2131         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2134         cvSmooth( srcImg, outImg, CV_MEDIAN, W );
  2136         outImg->origin = srcImg->origin;
  2142         cvReleaseImage( &outImg );
  2155         IplImage *srcImg = getAs<IplImage>();   
  2157         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2160         cvSmooth( srcImg, outImg, CV_MEDIAN, W );
  2162         outImg->origin = srcImg->origin;
  2179         const IplImage *srcImg = getAs<IplImage>();     
  2181         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2184         cvSmooth( srcImg, outImg, CV_GAUSSIAN, W, H );
  2186         outImg->origin = srcImg->origin;
  2192         cvReleaseImage( &outImg );
  2205         IplImage *srcImg = getAs<IplImage>();   
  2207         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2210         cvSmooth( srcImg, outImg, CV_GAUSSIAN, W, H );
  2212         outImg->origin = srcImg->origin;
  2229         IplImage *srcImg = getAs<IplImage>();   
  2231         if( static_cast<unsigned int>(srcImg->width) == 
width && 
static_cast<unsigned int>(srcImg->height) == 
height )
  2235         outImg = cvCreateImage( cvSize(
width,
height), srcImg->depth, srcImg->nChannels );
  2238         cvResize( srcImg, outImg, (
int)
interp );
  2240         outImg->origin = srcImg->origin;
  2256         const IplImage *srcImg = getAs<IplImage>();     
  2258         if( static_cast<unsigned int>(srcImg->width) == 
width && 
static_cast<unsigned int>(srcImg->height) == 
height )
  2266         outImg = cvCreateImage( cvSize(
width,
height), srcImg->depth, srcImg->nChannels );
  2269         cvResize( srcImg, outImg, (
int)
interp );
  2270         outImg->origin = srcImg->origin;
  2287         IplImage *srcImg = getAs<IplImage>();   
  2289         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2296         CvMat M = cvMat(2, 3, CV_32F, m);
  2298         m[0] = (float)(
scale*cos(angle_radians));
  2299         m[1] = (float)(
scale*sin(angle_radians));
  2305         cvGetQuadrangleSubPix( srcImg, outImg, &M );
  2307         outImg->origin = srcImg->origin;
  2326         std::vector<TPixelCoordf>       &cornerCoords,
  2327         unsigned int  check_size_x,
  2328         unsigned int  check_size_y,
  2329         unsigned int  lines_width,
  2334         if (cornerCoords.size()!=check_size_x*check_size_y) 
return false;
  2336         IplImage* ipl = this->getAs<IplImage>();
  2338         unsigned int x, 
y,i;
  2339         CvPoint prev_pt = cvPoint(0, 0);
  2340         const int line_max = 8;
  2341         CvScalar line_colors[8];
  2343         line_colors[0] = CV_RGB(255,0,0);
  2344         line_colors[1] = CV_RGB(255,128,0);
  2345         line_colors[2] = CV_RGB(255,128,0);
  2346         line_colors[3] = CV_RGB(200,200,0);
  2347         line_colors[4] = CV_RGB(0,255,0);
  2348         line_colors[5] = CV_RGB(0,200,200);
  2349         line_colors[6] = CV_RGB(0,0,255);
  2350         line_colors[7] = CV_RGB(255,0,255);
  2354         for( 
y = 0, i = 0; 
y < check_size_y; 
y++ )
  2356                 CvScalar 
color = line_colors[
y % line_max];
  2357                 for( 
x = 0; 
x < check_size_x; 
x++, i++ )
  2360                         pt.x = cvRound( cornerCoords[i].
x);
  2361                         pt.y = cvRound( cornerCoords[i].
y);
  2363                         if( i != 0 ) cvLine(ipl, prev_pt, pt, 
color, lines_width );
  2366                                           cvPoint( pt.x - 
r, pt.y - 
r ),
  2367                                           cvPoint( pt.x + 
r, pt.y + 
r ), 
color, lines_width );
  2369                                           cvPoint( pt.x - 
r, pt.y + 
r),
  2370                                           cvPoint( pt.x + 
r, pt.y - 
r), 
color, lines_width );
  2373                                 cvCircle(ipl, pt, 
r+1, 
color );
  2377                         if (i==0 || i==cornerCoords.size()-1)
  2400         const IplImage *srcImg = getAs<IplImage>();     
  2401         IplImage *outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, 3 );
  2403         cvCvtColor( srcImg, outImg, CV_GRAY2BGR );
  2405         outImg->origin = srcImg->origin;
  2420         IplImage *srcImg = getAs<IplImage>();   
  2422         outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, 3 );
  2424         cvCvtColor( srcImg, outImg, CV_GRAY2BGR );
  2426         outImg->origin = srcImg->origin;
  2442         const IplImage* _im1 = im1.
getAs<IplImage>();
  2443         const IplImage* _im2 = im2.
getAs<IplImage>();
  2445         ASSERT_( _im1->depth == _im2->depth && _im1->nChannels == _im2->nChannels );
  2447         IplImage *out = cvCreateImage( cvSize( _im1->width + _im2->width, _im1->height ), _im1->depth, _im1->nChannels );
  2449         cvSetImageROI( out, cvRect( 0, 0, _im1->width, _im1->height ) );
  2450         cvCopy( _im1, out );
  2451         cvSetImageROI( out, cvRect( _im1->width, 0, _im2->width, _im2->height ) );
  2452         cvCopy( _im2, out );
  2453         cvSetImageROI( out, cvRect( 0, 0, out->width, out->height ) );
  2456         if( (
int)_im1->nChannels != (
int)this->getChannelCount() )      
  2458                 out2 = cvCreateImage( cvSize( _im1->width + _im2->width, _im1->height ), _im1->depth, this->getChannelCount() );
  2459                 cvCvtColor( out, out2, CV_GRAY2BGR );
  2478         const IplImage *srcImg = getAs<IplImage>();     
  2483         if (srcImg->nChannels==1)
  2485                 cvEqualizeHist(srcImg, outImg.
getAs<IplImage>() );
  2489                 IplImage *hsv = cvCreateImage(cvGetSize(srcImg), 8, 3);
  2490                 IplImage *h = cvCreateImage(cvGetSize(srcImg), 8, 1);
  2491                 IplImage *
s = cvCreateImage(cvGetSize(srcImg), 8, 1);
  2492                 IplImage *
v = cvCreateImage(cvGetSize(srcImg), 8, 1);
  2494                 cvCvtColor(srcImg, hsv, CV_BGR2HSV);
  2495                 cvSplit(hsv, h, 
s, 
v, NULL);
  2497                 cvEqualizeHist(
v, 
v);
  2499                 cvMerge(h, 
s, 
v, NULL, hsv);
  2500                 cvCvtColor(hsv, outImg.
getAs<IplImage>(), CV_HSV2BGR);
  2502                 cvReleaseImage(&hsv);
  2518         IplImage *srcImg = getAs<IplImage>();   
  2521         IplImage *outImg = cvCreateImage( cvGetSize( srcImg ), srcImg->depth, srcImg->nChannels );
  2522         outImg->origin = srcImg->origin;
  2524         if (srcImg->nChannels==1)
  2526                 cvEqualizeHist(srcImg, outImg );
  2530                 IplImage *hsv = cvCreateImage(cvGetSize(srcImg), 8, 3);
  2531                 IplImage *h = cvCreateImage(cvGetSize(srcImg), 8, 1);
  2532                 IplImage *
s = cvCreateImage(cvGetSize(srcImg), 8, 1);
  2533                 IplImage *
v = cvCreateImage(cvGetSize(srcImg), 8, 1);
  2535                 cvCvtColor(srcImg, hsv, CV_BGR2HSV);
  2536                 cvSplit(hsv, h, 
s, 
v, NULL);
  2538                 cvEqualizeHist(
v, 
v);
  2540                 cvMerge(h, 
s, 
v, NULL, hsv);
  2541                 cvCvtColor(hsv, outImg, CV_HSV2BGR);
  2543                 cvReleaseImage(&hsv);
  2557 template <
unsigned int HALF_WIN_SIZE>
  2560         const unsigned int min_x = 
x-HALF_WIN_SIZE;
  2561         const unsigned int min_y = 
y-HALF_WIN_SIZE;
  2567         const unsigned int WIN_SIZE = 1+2*HALF_WIN_SIZE;
  2569         unsigned int yy = min_y;
  2570         for (
unsigned int iy=WIN_SIZE; iy ; --iy, ++yy)
  2572                 const uint8_t* ptr = 
in + widthStep*yy+ min_x;
  2573                 unsigned int xx = min_x;
  2574                 for (
unsigned int ix = WIN_SIZE; ix; --ix, ++xx)
  2576                         const int32_t dx = ptr[+1]-ptr[-1];
  2577                         const int32_t dy = ptr[+widthStep]-ptr[-widthStep];
  2591         const unsigned int x,
  2592         const unsigned int y,
  2593         const unsigned int half_window_size )
 const  2596         const IplImage *srcImg = this->getAs<IplImage>();
  2598         ASSERTMSG_(srcImg->nChannels==1, 
"KLT_response only works with grayscale images.")
  2600         const unsigned int img_w = srcImg->width;
  2601         const unsigned int img_h = srcImg->height;
  2602         const int widthStep = srcImg->widthStep;
  2605         const unsigned int min_x = 
x-half_window_size;
  2606         const unsigned int max_x = 
x+half_window_size;
  2607         const unsigned int min_y = 
y-half_window_size;
  2608         const unsigned int max_y = 
y+half_window_size;
  2611         ASSERTMSG_(min_x<img_w && max_x<img_w && min_y<img_h && max_y<img_h, 
"Window is out of image bounds")
  2618         const uint8_t* img_data = 
reinterpret_cast<const uint8_t*
>(srcImg->imageData);  
  2619         switch (half_window_size)
  2621                 case 2: image_KLT_response_template<2>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2622                 case 3: image_KLT_response_template<3>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2623                 case 4: image_KLT_response_template<4>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2624                 case 5: image_KLT_response_template<5>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2625                 case 6: image_KLT_response_template<6>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2626                 case 7: image_KLT_response_template<7>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2627                 case 8: image_KLT_response_template<8>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2628                 case 9: image_KLT_response_template<9>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2629                 case 10: image_KLT_response_template<10>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2630                 case 11: image_KLT_response_template<11>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2631                 case 12: image_KLT_response_template<12>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2632                 case 13: image_KLT_response_template<13>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2633                 case 14: image_KLT_response_template<14>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2634                 case 15: image_KLT_response_template<15>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2635                 case 16: image_KLT_response_template<16>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2636                 case 32: image_KLT_response_template<32>(img_data,widthStep,
x,
y,gxx,gyy,gxy); 
break;
  2639                         for (
unsigned int yy = min_y; yy<=max_y; yy++)
  2641                                 const uint8_t* ptr = img_data + widthStep*yy+ min_x;
  2642                                 for (
unsigned int xx = min_x; xx<=max_x; xx++)
  2644                                         const int32_t dx = ptr[+1]-ptr[-1];
  2645                                         const int32_t dy = ptr[+widthStep]-ptr[-widthStep];
  2654         const float K = 0.5f/( (max_y-min_y+1) * (max_x-min_x+1) );
  2655         const float Gxx = gxx * K;
  2656         const float Gxy = gxy * K;
  2657         const float Gyy = gyy * K;
  2663         const float t  = Gxx+Gyy;         
  2664         const float de = Gxx*Gyy-Gxy*Gxy; 
  2666         return 0.5f * (
t - std::sqrt( 
t*
t - 4.0f*de ) );
  2680         strcpy( ((IplImage*)
img)->channelSeq, 
"RGB");
  2691         strcpy( ((IplImage*)
img)->channelSeq, 
"BGR");
  2703 #if MRPT_HAS_OPENCV && MRPT_HAS_WXWIDGETS  2705                 const wxImage 
b(xpm_array);
  2707                 const size_t lx = 
b.GetWidth();
  2708                 const size_t ly = 
b.GetHeight();
  2713         catch(std::exception &e)
  2715                 std::cerr << 
"[CImage::loadFromXPM] " << e.what() << std::endl;
  2721 #endif // MRPT_HAS_OPENCV && MRPT_HAS_WXWIDGETS  2730         std::fstream stream;
  2732         if (!stream.is_open())
  2734                 std::cerr << 
"[CImage::loadTGA] Couldn't open file '"<< fileName <<
"'.\n";
  2740         stream.seekg(0, std::ios_base::beg);
  2743         char dumpBuffer[12];
  2744         char trueColorHeader[] = 
"\0\0\2\0\0\0\0\0\0\0\0\0";
  2745         stream.read(dumpBuffer, 12);
  2746         if(memcmp(dumpBuffer, trueColorHeader, 12) != 0)
  2748                 std::cerr << 
"[CImage::loadTGA] Unsupported format or invalid file.\n";
  2755         stream.read((
char *)&
width, 2);
  2756         stream.read((
char *)&
height, 2);
  2760                 std::cerr << 
"[CImage::loadTGA] Only 32 bpp format supported!\n";
  2765         desc = stream.get();
  2766         if(desc!= 8 && desc!=32)
  2768                 std::cerr << 
"[CImage::loadTGA] Unsupported format or invalid file.\n";
  2771         const bool origin_is_low_corner = (desc==8);
  2785                 unsigned int actual_row = origin_is_low_corner ? (
height-1-
r) : 
r;
  2786                 IplImage *ipl = ((IplImage*)out_RGB.
img);
  2787                 unsigned char* 
data= (
unsigned char*) &ipl->imageData[ actual_row * ipl->widthStep ];
  2789                 IplImage *ipl_alpha = ((IplImage*)out_alpha.
img);
  2790                 unsigned char* data_alpha= (
unsigned char*)&ipl->imageData[ actual_row * ipl_alpha->widthStep ];
  2794                         *
data++ = bytes[idx++]; 
  2795                         *
data++ = bytes[idx++]; 
  2796                         *
data++ = bytes[idx++]; 
  2797                         *data_alpha++ = bytes[idx++]; 
  2804 #endif // MRPT_HAS_OPENCV virtual void textOut(int x0, int y0, const std::string &str, const mrpt::utils::TColor color)
Renders 2D text using bitmap fonts. 
 
void BASE_IMPEXP memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) MRPT_NO_THROWS
An OS and compiler independent version of "memcpy". 
 
bool is_aligned< 16 >(const void *ptr)
 
float getAsFloat(unsigned int col, unsigned int row, unsigned int channel) const
Returns the contents of a given pixel at the desired channel, in float format: [0,255]->[0,1] The coordinate origin is pixel(0,0)=top-left corner of the image. 
 
void equalizeHistInPlace()
Equalize the image histogram, replacing the original image. 
 
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei imageSize
 
float correlate(const CImage &img2int, int width_init=0, int height_init=0) const
Computes the correlation coefficient (returned as val), between two images This function use grayscal...
 
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL. 
 
TImageChannels getChannelCount() const
Returns the number of channels, typically 1 (GRAY) or 3 (RGB) 
 
static bool DISABLE_JPEG_COMPRESSION
By default, when storing images through the CSerializable interface, RGB images are JPEG-compressed t...
 
static int SERIALIZATION_JPEG_QUALITY
Unless DISABLE_JPEG_COMPRESSION=true, this sets the JPEG quality (range 1-100) of serialized RGB imag...
 
std::string m_externalFile
The file name of a external storage image. 
 
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
 
static bool loadTGA(const std::string &fileName, mrpt::utils::CImage &out_RGB, mrpt::utils::CImage &out_alpha)
Loads a TGA true-color RGBA image as two CImage objects, one for the RGB channels plus a separate gra...
 
CImage scaleDouble() const
Returns a new image scaled up to double its original size. 
 
The virtual base class which provides a unified interface for all persistent objects in MRPT...
 
bool m_imgIsReadOnly
Set to true only when using setFromIplImageReadOnly. 
 
A class for storing images as grayscale or RGB bitmaps. 
 
void drawCircle(int x, int y, int radius, const mrpt::utils::TColor &color=mrpt::utils::TColor(255, 255, 255), unsigned int width=1) MRPT_OVERRIDE
Draws a circle of a given radius. 
 
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files. 
 
void flipVertical(bool also_swapRB=false)
Flips the image vertically. 
 
GLenum GLenum GLenum GLenum GLenum scale
 
#define THROW_TYPED_EXCEPTION_FMT(exceptionClass, _FORMAT_STRING,...)
 
void rotateImage(double angle_radians, unsigned int center_x, unsigned int center_y, double scale=1.0)
Rotates the image by the given angle around the given center point, with an optional scale factor...
 
void image_SSSE3_bgr_to_gray_8u(const uint8_t *in, uint8_t *out, int w, int h)
Convert a RGB image (3cu8) into a GRAYSCALE (1c8u) image, using Y=77*R+150*G+29*B. 
 
void rectifyImageInPlace(const mrpt::utils::TCamera &cameraParams)
Rectify (un-distort) the image according to a certain camera matrix and vector of distortion coeffici...
 
void copyFastFrom(CImage &o)
Moves an image from another object, erasing the origin image in the process (this is much faster than...
 
#define THROW_EXCEPTION(msg)
 
void resize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Changes the size of the image, erasing previous contents (does NOT scale its current content...
 
void getAsMatrix(mrpt::math::CMatrixFloat &outMatrix, bool doResize=true, int x_min=0, int y_min=0, int x_max=-1, int y_max=-1) const
Returns the image as a matrix with pixel grayscale values in the range [0,1]. 
 
A pair (x,y) of pixel coordinates (integer resolution). 
 
void rectifyImage(CImage &out_img, const mrpt::utils::TCamera &cameraParams) const
Rectify (un-distort) the image according to some camera parameters, and returns an output un-distorte...
 
const char * getChannelsOrder() const
Returns a string of the form "BGR","RGB" or "GRAY" indicating the channels ordering. 
 
float getMaxAsFloat() const
Return the maximum pixel value of the image, as a float value in the range [0,1]. ...
 
void unload() const MRPT_NO_THROWS
For external storage image objects only, this method unloads the image from memory (or does nothing i...
 
void WriteBuffer(const void *Buffer, size_t Count)
Writes a block of bytes to the stream from Buffer. 
 
void filterMedian(CImage &out_img, int W=3) const
Filter the image with a Median filter with a window size WxW, returning the filtered image in out_img...
 
#define MRPT_NO_THROWS
C++11 noexcept: Used after member declarations. 
 
void flipHorizontal()
Flips the image horizontally. 
 
void colorImageInPlace()
Replaces this grayscale image with a RGB version of it. 
 
static TColor blue
Predefined colors. 
 
char BASE_IMPEXP * strcpy(char *dest, size_t destSize, const char *source) MRPT_NO_THROWS
An OS-independent version of strcpy. 
 
bool loadFromFile(const std::string &fileName, int isColor=-1)
Load image from a file, whose format is determined from the extension (internally uses OpenCV)...
 
int TImageChannels
For use in mrpt::utils::CImage. 
 
void normalize()
Optimize the brightness range of an image without using histogram Only for one channel images...
 
void loadFromIplImage(void *iplImage)
Reads the image from a OpenCV IplImage object (making a COPY). 
 
static std::string IMAGES_PATH_BASE
By default, ".". 
 
GLubyte GLubyte GLubyte GLubyte w
 
const T * getAs() const
Returns a pointer to a const T* containing the image - the idea is to call like "img.getAs<IplImage>()" so we can avoid here including OpenCV's headers. 
 
virtual ~CImage()
Destructor: 
 
CImage & operator=(const CImage &o)
Copy operator (if the image is externally stored, the writen image will be such as well)...
 
T square(const T x)
Inline function for the square of a number. 
 
void readFromStream(mrpt::utils::CStream &in, int version)
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
 
void image_SSE2_scale_half_smooth_1c8u(const uint8_t *in, uint8_t *out, int w, int h)
Average each 2x2 pixels into 1x1 pixel (arithmetic average) 
 
void cross_correlation_FFT(const CImage &in_img, math::CMatrixFloat &out_corr, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, float biasThisImg=0, float biasInImg=0) const
Computes the correlation matrix between this image and another one. 
 
void image_SSSE3_scale_half_3c8u(const uint8_t *in, uint8_t *out, int w, int h)
Subsample each 2x2 pixel block into 1x1 pixel, taking the first pixel & ignoring the other 3...
 
void getAsMatrixTiled(math::CMatrix &outMatrix) const
Returns the image as a matrix, where the image is "tiled" (repeated) the required number of times to ...
 
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
 
This base provides a set of functions for maths stuff. 
 
T round2up(T val)
Round up to the nearest power of two of a given number. 
 
void loadFromMemoryBuffer(unsigned int width, unsigned int height, bool color, unsigned char *rawpixels, bool swapRedBlue=false)
Reads the image from raw pixels buffer in memory. 
 
float KLT_response(const unsigned int x, const unsigned int y, const unsigned int half_window_size) const
Compute the KLT response at a given pixel (x,y) - Only for grayscale images (for efficiency it avoids...
 
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler. 
 
This CStream derived class allow using a memory buffer as a CStream. 
 
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations. 
 
void cross_correlation(const CImage &patch_img, size_t &u_max, size_t &v_max, double &max_val, int u_search_ini=-1, int v_search_ini=-1, int u_search_size=-1, int v_search_size=-1, CImage *out_corr_image=NULL) const
Computes the correlation between this image and another one, encapsulating the openCV function cvMatc...
 
void image_KLT_response_template(const uint8_t *in, const int widthStep, int x, int y, int32_t &_gxx, int32_t &_gyy, int32_t &_gxy)
 
IplImage * ipl_to_grayscale(const IplImage *img_src)
 
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const
Introduces a pure virtual method responsible for writing to a CStream. 
 
virtual void selectTextFont(const std::string &fontName)
Select the current font used when drawing text. 
 
CImage grayscale() const
Returns a grayscale version of the image, or itself if it is already a grayscale image. 
 
void scaleImage(unsigned int width, unsigned int height, TInterpolationMethod interp=IMG_INTERP_CUBIC)
Scales this image to a new size, interpolating as needed. 
 
void line(int x0, int y0, int x1, int y1, const mrpt::utils::TColor color, unsigned int width=1, TPenStyle penStyle=psSolid) MRPT_OVERRIDE
Draws a line. 
 
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf. 
 
void setChannelsOrder_RGB()
Marks the channel ordering in a color image as "RGB" (this doesn't actually modify the image data...
 
#define IMPLEMENTS_MEXPLUS_FROM(complete_type)
 
size_t getRowStride() const
Returns the row stride of the image: this is the number of bytes between two consecutive rows...
 
bool isExternallyStored() const MRPT_NO_THROWS
See setExternalStorage(). 
 
void saveToStreamAsJPEG(mrpt::utils::CStream &out, const int jpeg_quality=95) const
Save image to binary stream as a JPEG (.jpg) compressed format. 
 
void swapRB()
Swaps red and blue channels. 
 
void setFromIplImage(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy). 
 
void changeSize(unsigned int width, unsigned int height, TImageChannels nChannels, bool originTopLeft)
Resize the buffers in "img" to accomodate a new image size and/or format. 
 
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf. 
 
bool loadFromXPM(const char **xpm_array, bool swap_rb=true)
Loads the image from an XPM array, as #include'd from a ".xpm" file. 
 
void setFromIplImageReadOnly(void *iplImage)
Reads the image from a OpenCV IplImage object (WITHOUT making a copy) and from now on the image canno...
 
GLsizei const GLchar ** string
 
void swap(CImage &o)
Very efficient swap of two images (just swap the internal pointers) 
 
GLint GLint GLsizei GLsizei GLsizei GLint GLenum GLenum const GLvoid * pixels
 
mrpt::math::CMatrixDouble33 intrinsicParams
Matrix of intrinsic parameters (containing the focal length and principal point coordinates) ...
 
void BASE_IMPEXP idft2_complex(const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_real, CMatrixFloat &out_imag)
Compute the 2D inverse Discrete Fourier Transform (DFT). 
 
void image_SSE2_scale_half_1c8u(const uint8_t *in, uint8_t *out, int w, int h)
Subsample each 2x2 pixel block into 1x1 pixel, taking the first pixel & ignoring the other 3...
 
void copyFromForceLoad(const CImage &o)
Copies from another image, and, if that one is externally stored, the image file will be actually loa...
 
void * getRawBufferData()
Method for getting a pointer to the raw stored data. 
 
void filterMedianInPlace(int W=3)
Filter the image with a Median filter with a window size WxH, replacing "this" image by the filtered ...
 
TInterpolationMethod
Interpolation methods for images. 
 
void setChannelsOrder_BGR()
Marks the channel ordering in a color image as "BGR" (this doesn't actually modify the image data...
 
void makeSureImageIsLoaded() const
Checks if the image is of type "external storage", and if so and not loaded yet, load it...
 
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries. 
 
void update_patch(const CImage &patch, const unsigned int col, const unsigned int row)
Update a part of this image with the "patch" given as argument. 
 
void releaseIpl(bool thisIsExternalImgUnload=false) MRPT_NO_THROWS
Release the internal IPL image, if not NULL or read-only. 
 
unsigned char * operator()(unsigned int col, unsigned int row, unsigned int channel=0) const
Returns a pointer to a given pixel information. 
 
GLdouble GLdouble GLdouble r
 
CImage scaleHalfSmooth() const
Returns a new image scaled down to half its original size (averaging between every two rows) ...
 
mrpt::math::CArrayDouble< 5 > dist
[k1 k2 t1 t2 k3] -> k_i: parameters of radial distortion, t_i: parameters of tangential distortion (d...
 
virtual mxArray * writeToMatlab() const
Introduces a pure virtual method responsible for writing to a mxArray Matlab object, typically a MATLAB struct whose contents are documented in each derived class. 
 
CImage scaleHalf() const
Returns a new image scaled down to half its original size. 
 
void equalizeHist(CImage &outImg) const
Equalize the image histogram, saving the new image in the given output object. 
 
void filterGaussianInPlace(int W=3, int H=3)
Filter the image with a Gaussian filter with a window size WxH, returning the filtered image in out_i...
 
GLenum GLenum GLvoid * row
 
CImage()
Default constructor: initialize an 1x1 RGB image. 
 
void extract_patch(CImage &patch, const unsigned int col=0, const unsigned int row=0, const unsigned int width=1, const unsigned int height=1) const
Extract a patch from this image, saveing it into "patch" (its previous contents will be overwritten)...
 
bool drawChessboardCorners(std::vector< TPixelCoordf > &cornerCoords, unsigned int check_size_x, unsigned int check_size_y, unsigned int lines_width=1, unsigned int circles_radius=4)
Draw onto this image the detected corners of a chessboard. 
 
bool isOriginTopLeft() const
Returns true if the coordinates origin is top-left, or false if it is bottom-left. 
 
void changeSize(uint64_t newSize)
Change size. This would be rarely used. Use ">>" operators for writing to stream. ...
 
A versatile "profiler" that logs the time spent within each pair of calls to enter(X)-leave(X), among other stats. 
 
double leave(const char *func_name)
End of a named section. 
 
A matrix of dynamic size. 
 
uint64_t getTotalBytesCount() MRPT_OVERRIDE
Returns the total size of the internal buffer. 
 
int round(const T value)
Returns the closer integer (int) to x. 
 
bool saveToFile(const std::string &fileName, int jpeg_quality=95) const
Save the image to a file, whose format is determined from the extension (internally uses OpenCV)...
 
uint64_t Seek(int64_t Offset, CStream::TSeekOrigin Origin=sFromBeginning) MRPT_OVERRIDE
Introduces a pure virtual method for moving to a specified position in the streamed resource...
 
static bool DISABLE_ZIP_COMPRESSION
By default, when storing images through the CSerializable interface, grayscale images will be ZIP com...
 
bool m_imgIsExternalStorage
Set to true only when using setExternalStorage. 
 
bool isColor() const
Returns true if the image is RGB, false if it is grayscale. 
 
void colorImage(CImage &ret) const
Returns a RGB version of the grayscale image, or itself if it is already a RGB image. 
 
void BASE_IMPEXP compress(void *inData, size_t inDataSize, std::vector< unsigned char > &outData)
Compress an array of bytes into another one. 
 
unsigned char * get_unsafe(unsigned int col, unsigned int row, unsigned int channel=0) const
Access to pixels without checking boundaries - Use normally the () operator better, which checks the coordinates. 
 
void setExternalStorage(const std::string &fileName) MRPT_NO_THROWS
By using this method the image is marked as referenced to an external file, which will be loaded only...
 
void BASE_IMPEXP decompress(void *inData, size_t inDataSize, std::vector< unsigned char > &outData, size_t outDataEstimatedSize)
Decompress an array of bytes into another one. 
 
This class is a "CSerializable" wrapper for "CMatrixFloat". 
 
TPenStyle
Definition of pen styles. 
 
GLenum GLsizei GLsizei height
 
void BASE_IMPEXP dft2_complex(const CMatrixFloat &in_real, const CMatrixFloat &in_imag, CMatrixFloat &out_real, CMatrixFloat &out_imag)
Compute the 2D Discrete Fourier Transform (DFT) of a complex matrix, returning the real and imaginary...
 
void setOriginTopLeft(bool val)
Changes the property of the image stating if the top-left corner (vs. 
 
unsigned __int32 uint32_t
 
void enter(const char *func_name)
Start of a named section. 
 
#define ASSERTMSG_(f, __ERROR_MSG)
 
GLsizei GLsizei GLenum GLenum const GLvoid * data
 
Used in mrpt::utils::CImage. 
 
void * img
The internal IplImage pointer to the actual image content. 
 
size_t getWidth() const MRPT_OVERRIDE
Returns the width of the image in pixels. 
 
void getExternalStorageFileAbsolutePath(std::string &out_path) const
Only if isExternallyStored() returns true. 
 
void grayscaleInPlace()
Replaces the image with a grayscale version of it. 
 
void joinImagesHorz(const CImage &im1, const CImage &im2)
Joins two images side-by-side horizontally. 
 
void filterGaussian(CImage &out_img, int W=3, int H=3) const
Filter the image with a Gaussian filter with a window size WxH, replacing "this" image by the filtere...
 
TImageSize getSize() const
Return the size of the image. 
 
struct mxArray_tag mxArray
Forward declaration for mxArray (avoid #including as much as possible to speed up compiling) ...
 
void setPixel(int x, int y, size_t color) MRPT_OVERRIDE
Changes the value of the pixel (x,y). 
 
Structure to hold the parameters of a pinhole camera model. 
 
size_t getHeight() const MRPT_OVERRIDE
Returns the height of the image in pixels. 
 
void getAsRGBMatrices(mrpt::math::CMatrixFloat &outMatrixR, mrpt::math::CMatrixFloat &outMatrixG, mrpt::math::CMatrixFloat &outMatrixB, bool doResize=true, int x_min=0, int y_min=0, int x_max=-1, int y_max=-1) const
Returns the image as RGB matrices with pixel values in the range [0,1]. 
 
std::string getExternalStorageFileAbsolutePath() const
Only if isExternallyStored() returns true. 
 
void loadFromStreamAsJPEG(CStream &in)
Reads the image from a binary stream containing a binary jpeg file.