图像过滤器应用reduce domain图像的问题
过滤器几乎是每个机器视觉应用程序的重要组成部分。例如,mean_image可用于平滑图像, edges_sub_pix提取子像素的精确边缘以及fft_image 计算图像的快速傅立叶变换。
在下面的内容中,我们将仔细研究特殊情况:将具有reduce domain的图像用作滤镜的输入,以及由图像域外部的灰度值引起的问题。
图像滤镜,蒙版和reduced domain缩小域
如果将使用蒙版的滤镜应用于reduced domain的图像,则沿域边界的结果可能会令人吃惊,因为位于边界外部的灰度值用作滤波过程的输入。要理解这一点,您必须在以下情况下考虑域的定义:对于过滤器,域定义了必须为哪些输入像素计算输出像素。但是可以将域外的像素(位于图像矩阵内)用于处理。
由Image域外部的灰度值引起的问题
将图像作为输出的运算符(大多数过滤器运算符)仅返回输入域中包含的像素的结果。
出于性能原因,位于图像域之外的像素将变为“未定义”。这些未定义的像素可能因系统而异,例如,是否激活并行化。如果在具有相同配置的系统上重复执行该程序,则仅保证值是一致的。在某些情况下,这些“未定义”像素可能会导致问题。使用命令full_domain将生成的图像扩展到整个域会导致伪像出现在先前的图像域之外。
导致问题的另一个原因是,如果连续应用两个或多个过滤器,则域外的未定义值也会被应用,因为这些过滤器也会将未定义值视为靠近域边界。这意味着从后面到中间,每个后续过滤器的误差都会增加。
在下文中,提出了解决这些问题的四种策略。
image.png
应用两个连续的过滤器后,在域边界的伪影。
例如,通过选择一个比实际需要的图像部分大很多的域,可以轻松地防止由未定义像素引起的错误。过滤器应用后,可以将图像域缩小到其原始大小(例如,使用erosion_rectangle1和reduce_domain)。这样做会切除图像中包含不正确值的那些部分,因此不会增加下一个滤镜操作的误差。
另一个选择是将域完全设置为图像中感兴趣部分的大小,然后在应用滤镜之前调用运算符expand_domain_gray 。此运算符将边界内的像素复制到边界外,因此避免了由域外未定义的像素引起的错误。随后,可以再次将域减小到其原始大小。接下来的每个过滤器操作都应重复此过程。但是请注意,此选项会大大增加运行时间。
image.png
看起来 expand_domain_gray的结果就像边界被多次复制并在外部添加一样。
-
如果运行时不是问题,则可以在将第一个过滤器应用于图像之前调用full_domain运算符。这样,整个图像被定义为域,并且完全避免了未定义的像素。
-
获得没有未定义像素的图像的另一种可能性是通过在应用滤镜之前调用crop_domaincrop_domain运算符。操作员将图像裁剪为域的大小,这意味着域将覆盖完整的较小图像。但是请注意,对于裁剪后的图像,坐标系相对于原始图像已更改,这将影响所有后续应用程序,具体取决于图像坐标系(例如,计算重心)。
halcon的常见过滤器(按功能分类)
(一)Arithmetic (算术)
abs_diff_image
Calculate the absolute difference of two images.
abs_image
Calculate the absolute value (modulus) of an image.
acos_image
Calculate the arccosine of an image.
add_image
Add two images.
asin_image
Calculate the arcsine of an image.
atan2_image
Calculate the arctangent of two images.
atan_image
Calculate the arctangent of an image.
cos_image
Calculate the cosine of an image.
div_image
Divide two images.
exp_image
Calculate the exponentiation of an image.
gamma_image
Perform a gamma encoding or decoding of an image.
invert_image
Invert an image.
log_image
Calculate the logarithm of an image.
max_image
Calculate the maximum of two images pixel by pixel.
min_image
Calculate the minimum of two images pixel by pixel.
mult_image
Multiply two images.
pow_image
Raise an image to a power.
scale_image
Scale the gray values of an image.
sin_image
Calculate the sine of an image.
sqrt_image
Calculate the square root of an image.
sub_image
Subtract two images.
tan_image
Calculate the tangent of an image.
(二)Bit (位)
bit_and
Bit-by-bit AND of all pixels of the input images.
bit_lshift
Left shift of all pixels of the image.
bit_mask
Logical “AND” of each pixel using a bit mask.
bit_not
Complement all bits of the pixels.
bit_or
Bit-by-bit OR of all pixels of the input images.
bit_rshift
Right shift of all pixels of the image.
bit_slice
Extract a bit from the pixels.
bit_xor
Bit-by-bit XOR of all pixels of the input images.
(三)Color (颜色)
apply_color_trans_lut
Color space transformation using pre-generated look-up-table.
cfa_to_rgb
Convert a single-channel color filter array image into an RGB image.
clear_color_trans_lut
Release the look-up-table needed for color space transformation.
create_color_trans_lut
Creates the look-up-table for transformation of an image from the RGB color space to an arbitrary color space.
gen_principal_comp_trans
Compute the transformation matrix of the principal component analysis of multichannel images.
linear_trans_color
Compute an affine transformation of the color values of a multichannel image.
principal_comp
Compute the principal components of multichannel images.
rgb1_to_gray
Transform an RGB image into a gray scale image.
rgb3_to_gray
Transform an RGB image to a gray scale image.
trans_from_rgb
Transform an image from the RGB color space to an arbitrary color space.
trans_to_rgb
Transform an image from an arbitrary color space to the RGB color space.
(四)Edges (边缘)
close_edges
Close edge gaps using the edge amplitude image.
close_edges_length
Close edge gaps using the edge amplitude image.
derivate_gauss
Convolve an image with derivatives of the Gaussian.
diff_of_gauss
Approximate the LoG operator (Laplace of Gaussian).
edges_color
Extract color edges using Canny, Deriche, or Shen filters.
edges_color_sub_pix
Extract subpixel precise color edges using Deriche, Shen, or Canny filters.
edges_image
Extract edges using Deriche, Lanser, Shen, or Canny filters.
edges_sub_pix
Extract sub-pixel precise edges using Deriche, Lanser, Shen, or Canny filters.
frei_amp
Detect edges (amplitude) using the Frei-Chen operator.
frei_dir
Detect edges (amplitude and direction) using the Frei-Chen operator.
highpass_image
Extract high frequency components from an image.
info_edges
Return the filter coefficients of a filter in edges_image.
kirsch_amp
Detect edges (amplitude) using the Kirsch operator.
kirsch_dir
Detect edges (amplitude and direction) using the Kirsch operator.
laplace
Calculate the Laplace operator by using finite differences.
laplace_of_gauss
LoG-Operator (Laplace of Gaussian).
prewitt_amp
Detect edges (amplitude) using the Prewitt operator.
prewitt_dir
Detect edges (amplitude and direction) using the Prewitt operator.
roberts
Detect edges using the Roberts filter.
robinson_amp
Detect edges (amplitude) using the Robinson operator.
robinson_dir
Detect edges (amplitude and direction) using the Robinson operator.
sobel_amp
Detect edges (amplitude) using the Sobel operator.
sobel_dir
Detect edges (amplitude and direction) using the Sobel operator.
(五)Enhancement (增强功能)
coherence_enhancing_diff
Perform a coherence enhancing diffusion of an image.
emphasize
Enhance contrast of the image.
equ_histo_image
Histogram linearization of images
illuminate
Illuminate image.
mean_curvature_flow
Apply the mean curvature flow to an image.
scale_image_max
Maximum gray value spreading in the value range 0 to 255.
shock_filter
Apply a shock filter to an image.
(六)FFT (快速傅立叶变换)
convol_fft
Convolve an image with a filter in the frequency domain.
convol_gabor
Convolve an image with a Gabor filter in the frequency domain.
correlation_fft
Compute the correlation of two images in the frequency domain.
deserialize_fft_optimization_data
Deserialize FFT speed optimization data.
energy_gabor
Calculate the energy of a two-channel image.
fft_generic
Compute the fast Fourier transform of an image.
fft_image
Compute the fast Fourier transform of an image.
fft_image_inv
Compute the inverse fast Fourier transform of an image.
gen_bandfilter
Generate an ideal band filter.
gen_bandpass
Generate an ideal bandpass filter.
gen_derivative_filter
Generate a derivative filter in the frequency domain.
gen_filter_mask
Store a filter mask in the spatial domain as a real-image.
gen_gabor
Generate a Gabor filter.
gen_gauss_filter
Generate a Gaussian filter in the frequency domain.
gen_highpass
Generate an ideal highpass filter.
gen_lowpass
Generate an ideal lowpass filter.
gen_mean_filter
Generate a mean filter in the frequency domain.
gen_sin_bandpass
Generate a bandpass filter with sinusoidal shape.
gen_std_bandpass
Generate a bandpass filter with Gaussian or sinusoidal shape.
optimize_fft_speed
Optimize the runtime of the FFT.
optimize_rft_speed
Optimize the runtime of the real-valued FFT.
phase_correlation_fft
Compute the phase correlation of two images in the frequency domain.
phase_deg
Return the phase of a complex image in degrees.
phase_rad
Return the phase of a complex image in radians.
power_byte
Return the power spectrum of a complex image.
power_ln
Return the power spectrum of a complex image.
power_real
Return the power spectrum of a complex image.
read_fft_optimization_data
Load FFT speed optimization data from a file.
rft_generic
Compute the real-valued fast Fourier transform of an image.
serialize_fft_optimization_data
Serialize FFT speed optimization data.
write_fft_optimization_data
Store FFT speed optimization data in a file.
(七)Geometric Transformations (几何变换)
affine_trans_image
对图像应用任意仿射二维变换.
affine_trans_image_size
对图像应用任意仿射二维变换并指定输出图像大小.
convert_map_type
将图像贴图转换为其他贴图类型.
map_image
Apply a general transformation to an image.
mirror_image
Mirror an image.
polar_trans_image_ext
Transform an annular arc in an image to polar coordinates.
polar_trans_image_inv
Transform an image in polar coordinates back to cartesian coordinates
projective_trans_image
Apply a projective transformation to an image.
projective_trans_image_size
Apply a projective transformation to an image and specify the output image size.
rotate_image
Rotate an image about its center.
zoom_image_factor
Zoom an image by a given factor.
zoom_image_size
Zoom an image to a given size.
(八)Inpainting (修补)
harmonic_interpolation
Perform a harmonic interpolation on an image region.
inpainting_aniso
Perform an inpainting by anisotropic diffusion.
inpainting_ced
Perform an inpainting by coherence enhancing diffusion.
inpainting_ct
Perform an inpainting by coherence transport.
inpainting_mcf
Perform an inpainting by smoothing of level lines.
inpainting_texture
Perform an inpainting by texture propagation.
(九)Lines (线)
bandpass_image
Edge extraction using bandpass filters.
lines_color
Detect color lines and their width.
lines_facet
Detection of lines using the facet model.
lines_gauss
Detect lines and their width.
(十)Match (匹配)
exhaustive_match
Matching of a template and an image.
exhaustive_match_mg
Matching a template and an image in a resolution pyramid.
gen_gauss_pyramid
Calculating a Gauss pyramid.
monotony
Calculating the monotony operation.
(十一)Misc (杂项)
convol_image
Calculate the correlation between an image and an arbitrary filter mask
deviation_n
Calculate standard deviation over several channels.
expand_domain_gray
Expand the domain of an image and set the gray values in the expanded domain.
gray_inside
Calculate the lowest possible gray value on an arbitrary path to the image border for each point in the image.
gray_skeleton
Thinning of gray value images.
lut_trans
Transform an image with a gray-value look-up-table
symmetry
Symmetry of gray values along a row.
topographic_sketch
Compute the topographic primal sketch of an image.
(十二)Noise (噪声)
add_noise_distribution
Add noise to an image.
add_noise_white
Add noise to an image.
gauss_distribution
Generate a Gaussian noise distribution.
noise_distribution_mean
Determine the noise distribution of an image.
sp_distribution
Generate a salt-and-pepper noise distribution.
(十三)Optical Flow (光流)
derivate_vector_field
Convolve a vector field with derivatives of the Gaussian.
optical_flow_mg
Compute the optical flow between two images.
unwarp_image_vector_field
Unwarp an image using a vector field.
vector_field_length
Compute the length of the vectors of a vector field.
(十四)Points (点)
corner_response
Searching corners in images.
dots_image
Enhance circular dots in an image.
points_foerstner
Detect points of interest using the Förstner operator.
points_harris
Detect points of interest using the Harris operator.
points_harris_binomial
Detect points of interest using the binomial approximation of the Harris operator.
points_lepetit
Detect points of interest using the Lepetit operator.
points_sojka
Find corners using the Sojka operator.
(十五)Scene Flow (场景流)
scene_flow_calib
Compute the calibrated scene flow between two stereo image pairs.
scene_flow_uncalib
Compute the uncalibrated scene flow between two stereo image pairs.
(十六)Smoothing (平滑处理)
图像平滑介绍
anisotropic_diffusion
Perform an anisotropic diffusion of an image.
bilateral_filter
bilateral filtering of an image.
binomial_filter
Smooth an image using the binomial filter.
eliminate_min_max
Smooth an image in the spatial domain to suppress noise.
eliminate_sp
Replace values outside of thresholds with average value.
fill_interlace
Interpolate 2 video half images.
gauss_filter
Smooth using discrete gauss functions.
guided_filter
Guided filtering of an image.
info_smooth
Information on smoothing filter smooth_image.
isotropic_diffusion
Perform an isotropic diffusion of an image.
mean_image
Smooth by averaging.
mean_n
Average gray values over several channels.
mean_sp
Suppress salt and pepper noise.
median_image
Compute a median filter with various masks.
median_rect
Compute a median filter with rectangular masks.
median_separate
Separated median filtering with rectangle masks.
median_weighted
Weighted median filtering with different rank masks.
midrange_image
Calculate the average of maximum and minimum inside any mask.
rank_image
Compute a rank filter with arbitrary masks.
rank_n
Return gray values with given rank from multiple channels.
rank_rect
Compute a rank filter with rectangular masks.
sigma_image
Non-linear smoothing with the sigma filter.
smooth_image
Smooth an image using various filters.
trimmed_mean
Smooth an image with an arbitrary rank mask.
(十七)Texture Inspection (纹理检查)
deviation_image
Calculate the standard deviation of gray values within rectangular windows.
entropy_image
Calculate the entropy of gray values within a rectangular window.
texture_laws
Filter an image using a Laws texture filter.
(十八)Wiener Filter (维纳过滤器)
gen_psf_defocus
Generate an impulse response of an uniform out-of-focus blurring.
gen_psf_motion
Generate an impulse response of a (linearly) motion blurring.
simulate_defocus
Simulate an uniform out-of-focus blurring of an image.
simulate_motion
Simulation of (linearly) motion blur.
wiener_filter
Image restoration by Wiener filtering.
wiener_filter_ni
Image restoration by Wiener filtering.