6.1.3   HAllFilter

HAllFilter (see figure 6.1) further extends the loop macros introduced so far: For every input image object a new output image object is created (and added to the first output object parameter) with

Thus, HAllFilter is a combination/modification of HAllObj (see section “HAllObj”), HGetFDRL (see section “HGetFDRL”), HAllComp (see section “HAllComp”), HCopyObj (see section “HCopyObj”), and HPutDImage (see section “HPutDImage”). It has been designed for filter operators that typically create a modified result image for every input image. The region remains unmodified. Typical examples for this functionality are the HALCON operators sobel_amp, mean_image, scale_image_max, or texture_laws.

    Herror IPScaleNew(Hrlregion         *region,
                      Himage            *image_in,
                      Himage            *image_out,
    {
      INT4_8 i,l,end;
      double h;
   
      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(h,image_in,l);
          HImageFD(image_out,h*mult,l);
      } } 
      return(H_MSG_OK);
    }
 
    Herror CIPScaleNew(Hproc_handle proc_handle)
    {
      Hcpar        mult;
      Hrlregion    *region;
      Himage       image_in,image_out;
      INT4_8       i;
   
      HGetSPar(proc_handle,1,DOUBLE_PAR,&mult,1);
      HAllFilter(proc_handle,&region,&image_in,&image_out,1,i) {
        HCkP(IPScaleNew(region,&image_in,mult.par.f,&image_out));
      }
      return(H_MSG_TRUE);
    }

Figure 6.5: A typical application of HAllFilter: A filter operator.

Figure 6.5 shows a typical application of HAllFilter – a hypothetical operator scale_new that multiplies all gray values of the input objects within the first input object parameter with a constant. The corresponding def-file (short version) might look like

      scale_new <- CIPScaleNew[Image:ImageScaled:Mult$f:];

The operator has one input object parameter (Image) that contains one or more input image objects (each consisting of one or more gray value channels and one region as domain, i.e., area of definition). With every pass of the loop an image object is accessed and its components are transferred to region and image_in, see also HAllSegm in section “HAllSegm”. These components are passed to the action procedure IPScaleNew. In this example only the first channel of each input object is used.

HAllFilter also creates output objects (in the HALCON database) to return the modified data. Furthermore, these objects are added to the list of objects for the first output object parameter (here ImageScaled). Their underlying image matrices are accessible via image_out. Those are also passed to the action procedure IPScaleNew within the loop. IPScaleNew calculates the new gray values for all pixels within the domain of the input image and writes them into the provided image components image_out22). The regions of the image objects remain unmodified so that all pixels of output objects lying outside the region are undefined.

Note, that HAllFilter creates all necessary image matrices, combines them with the input regions to new image objects, and returns those in the first output object parameter. So the programmer of the supply procedure needs not to bother about the handling of image objects etc. To access the input control parameter, HGetSPar (see section “HGetSPar”) is used in the example.

The structure image_in may contain different pixel types. There are several ways to handle this within an operator:

  1. The simplest method is to implement the operator just for the most common pixel type BYTE_IMAGE and return an error message (H_ERR_WIT) for any other pixel type.
  2. Another way is to provide several action procedures – one for every pixel type – and call the appropriate procedure via switch(image_in.kind).
  3. The third (generic) method makes use of the macros HDFImage and HImageFD, see figure 6.6. They encapsulate the access to gray values by buffering them in a double variable. By writing pixel values via HImageFD, the double value val is converted into the current pixel type of image_in (and therefore may be clipped) and stored in the pixel specified by the linear coordinate lin_coord, see section “Pixel Data (Himage)”. The other way around, the specified pixel value is converted to double and returned in val when using HDFImage to read image data.

The third method has been used in our example, as it allows a very compact source code. But this variant naturally shows drawbacks in terms of computation time: Two type conversions have to be computed with every pixel access and all pixel arithmetic has to be done in double.

Names

    HDFImage, HImageFD

Synopsis

    #include "Halcon.h"
 
    HDFImage( double          &val,
              Himage          *image,
              INT4_8          lin_coord)
   
    HImageFD( Himage          *image,
              double          val,
              INT4_8          lin_coord)

Figure 6.6: Auxiliary macros for generic access to pixel data. “&” denotes an output parameter of HDFImage. This is only a special notation to make clear that this parameter is changed by the macro. So do not pass a pointer to double but the double variable itself to the macro.

22) Note, that image_out contains a pointer to a pixel matrix with the same size and pixel type as image_in.