HALCON从入门到入门-对比三种滤波方式

测试效果

Guided Filter,即引导滤波,是一种图像滤波技术,它通过一张引导图(可以是输入图像本身或其他图像)对目标图像进行滤波处理,使得最后的输出图像在保持大体上与输入图像相似的同时,纹理部分与引导图相似。

Bilateral_filter(双边滤波器)是一种非线性的滤波方法,它结合了图像的空间邻近度和像素值相似度进行折中处理,同时考虑空域信息和灰度相似性,以达到保边去噪的目的。

各向异性扩散(Anisotropic Diffusion)是一种图像处理技术,旨在减少图像噪声的同时保持图像的边缘和细节。这种技术利用偏微分方程(PDE)来描述图像的扩散过程,并通过迭代计算来逐步平滑图像。

测试代码

* This example program shows how to use anisotropic_diffusion to smooth an
* image while preserving or enhancing the edge information to different degrees.
* 
* Prepare visualization
dev_close_window ()
dev_open_window (0, 0, 512, 512, 'black', WindowHandle)
dev_set_part (0, 0, 511, 511)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_clear_window ()
Methods := ['\'guided_filter\'','\'bilateral_filter\'','\'anisotropic_diffusion\'']
Message := 'Compare different methods for'
Message[1] := 'edge-preserving smoothing:'
Message := [Message,' - ' + Methods]
dev_disp_text (Message, 'window', 12, 12, 'white', 'box', 'false')
dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
stop ()
* 
Loops := 5
Radius := 2
Amplitude := 15
SigmaSpatial := Radius
SigmaRange := Amplitude
Contrast := 3
Theta := 10
Iterations := 1
* 
ImageFiles := ['mreut','claudia']
read_image (Images, ImageFiles)
for Index := 1 to |ImageFiles| by 1
    select_obj (Images, Image, Index)
    get_image_size (Image, ImageWidth, ImageHeight)
    dev_resize_window_fit_size (0, 0, ImageWidth, ImageHeight, -1, -1)
    dev_display (Image)
    Message := 'Original image'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    * 
    * Perform guided filtering.
    * 
    * Execute once for caching to allow a more robust time measurement.
    guided_filter (Image, Image, ImageGuided, Radius, Amplitude)
    * Measure execution time
    count_seconds (S1)
    for L := 1 to Loops by 1
        guided_filter (Image, Image, ImageGuided, Radius, Amplitude)
    endfor
    count_seconds (S2)
    TimeGuided := S2 - S1
    dev_display (ImageGuided)
    Message := 'Guided filter'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    * 
    * Perform bilateral filtering.
    * 
    * Execute once for caching to allow a more robust time measurement.
    bilateral_filter (Image, Image, ImageBilateral, SigmaSpatial, SigmaRange, [], [])
    * Measure execution time
    count_seconds (S3)
    for L := 1 to Loops by 1
        bilateral_filter (Image, Image, ImageBilateral, SigmaSpatial, SigmaRange, [], [])
    endfor
    count_seconds (S4)
    TimeBilateral := S4 - S3
    dev_display (ImageBilateral)
    Message := 'Bilateral filter'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    * 
    * Perform the anisotropic diffusion using the parabolic edge detection function.
    * Note that this function still allows a slight diffusion (smoothing) across edges.
    * 
    * Execute once for caching to allow a more robust time measurement.
    anisotropic_diffusion (Image, ImagePeronaMalik, 'perona-malik', Contrast, Theta, Iterations)
    * Measure execution time
    count_seconds (S5)
    for L := 1 to Loops by 1
        anisotropic_diffusion (Image, ImagePeronaMalik, 'perona-malik', Contrast, Theta, Iterations)
    endfor
    count_seconds (S6)
    TimeAnisoDiff := S6 - S5
    dev_display (ImagePeronaMalik)
    Message := 'Perona-Malik anisotropic diffusion'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    * 
    * Display detail
    if (ImageFiles[Index - 1] == 'mreut')
        dev_set_part (111, 205, 181, 275)
    else
        dev_set_part (30, 80, 30 + 2 * 48, 80 + 2 * 37)
    endif
    dev_display (Image)
    Message := 'Original image: ' + ImageFiles[Index - 1]
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    stop ()
    dev_display (ImageGuided)
    Message := 'Guided filter'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    dev_display (ImageBilateral)
    Message := 'Bilateral filter'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    dev_display (ImagePeronaMalik)
    Message := 'Perona-Malik anisotropic diffusion'
    dev_disp_text (Message, 'window', 12, 12, 'black', [], [])
    dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
    stop ()
    * 
    * Compare execution times
    Time := [TimeGuided,TimeBilateral,TimeAnisoDiff] * 1000 / Loops
    * 
    tuple_sort_index (Time, Indices)
    Colors := ['green','yellow','red']
    TimeMax := Time[Indices[2]]
    * 
    Width := 0.9 * ImageWidth * Time / TimeMax
    Row := [50,150,250]
    Column := gen_tuple_const(3,12)
    gen_rectangle1 (Rectangle, Row, Column, Row + 50, Column + Width)
    * 
    dev_clear_window ()

    dev_set_part (0, 0, ImageHeight - 1, ImageWidth - 1)
    dev_disp_text ('Execution times (' + ImageFiles[Index - 1] + ')', 'window', 12, 12, 'black', [], [])
    dev_disp_text (Methods + ': ' + Time$'.1f' + ' ms', 'image', Row + 55, Column, 'white', 'box', 'false')
    dev_set_color (Colors[Indices])
    dev_display (Rectangle)
    if (Index < |ImageFiles|)
        dev_disp_text ('Press Run (F5) to continue', 'window', 'bottom', 'right', 'black', [], [])
        stop ()
    endif
endfor

### 回答1: Halcon双边滤波是一种图像处理技术,主要用于减少图像中的噪声和平滑图像,同时保留图像的边缘信息。该滤波器结合了空间域和灰度域两种信息在滤波过程中的权重。 首先,双边滤波器会计算每个像素的空间域权重和灰度域权重。空间域权重是根据像素距离计算的,距离越近的像素权重越高。灰度域权重是根据像素灰度值之间的差异计算的,差异越小的像素权重越高。 然后,双边滤波器会根据计算得到的权重对每个像素进行平滑处理。在平滑过程中,距离较近且灰度值相似的像素会对当前像素有更大的贡献,而距离较远或者灰度值差异较大的像素则会对当前像素有较小的影响。这样可以保留图像中的边缘信息,同时消除图像中的噪声。 双边滤波通常由两个参数控制:空间域标准差和灰度域标准差。空间域标准差影响滤波器对空间距离的敏感度,标准差越大,滤波器对距离的敏感度越小。灰度域标准差影响滤波器对灰度差异的敏感度,标准差越大,滤波器对灰度差异的敏感度越小。 总之,Halcon双边滤波是一种能够在平滑图像的同时保留边缘信息的图像处理技术。它通过计算像素的空间域权重和灰度域权重,并根据权重对像素进行平滑处理,从而达到减少噪声的效果。 ### 回答2: Halcon是一种用于机器视觉应用的软件库,具有强大的图像处理和分析功能。双边滤波Halcon中的一种图像滤波方法,用于降低图像噪声并保留边缘。 双边滤波是一种非线性滤波方法,其基本思想是根据像素与其周围像素之间的相似度来决定滤波器的权值。其中,相似度通过像素的空间距离和像素值之间的差异来度量。双边滤波器在模糊图像的同时保留图像细节信息,尤其是边缘信息,对于去除图像噪声和平滑纹理的同时保持图像的清晰度具有很好的效果。 在Halcon中,使用双边滤波器可以通过bilateral_filter函数实现。该函数有多个参数,包括输入图像、滤波器半径、空间标准差和像素差异标准差。滤波器半径定义了滤波器的大小,空间标准差用于控制像素之间的距离权重,像素差异标准差用于控制像素值之间的差异权重。 一般而言,选择合适的滤波器半径和标准差是使用双边滤波的关键。滤波器半径过大会导致图像过度模糊,而过小则无法有效去除噪声。标准差越大,图像的模糊效果越明显,但保留的细节信息也会减少。 使用Halcon中的双边滤波函数,可以对图像进行降噪和平滑处理,从而提高后续图像处理算法的准确度和稳定性。双边滤波器的独特性能使其成为Halcon中常用的图像处理方法之一。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

黄晓魚

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值