HAllSegm (see figure 6.1) extends HAllReg: Not only the region but also all gray value channels of an object within the first input image object parameter are accessed within a loop. Thus, HAllSegm is a combination/modification of HAllObj (see section “HAllObj”), HGetFDRL (see section “HGetFDRL”), and HAllComp (see section “HAllComp”). It is especially useful for segmentation operators (transition of gray value channels to regions). Some typical HALCON operators that make use of HAllSegm are threshold, regiongrowing, auto_threshold, or label_to_region.
A HALCON image object (in short a HALCON image) consists of one region (domain) that specifies its area of definition and of one or more channels (gray value components) containing the pixel data. All channels of an image are of the same size, but may have different pixel types. The data contained in a channel (pixel type, the image matrix, etc.) is stored in a structure of type Himage (see section “Pixel Data (Himage)”). If the image has only one channel, the address of a variable of the type Himage is passed to HAllSegm. For multi-channel images an array of the type Himage[max_channels] must be passed. The maximal number of channels to be accessed by HAllSegm is specified by the parameter max_channels, see figure 6.3.
Himage images[3]; HAllSegm(proc_handle,region,images,3,i) { ... Himage image; HAllSegm(proc_handle,region,&image,1,i) { ...
Figure 6.3: The parameters image and max_channels of HAllSegm.
The parameter max_channels only specifies the maximum number of channels. If an image contains less channels, the corresponding Himage elements in the image array are undefined. The actual number of channels can be accessed e.g., using HNumOfChannels (see section “HNumOfChannels”). An image must contain at least one channel. Otherwise, HAllSegm returns an error. If the number of channels exceeds max_channels, the remaining channels are ignored. Furthermore, the size of all channels is checked for equality21).
Herror IPSegm(Hproc_handle proc_handle, /* HALCON proc. handle */ Hrlregion *region, /* domain (area of definition) */ Himage *image, /* input image */ Hrlregion *out) /* segmentation result */ { /* compute region "out" from "region" and "image" */ return(H_MSG_OK); } Herror CIPSegm(Hproc_handle proc_handle) { INT4_8 i; Hrlregion *region, *new_region; Himage image; HCkP(HAllocRLTmp(proc_handle,&new_region)); /* allocate memory*/ HAllSegm(proc_handle,®ion,&image,1,i) { /* all inp. images*/ HCkP(IPSegm(region,&image,new_region)); HNewRegion(proc_handle,new_region); /* allocate new */ } /* region */ HCkP(HFreeRLTmp(proc_handle,new_region)); /* free memory */ return(H_MSG_TRUE); }
Figure 6.4: A typical application of HAllSegm: A segmentation operator.
Figure 6.4 shows a framework for a supply procedure for a segmentation operator using HAllSegm. The corresponding hypothetical operator segm has one input object parameter for input images containing at least one channel. The def-file (short version) might look like
segm <- CIPSegm[Image:Region::];
The macro HAllSegm used in CIPSegm performs a loop over all image objects within the first input object parameter Image of segm. With every pass of the loop it returns the image data of the current input object in the variables region (domain) and image (first gray value channel). The results of the segmentation (new_region) are stored via the macro HNewRegion (see section “HNewRegion”) as new objects of the HALCON database and returned in the (first) output object parameter (Region). Note, that this simple operator has no control parameters.
A new region is allocated for the action procedure via HAllocRLTmp (see section “Temporary Data”) before entering the loop. This region is used as temporary memory for the computation result and must be deallocated (via HFreeRLTmp) before exiting the supply procedure.
| 21) Remember: The sizes must be equal, whereas
the pixel types of different channels may vary
|