Filters are an important part of nearly every machine vision application.
They can, for instance, be used to smooth images (e.g.,
),
extract sub-pixel precise edges (e.g., mean_image
) or
process the frequency domain of images (e.g., edges_sub_pix
).
fft_image
Usually, filter operations are applied using filter masks, which are moved across the input image pixelwise. For each pixel a new value is calculated based on its neighborhood. The neighborhood is determined by shape and size of the filter mask (see the scheme below).
(1) | (2) | (3) | (4) |
You can tell from the working principle of filter masks, the treatment of pixels along the image or domain border requires special attention, as part of the filter mask exceeds the domain. In the following sections some consequential issues will be discussed.
If a filter that is using a mask is applied on an image with a reduced domain, the result along the domain boundary might be surprising because gray values lying outside the boundary are used as input for the filter process (see scheme below).
(1) | (2) | (3) | (4) |
To understand this, the definition of domains in this context must be considered: For a filter, a domain defines for which input pixels output pixels must be calculated. But pixels outside the domain (which lie within the image matrix) might be used for processing nevertheless.
Another point to notice is the handling of pixels outside the input
image domain.
The parameter 'init_new_image'
of
determines
how those pixels are treated. If the pixels are initialized with 0,
consecutive runs will yield identical results. Otherwise, those pixels
remain undefined.
While this enhances the program runtime, undefined pixels can differ
from system to system, for example if parallelization is activated or not.
It is merely guaranteed that the values are consistent if the program is
executed repeatedly on systems with the same configuration.
In certain cases, these 'undefined' pixels might lead to problems.
Expanding the resulting image to the full domain with
set_system
will lead to artifacts appearing outside of
the former image domain.
full_domain
When two or more filters are applied consecutively on the same domain, the undefined or unexpected values (as described in the paragraphs above) have a higher impact on the result image. This is because with every following filter the error increases, starting from the border to the middle. In the following, four strategies for solving those problems are presented.
Errors caused by undefined pixels can easily be prevented by, e.g., choosing a dilated domain (see Morphology / Gray Values) according to the filter mask. If multiple filters are applied consecutively, the image domain can be dilated in advance, considering the filter sizes to be used. For instance, when using a cascade of rectangular filters of arbitrary dimensions, the width and length dimension of the dilation mask can be calculated considering the individual filter mask dimensions and the number of filter operations :
.
After the filters were applied, the image domain can be reduced to its
original size (e.g., with
).
reduce_domain
Another option is to set the domain exactly to the size of the
interesting part within the image and then calling the operator
before applying a filter. This operator copies the
pixels inside of the border to the outside of the border
and therefore avoids errors caused by pixels that are undefined outside of
the domain. Subsequently, the domain can again be reduced to its original
size. This process should be repeated for every following filter operation.
Note, however, that this option increases the runtime significantly.
expand_domain_gray
If runtime is not an issue, the operator
can be
called before applying the first filter to the image. That way, the whole
image is defined as domain and undefined pixels are avoided completely.
full_domain
Another possibility of getting an image without undefined pixels is by
calling the operator
before applying a filter.
The operator crop_domain
crops the image to the size of the
domain, which means that the domain then covers a complete smaller image.
Note, however, that for the cropped image the coordinate system has changed
in relation to the original image, which will influence all following
applications depending on the image coordinate system (e.g., calculating the
center of gravity).
crop_domain