gen_structured_light_pattern — Generate the pattern images to be displayed in a structured light setup.
gen_structured_light_pattern generates the pattern images that need
to be displayed in a structured light setup. Several parameters such as the
width and height of the images, the pattern type and the minimal stripe width
need to be set in advance in the model
Dependent on the set parameters of the
number and the appearance of the pattern images vary.
In general, the pattern images can be divided into four groups of images:
Gray code images
Phase shift images
Single stripe images
Decoding of Gray code images relies upon being able to know whether a pixel
is in a region where a light stripe is reflected or where a dark stripe
is reflected. To allow a robust decoding even for large variations in the
surface reflectance, normalization images are used to simplify the process
of identifying light and dark regions.
The simplest but in most cases also sufficient approach is to generate one
entirely black and one entirely white image.
During the decoding of the acquired camera images
decode_structured_light_pattern) all Gray code images are then
compared with the mean of the dark and the bright image and a pixel within
the image is classified as bright if its gray value is greater or equal the
previously calculated mean.
Another approach is to use the Gray code images as explained in the next section and generate an inverted version of these images. A pixel is then classified as light, if its gray value in the first image is brighter than the gray value of the inverted version.
Gray code images:
Before performing any practical task such as detecting defects, the first step in any structured light measurement process is to find a mapping between the pixel plane of the camera and the pixel plane of the monitor. This can be achieved by displaying a series of images that uniquely encode the rows and columns of the monitor. Since Gray code images have some advantages compared to other pattern types, they are typically used for the encoding. An example of a series of vertical and horizontal Gray code images can be seen in the subsequent figure.
Although using Gray code images is a very simple, yet suitable approach, it comes with certain limitations. One drawback is that often many Gray code images are required to achieve a spatial resolution sufficient for practical applications. However, with increasingly finer resolution of the stripes, a correct decoding becomes harder and harder because of blurring effects introduced by the optics involved in the measurement process. To overcome these limitations, the third group of pattern images (phase shift images) can be generated.
Phase shift images:
Phase shift images usually use periodic patterns such as sine or cosine waves to reconstruct the phase and in combination with Gray code images the correspondences between the monitor and the camera coordinates. To allow a decoding that is robust despite variations in the surface reflectance and has a relaxed noise influence, four phase shift images per orientation (vertical or horizontal) are generated. Each image is a cosine wave with phase shifts of , where .
The main advantage of using phase shift images, is that in contrast to Gray code images subpixel-precise correspondences between the monitor and the camera coordinates can be calculated. Since the images are periodic, the encoding is unique up to integer multiples of the period length. In order to achieve a unique encoding over the entire image, the combination with the Gray code image is necessary.
Single stripe images:
Single stripe images are dark with one bright stripe. The bright stripe is shifted over the images such that each monitor pixel is contained in exactly one stripe. To decide which bright stripe is reflected in the area observed by a camera pixel, the brightest pixel value within the sequence of single stripe images is chosen during decoding. This allows a decoding that is robust despite variations in the surface reflectance.
The Gray code sequence and phase are then used to refine the position within the found single stripe. Thus, while additional single stripe images are generated, the number of created Gray code images will typically decrease slightly.
Generating the normalization images:
As mentioned above, HALCON offers two different kinds of normalization
images. By default, the 'normalization' method is set to
'global' which results in the generation of an entirely black
and an entirely white image.
To change the method such that each Gray code is additionally inverted,
set_structured_light_model_param has to be called using the
The main advantage of using a global normalization is that the number of images is significantly smaller while simultaneously providing satisfying results. Only in cases of partially specular surfaces, the other method might be more robust and should be chosen if the global normalization leads to wrong decoding results.
Generating the Gray code images:
The size, the number and the appearance of the Gray code images is
dependent on the following parameters
'min_stripe_width', and 'pattern_orientation'.
The first two parameters determine the size of the generated Gray code images and should usually be set to the size of the monitor that is used to display the pattern images. The parameter 'min_stripe_width' sets the width (in pixels) of the finest stripe of the pattern images that are generated. Additionally, all three parameters have a major influence on the number of created Gray code images.
Let be the maximum stripe width in vertical direction and be the maximum stripe width in horizontal direction. Then the number of Gray code images with stripes oriented in one of the two directions (either horizontal or vertical) is given by
The parameter 'pattern_orientation' sets the orientation of the
Gray code (and phase shift) images that are generated. By default, images
with vertical stripes as well as images with horizontal stripes are
created. It is also possible to generate images with stripes having only
one of the two directions. However, this is not recommended, because
changes in the surface can then only be detected in one direction.
Solely, if changes on the surface should be ignored or if defects are to be
expected in only one direction, this parameter should be changed using
Generating the phase shift images:
Since phase shift images are suitable to overcome the practical limitations of Gray code images their generation is recommended and enabled by default.
In case that the accuracy using Gray code images only is sufficient, the
creation of phase shift images can be deactivated using
set_structured_light_model_param by setting the
'pattern_type' to the value 'gray_code'.
Generating the single stripe images:
In case that using Gray code and phase shift images only is not robust
enough (this might happen, for example, on semi-specular surfaces), the
creation of single stripe images can be activated using
set_structured_light_model_param by setting the
'pattern_type' to the value 'single_stripe'.
The number and the appearance of the single stripe images depends on the
parameter 'single_stripe_width' which sets the width in pixels
While additional single stripe images are generated, the number of created Gray code images will typically decrease slightly. To calculate the number of Gray code images, 'max_stripe_width' is replaced by 'single_stripe_width' in the formula above.
The use of these images is described in the introduction to the chapter Inspection / Structured Light.
This operator modifies the state of the following input parameter:
During execution of this operator, access to the value of this parameter must be synchronized if it is used across multiple threads.
Generated pattern images.
StructuredLightModel(input_control, state is modified) structured_light_model
Handle of the structured light model.
* Create the model create_structured_light_model ('deflectometry', StructuredLightModel) * Set the size of the monitor set_structured_light_model_param (StructuredLightModel, \ 'pattern_width', 1600) set_structured_light_model_param (StructuredLightModel, \ 'pattern_height', 1200) * Set the smallest width of the stripes in the pattern set_structured_light_model_param (StructuredLightModel, \ 'min_stripe_width', 8) * Generate the patterns to project gen_structured_light_pattern (PatternImages, StructuredLightModel) * Decode the camera images decode_structured_light_pattern (CameraImages, StructuredLightModel)
gen_structured_light_pattern returns the
value TRUE if the given parameters are valid. Otherwise, an exception will be