4.1   Pixel Data (Himage)

Gray value images are represented by a rectangular image matrix. Several matrices (called channels) can be combined to a multi-channel image. Each channel can be accessed separately, i.e. the channels are not interleaved. The structure Himage contains size, pixel type, and pixel data of one channel. Furthermore, a time-stamp is included. Figure 4.1 shows the corresponding type declaration.


typedef union {
  uint8_t*       b;         /* 0..255 (BYTE_IMAGE)                          */
  uint8_t*       z;         /* 0..255 mod 256 (CYCLIC_IMAGE)                */
  uint8_t*       d;         /* orientation 0..180 (DIR_IMAGE)               */
  int8_t*        i;         /* -128..127 (INT1_IMAGE)                       */
  int32_t*       l;         /* 4 byte integer (LONG_IMAGE)                  */
  int64_t*       i8;        /* 8 byte integer (INT8_IMAGE)                  */
  float*         f;         /* 4 byte real (FLOAT_IMAGE)                    */
  HVFPixel*      vf;        /* vector field (VF_IMAGE)                      */
  HComplexPixel* c;         /* complex image (COMPLEX_IMAGE)                */
  HInt2Pixel     s;         /* 2 bytes with sign (INT2_IMAGE)               */
  HUInt2Pixel    u;         /* 2 bytes without sign (UINT2_IMAGE)           */
} HPixelImage;

typedef struct {
  int         kind;         /* pixel type                                   */
  HPixelImage pixel;        /* pixel data                                   */
  HIMGDIM     width;        /* image width                                  */
  HIMGDIM     height;       /* image height                                 */
  HImageFreeProc free_proc; /* function for deallocating image data         */
  bool        free;         /* free image data when deleting image          */
  /* time of creation of image                                              */
  uint16_t    msec;         /* milliseconds 0..999                          */
  uint8_t     sec;          /* seconds 0..59                                */
  uint8_t     min;          /* minutes 0.59                                 */
  uint8_t     hour;         /* 0..23                                        */
  uint8_t     day;          /* 1..31                                        */
  uint16_t    yday;         /* 1..366                                       */
  uint8_t     mon;          /* 1..12                                        */
  uint16_t    year;         /* 19xx                                         */
} Himage;

Figure 4.1: Data type Himage for images.

The maximum for width and height, which describe the image size, is determined with MAX_FORMAT (HALCON: 32 768, HALCON XL: 1 073 741 824). The origin of an image matrix is at position (0, 0). Row coordinates range from 0 to height - 1, column coordinates from 0 to width - 1. The image pointer (HPixelImage) refers to the first pixel of the matrix (index: 0,0). Different pixel types are supported. They are distinguished by a selector (kind), see figure 4.2. The pixel types include basic types like uint8_t, int8_t, int32_t, and float as well as composed types. Their definitions can be seen in figure 4.3.

  #define BYTE_IMAGE    (int)1     /* 1 byte per pixel (0..255)      */
  #define INT4_IMAGE    (int)2     /* Type: 4 bytes per pixel (int32_t) */
  #define LONG_IMAGE    (int)2     /* 4 byte per pixel (int32_t)        */
  #define FLOAT_IMAGE   (int)4     /* 4 byte per pixel (float)       */
  #define DIR_IMAGE     (int)8     /* edge orientation 0..180        */
  #define CYCLIC_IMAGE  (int)16    /* 0..255 cyclic                  */
  #define INT1_IMAGE    (int)32    /* -128..127                      */
  #define COMPLEX_IMAGE (int)128   /* 2 float images                 */
  #define INT2_IMAGE    (int)512   /* 2 bytes with sign              */
  #define UINT2_IMAGE   (int)1024  /* Type: 2 bytes (unsigned short) */
  #define VF_IMAGE      (int)2048  /* Two float images               */
  #define INT8_IMAGE    (int)4096  /* 8 byte per pixel (int64_t)       */

Figure 4.2: Definitions of pixel types.

  typedef struct {
    float re;                /* real image part        */
    float im;                /* imaginary image part   */
  } HComplexPixel;

  typedef struct {
    int16_t* p;              /* gray values            */
    int8_t   num_bits;       /* number of used bits    */
  } HInt2Pixel;

  typedef struct {
    uint16_t* p;             /* gray values            */
    int8_t    num_bits;      /* number of used bits    */
  } HUInt2Pixel;

  typedef struct {
    float* row;              /* row direction          */
    float* col;              /* column direction       */
  } HVFPixel;

Figure 4.3: Data types for Himage.

The pixel data is stored as a one-dimensional array (image vector) of one of the pixel types. The indices of the array range from 0 to width*height-1. A linear coordinate L within an image is derived from the row index R and column index C as follows:

         L = R * image.width + C

This transformation is performed by the following macro HLinCoor:

         L = HLinCoor(R,C,image.width);

There are two additional macros for computing rows (HRow) and columns (HCol):

         R = HRow(L,image.width);
         C = HCol(L,image.width);

Please see section “Permanent Data” for routines to allocate image data within Himage.