6.1.4   HAllFilter2

The macro HAllFilter2 (see figure 6.1) is a variation of HAllFilter introduced in the previous section. It facilitates the implementation of filters with two input object parameters. Examples for this technique are the HALCON operators add_image, mult_image, bit_and, and max_image.

HAllFilter2 extends HAllFiter so that with every image object of the first input object parameter also the corresponding image object (with the same object index obj_index) of the second input object parameter is provided. Moreover, it checks the image sizes of both image objects for equality. If the sizes are equal, the images are provided in the loop variables image_in1 and image_in2, otherwise an error is returned.

Moreover, HAllFilter2 computes a new input region (region) by intersecting the domains (areas of definition) of both input images. Note, that memory for this region must have been allocated before (e.g. with HAllocRLTmp). Furthermore, region must be deallocated at the end of the supply procedure (HFreeRLTmp).

Output image objects are created and returned in the first output object parameter in the same way as described for HAllFilter in section “HAllFilter”.

Figure 6.7 shows a typical application of HAllFilter2 – the implementation of an operator that adds the gray values of two input images. As in procedure IPScaleNew in figure 6.5, the macros HDFImage and HImageFD are used to read and write pixel values. This example exhibits the additional advantage that the operator can even add the gray values of two images with different pixel types.

    Herror IPAddNew(Hproc_handle  proc_handle,
                    Hrlregion     *region,
                    Himage        *image_in1,*image_in2,*image_out)
    {
      INT4_8 i,l,end;
      double h1,h2;
   
      for (i=0; i<region->num; i++) {
        end = CE(region->rl,i,image_in->width);
        for (l=CB(region->rl,i,image_in->width); l<=end; l++) {
          HDFImage(h1,image_in1,l);
          HDFImage(h2,image_in2,l);
          HImageFD(image_out,h1+h2,l);
      } } 
      return(H_MSG_OK);
    }
 
    Herror CIPAddNew(Hproc_handle  proc_handle)
    {
      Hrlregion    *region;
      Himage       image_in1,image_in2,image_out;
      INT4_8       i;

      HCkP(HAllocRLTmp(proc_handle,&region));
      HAllFilter2(proc_handle,region,&image_in1,
                  &image_in2,&image_out,1,i) {
        HCkP(IPAddNew(proc_handle,region,&image_in1,
                      &image_in2,&image_out));
      }
      HCkP(HFreeRLTmp(proc_handle,region));
      return(H_MSG_TRUE);
    }

Figure 6.7: A typical application of HAllFilter2.