• halcon 分水领域法详解(转载)


    寻思自己写了的,但是这个大佬写的太好了,感谢Y忍冬草_ http://blog.csdn.net/y363703390 https://blog.csdn.net/y363703390/article/details/81806378

    1.算子

    通过阈值实现图像的分水岭算法分割
    watersheds_threshold(Image : Basins : Threshold : )

    2.原理

    第1步:
    通过分水岭算法watersheds()获取图像的盆地。

    第2步:
    根据第一步分水岭算法分离结果,若盆地部分的灰度**< threshold**,则被合并到一起。设B1和B2分别为相邻盆地的最小灰度值,W为将盆地分割为两个盆地的最小灰度值。则分割结果为:

    3.案例

    1)边缘振幅+分水岭阈值实现图像分割

    dev_set_draw ('fill')
    dev_set_line_width (2)
    dev_set_colored (12)
    read_image (ImageLogo, 'mvtec_logo.png')
    dev_close_window ()
    get_image_size (ImageLogo, Width, Height)
    dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
    dev_display (ImageLogo)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    gauss_filter (ImageLogo, ImageGauss, 9)
    sobel_amp (ImageGauss, EdgeAmplitude, 'sum_abs', 3)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    watersheds_threshold (EdgeAmplitude, Basins, 14)
    dev_display (Basins)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    return ()
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    其他算子:

    gauss_filter(Image : ImageGauss : Size : )高斯平滑滤波
    sobel_amp(Image : EdgeAmplitude : FilterType, Size : )sobel计算图像边缘幅度
    2)距离变换+watersheds_threshold等实现分割

    * In this example, the task is to split the touching pellets.
    * First, a simple thresholding operation yields the region of the pellets
    * in the image. Unfortunately, some of the connected components
    * of this region do not represent single pellets but contain more than one
    * pellet. Therefore, in a second step the watersheds are computed based
    * on the distance transformed pellets regions. The corresponding basins
    * are finally used to split the falsely connected pellets by intersecting the
    * basins with the pellets regions.
    *
    dev_set_draw ('margin')
    dev_set_colored (12)
    read_image (Image, 'pellets')
    dev_close_window ()
    get_image_size (Image, Width, Height)
    dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
    threshold (Image, Region, 105, 255)
    * 计算连通域
    connection (Region, ConnectedRegions)
    select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 20, 99999)
    dev_display (Image)
    dev_display (SelectedRegions)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * 距离变换
    distance_transform (SelectedRegions, DistanceImage, 'octagonal', 'true', 380, 350)
    convert_image_type (DistanceImage, DistanceImageByte, 'byte')
    invert_image (DistanceImageByte, DistanceImageInv)
    * 扩大图像灰度范围【0,255】
    scale_image_max (DistanceImageInv, DistanceImageInvScaled)
    watersheds_threshold (DistanceImageInv, Basins, 5)
    dev_display (DistanceImageInvScaled)
    dev_display (Basins)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    *
    dev_display (Image)
    dev_display (SelectedRegions)
    dev_set_color ('blue')
    dev_display (Basins)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    * 图像求交
    intersection (Basins, SelectedRegions, SegmentedPellets)
    dev_display (Image)
    dev_set_colored (12)
    dev_display (SegmentedPellets)
    disp_continue_message (WindowHandle, 'black', 'true')
    stop ()
    return ()
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49

    其他算子

    connection(Region : ConnectedRegions : : )计算区域的连通域
    select_shape (ConnectedRegions, SelectedRegions, ‘area’, ‘and’, 20, 99999) 根据区域特征(面积、长度等)提取区域
    distance_transform(Region : DistanceImage : Metric, Foreground, Width, Height : )计算区域的距离变换
    convert_image_type(Image : ImageConverted : NewType : )转换图像类型(byte* / direction* / cyclic* / int1* / int2* / uint2* / int4* / int8 / real* / complex*)
    invert_image(Image : ImageInvert : : )反转图像

    scale_image_max(Image : ImageScaleMax : : )将图像灰度范围扩大到【0,255】
    intersection(Region1, Region2 : RegionIntersection : : )计算区域的交集

  • 相关阅读:
    Kubernetes 再深入一点点
    10分钟完成 mongodb replSet 部署
    网络篇
    p2p 打洞专场(转)
    Dockerfile 编写
    关于github 代码管理,协作开发
    Kubernetes 基于 ubuntu18.04 手工部署 (k8s)
    备忘 ubuntu ip 及 dns 的坑
    各种语言web性能简单对比测试
    vue 按需加载
  • 原文地址:https://www.cnblogs.com/dengzhekaihua/p/10749310.html
Copyright © 2020-2023  润新知