5.6.3   HRLDecomp

HRLDecomp (see figure 5.39) is an auxiliary procedure to ease border treatment within the action procedures of filter operators based on filter masks. It's prototype is included in hlib\HRLClip.h.

    Herror IPBFilter(HBYTE      *in,            /* input image           */
                     Hrlregion  *region,        /* domain (area of def.) */
                     int        width,          /* image size: width     */
                     int        height,         /* image size: height    */
                     HBYTE      *out)           /* output image          */
    {
      ...
      Hrlregion *inner,*outer;

      HCkP(HAllocRLNumTmp(proc_handle,&inner,region->num));
      HCkP(HAllocRLNumTmp(proc_handle,&outer,region->num*2));
      HCkP(HRLDecomp(region,1,1,height-2,width-2,inner,outer));
      /* filtering without border treatment */
      for (i=0; i<inner->num; i++)
        for (k=CB(inner->rl,i,width); k<=CE(inner->rl,i,width); k++)
          out[k] = ...
      /* filtering with border treatment */
      for (i=0; i<outer->num; i++)
        for (k=CB(outer->rl,i,width); k<=CE(outer->rl,i,width); k++)
          out[k] = ...
      HCkP(HFreeRLTmp(proc_handle,outer));
      HCkP(HFreeRLTmp(proc_handle,inner));
    }

Figure 5.41: Border treatment for a 3 × 3 filter.

The region (respectively domain or area of definition) reg_in of the image to be processed is split into two parts: reg_inner and reg_outer. Note that both new regions must have been allocated before, see section “Temporary Data”.

reg_inner is the original region reg_in minus the pixels around the image border. It contains all pixels within the rectangle specified by the upper left corner18) (r1,c1) and the lower right corner (r2,c2). These coordinates should be selected that way, that the filter mask is completely within the image when placed on any pixel inside of the rectangle. Thus, no border treatment is necessary within reg_in.

reg_out is set to all remaining pixels within reg_in. For those pixels an appropriate (and time consuming) border treatment has to be performed. Figure 5.41 shows an application of HRLDecomp.

Note that HRLDecomp is no macro, i.e., it does not check the result state of the underlying procedure using HCkP. Thus, you must call HCkP on HRLDecomp yourself as shown in the example.

Note that the distinction of “inner” and “outer” area only refers to the image border, but not to the border of the regions specifying the domain (area of definition). So, it is only ensured that no memory access to positions outside the image matrix can happen, but there is no guarantee that all pixel values covered by the filter mask when placed on pixels within reg_inner are defined, if they do not belong to reg_in. This means, a filter might use undefined gray values along the border of the domain of the input images. The HALCON user should keep that in mind, when applying a sequence of filters to restricted regions of interest.

18) r1 and r2 denote row coordinates, c1 and c2 column coordinates.