Loop macros for accessing single input objects🔗
This section describes two macros that ease the access of all iconic objects and image components within an input iconic parameter, see Basic loop macros to access iconic objects.
More Info
See also the additional loop macros in Loop macros that further facilitate the programming of typical supply procedure.
Names
Synopsis
#include "Halcon.h"
HAllObj( Hproc_handle proc_handle,
int par_num,
Hkey &obj_key,
INT4_8 &index)
HAllComp(Hproc_handle proc_handle,
Hkey obj_key,
Hkey &image_in_key,
Himage &image_in,
INT4_8 &index)
& denotes output parameters of the macros.
This is only a special notation to make clear that these parameters are changed by the macros.
Hence, do not pass pointers to variables but the variables itself to the macro.
HAllObj🔗
HAllObj (see Basic loop macros to access iconic objects) performs a loop over all iconic objects of a specified input iconic parameter and returns their database key.
Hkey obj_key;
Hrlregion *region;
Himage image;
INT4_8 index;
...
HAllObj(proc_handle,1,obj_key,index) {
HGetFDRL(proc_handle,obj_key,®ion);
HGetDImage(proc_handle,obj_key,IMAGE_INDEX,&image);
}
Within the loop, all iconic objects contained in the input iconic parameter with the index par_num are accessed one by one.1
index is set to the index of the current iconic object to be processed and obj_key is set to the corresponding database key.
Thus, using HAllObj is equivalent to programming an explicit loop over all iconic objects contained in a parameter and determining the database keys via HGetObj, see also Example for HGetObj.
Application of HAllObj shows an application of HAllObj.
HAllComp🔗
HAllComp performs a loop over all gray value channels (components) of the image object denoted by the database key obj_key.
Within the loop, image_in_key is set to the database key of the current image object and the corresponding image data is delivered in image_in.
Using HAllComp is equivalent to programming an explicit loop over all channels of an image object using HGetDImage.
This also implies that the raw image data, i.e., the image matrix itself, is not copied.
Instead, only a pointer to this data is inserted in image_in.
So please restrict yourself to reading this data.
Any write access to the image matrix will cause unpredictable side effects.
Note that HAllComp does not check whether the image object contains at least one channel.
Note further, that any region processing should be performed outside the loop (otherwise you will process the same region again and again for each channel).
Hkey obj_in;
Hkey obj_out;
Hkey image_in_key;
INT4_8 comp_index;
Himage image_in,image_out;
...
HAllObj(proc_handle,1,obj_in,j) {
HCrObj(proc_handle,1,&obj_out);
HAllComp(proc_handle,obj_in,image_in_key,image_in,comp_index) {
HCkP(HCrImage(proc_handle,image_in_key,1,BYTE_IMAGE,
image_in.width,image_in.height,
&im_out_key,&image_out));
HCkP(IPBRot90(image_in.pixel.b,image_in.width,region_in,
image_out.pixel.b,width,height));
HDefObj(proc_handle,obj_out,im_out_key,comp_index);
}
}
Application of HAllComp shows an example of how to use HAllComp.
Within the HAllObj loop for each input image object, an output image object is created and added to the iconic object list of the first output iconic parameter (HCrObj).
After that, a loop over all gray value channels of the current image object is performed (HAllComp).
Within this loop, for every gray value channel a new image matrix is created (HCrImage) and filled with the rotated input matrix (IPBRot90).
Finally, this matrix is installed as a new gray value channel of the output image object (HDefObj).
The corresponding region transformation (rotating the region and defining the rotated region as new domain, i.e., area of definition, of the output image object via HDefObj) is omitted in this example.
-
So in contrast to the routines described in Loop macros,
HAllObjallows to specify the desired parameter by its index. ↩