6.1.1   HAllReg

HAllReg (see figure 6.1) implements a loop over all iconic objects of the first input image parameter. For every object within this parameter, it returns the region of the iconic object (domain) in region20). All gray value channels are ignored.

HAllReg is a combination of HAllObj (see section “HAllObj”) and HGetFDRL (see section “HGetFDRL”). It is typically used within feature extraction operators: A list of input regions have to be examined concerning special features. Some HALCON operators of this kind are e.g., circularity, area_center, or contlength. Moreover, it is possible to return new region(s) by using the interface macro HNewRegion (see section “HNewRegion”) as it is done e.g., by erosion_rectangle1 or shape_trans.

    Herror CIPCenter(Hproc_handle  proc_handle)
    {
      Hcpar      *Row,*Col;
      INT4_8     num;
      double     row,col;
      INT4_8     area;
      INT4_8     i;
      Hrlregion  *region;
    
      /* allocate memory corresponding to the number of regions. */
      HGetObjNum(proc_handle,1,&num);
      HCkP(HAlloc(proc_handle,sizeof(*Row)*num,&Row);
      HCkP(HAlloc(proc_handle,sizeof(*Col)*num,&Col);
      /* get the regions of all input iconic objects in the first param.  */
      HAllReg(proc_handle,&region,i)
      {
        HCkP(HRLArea(proc_handle,region,&area,&row,&col));
        Row[i-1].type  = DOUBLE_PAR;       /* par. type is float   */
        Row[i-1].par.d = row;              /* resulting row        */
        Col[i-1].type  = DOUBLE_PAR;       /* par. type is float   */
        Col[i-1].par.d = col;              /* resulting column     */
      }
      HPutPPar(proc_handle,1,Row,i);       /* return result */
      HPutPPar(proc_handle,2,Col,i);       /* return result */
      return(H_MSG_TRUE);
    }

Figure 6.2: An application of HAllReg: Compute the center of gravity for all input regions in the first input iconic object parameter.

Figure 6.2 illustrates the application of HAllReg showing a complete supply procedure for a hypothetical operator center that computes the center of gravity of all input regions. The operator has one input iconic object parameter that exclusively contains regions and two output control parameters for returning the results as tuples of floating-point numbers (the coordinates of the centers of gravity of all regions). The corresponding def-file (short version) might look like this:

      center <- CIPCenter[Regions:::Rows$F,Columns$F];

center may be called with one or more regions as input. HAllReg implements a loop over all of them, sets the loop index i to the current index of the region (1 … n), and passes a pointer to the region to the action procedure that performs the center of gravity. In our case the action procedure is the internal HALCON procedure HRLArea. The result values are written into two arrays of the type Hcpar and returned by HPutCPar (see section “HPutCPar”).

20) Remember: HALCON image objects consist of one region specifying the domain (area of definition) and an arbitrary number of gray value channels containing the pixel data