Why Iplimage using char* pointing to raw image data instead of unsigned char* pointer just like Mat did?

asked 2015-12-07 08:15:56 -0600

Here's the data structure of Iplimage:

typedef struct _IplImage {
  int                  nSize;
  int                  ID;
  int                  nChannels;
  int                  alphaChannel;
  int                  depth;
  char                 colorModel[4];
  char                 channelSeq[4];
  int                  dataOrder;
  int                  origin;
  int                  align;
  int                  width;
  int                  height;
  struct _IplROI*      roi;
  struct _IplImage*    maskROI;
  void*                imageId;
  struct _IplTileInfo* tileInfo;
  int                  imageSize;
  char*                imageData;
  int                  widthStep;
  int                  BorderMode[4];
  int                  BorderConst[4];
  char*                imageDataOrigin;
} IplImage;

As I said, the pointer to imageData is a char*.

class CV_EXPORTS Mat
    // ... a lot of methods ...

    /*! includes several bit-fields:
         - the magic signature
         - continuity flag
         - depth
         - number of channels
    int flags;
    //! the array dimensionality, >= 2
    int dims;
    //! the number of rows and columns or (-1, -1) when the array has more than 2 dimensions
    int rows, cols;
    //! pointer to the data
    uchar* data;

    //! pointer to the reference counter;
    // when array points to user-allocated data, the pointer is NULL
    int* refcount;

    // other members

The pointer to data is uchar* which is unsigned char*.

Here rises a problem that we all know the elements of a color(gray, RGB which are commonly used while loading image) ranges from 0~255, which can be adequately expressed by 8 bits(unsigned char).

Why don't use uchar* in the Iplimage data structure, same as Mat did?

edit retag flag offensive close merge delete



Why are you taking about Mat structures in past, and about IplImage in present? IplImage is old deprecated...

LorenaGdL gravatar imageLorenaGdL ( 2015-12-07 12:35:31 -0600 )edit

because I knew Mat before I got to know Iplimage. I know that Iplimage is deprecated, what I want to know is that why is Iplimage defined like that, since the rang of the color hasn't changed over time.

GUODONG DING gravatar imageGUODONG DING ( 2015-12-08 00:03:22 -0600 )edit

Because it was ineffectively programmed, then someone in the past decided to do it more efficiently in the Mat structure. But in order to allow backwards compatibility, we cannot change the char pointer to a uchar pointer. Simple as that.

StevenPuttemans gravatar imageStevenPuttemans ( 2015-12-08 04:11:17 -0600 )edit