halcon line_gauss 线状物提取 (by shany shang)

2024-03-08 15:58

本文主要是介绍halcon line_gauss 线状物提取 (by shany shang),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

主程序源代码:

dev_close_window ()

*载入yi'fu'tu'xiang
read_image (Angio, 'angio-part')
get_image_size (Angio, Width, Height)
dev_open_window (0, 0, 3 * Width / 2, 3 * Height / 2, 'black', WindowID)
dev_display (Angio)
dev_set_color ('blue')
MaxLineWidth := 8
Contrast := 12

*根据需要检测线宽MaxLineWidth 和线与背景的对比度 计算出 线性高斯计算需要用到的输入参数:Sigma, Low, High
calculate_lines_gauss_parameters (MaxLineWidth, [Contrast,0], Sigma, Low, High)

*进行线性高斯计算 'dark':需要检测黑色线 
lines_gauss (Angio, Lines, Sigma, Low, High, 'dark', 'true', 'parabolic', 'true')
dev_display(Lines)
count_obj (Lines, Number)
dev_update_pc ('off')
dev_update_var ('off')
for I := 1 to Number by 1
    select_obj (Lines, Line, I)

   *获取线的位置
    get_contour_xld (Line, Row, Col)

    *获取线的法向量角度
    get_contour_attrib_xld (Line, 'angle', Angle)

    *获取线到线区域左侧边的距离
    get_contour_attrib_xld (Line, 'width_left', WidthL)

  *获取线到线区域右侧边的距离
    get_contour_attrib_xld (Line, 'width_right', WidthR)
    * To display the lines, the point at which the gray value drops to
    * 25% of the contrast between the line and the background will be
    * displayed.  This point is given by sqrt(3/4) for the parabolic
    * line model.

*计算线区域轮廓的各个节点
    RowR := Row + cos(Angle) * WidthR * sqrt(0.75)
    ColR := Col + sin(Angle) * WidthR * sqrt(0.75)
    RowL := Row - cos(Angle) * WidthL * sqrt(0.75)
    ColL := Col - sin(Angle) * WidthL * sqrt(0.75)
    dev_set_color ('red')
    dev_display (Line)
    dev_set_color ('green')

*将各个节点连接成多边形显示出来
    disp_polygon (WindowID, RowL, ColL)
    disp_polygon (WindowID, RowR, ColR)
endfor

其中 本地函数:

calculate_lines_gauss_parameters (MaxLineWidth, [Contrast,0], Sigma, Low, High)

实现过程如下:

* Check control parameters
if (|MaxLineWidth| != 1)
    throw ('Wrong number of values of control parameter: 1')
endif
if (not is_number(MaxLineWidth))
    throw ('Wrong type of control parameter: 1')
endif
if (MaxLineWidth <= 0)
    throw ('Wrong value of control parameter: 1')
endif
if (|Contrast| != 1 and |Contrast| != 2)
    throw ('Wrong number of values of control parameter: 2')
endif
if (min(is_number(Contrast)) == 0)
    throw ('Wrong type of control parameter: 2')
endif
* Set and check ContrastHigh
ContrastHigh := Contrast[0]
if (ContrastHigh < 0)
    throw ('Wrong value of control parameter: 2')
endif
* Set or derive ContrastLow
if (|Contrast| == 2)
    ContrastLow := Contrast[1]
else
    ContrastLow := ContrastHigh / 3.0
endif
* Check ContrastLow
if (ContrastLow < 0)
    throw ('Wrong value of control parameter: 2')
endif
if (ContrastLow > ContrastHigh)
    throw ('Wrong value of control parameter: 2')
endif

* Calculate the parameters Sigma, Low, and High for lines_gauss
if (MaxLineWidth < sqrt(3.0))
    * Note that LineWidthMax < sqrt(3.0) would result in a Sigma < 0.5,
    * which does not make any sense, because the corresponding smoothing
    * filter mask would be of size 1x1.
    * To avoid this, LineWidthMax is restricted to values greater or equal
    * to sqrt(3.0) and the contrast values are adapted to reflect the fact
    * that lines that are thinner than sqrt(3.0) pixels have a lower contrast
    * in the smoothed image (compared to lines that are sqrt(3.0) pixels wide).
    ContrastLow := ContrastLow * MaxLineWidth / sqrt(3.0)
    ContrastHigh := ContrastHigh * MaxLineWidth / sqrt(3.0)
    MaxLineWidth := sqrt(3.0)
endif
* Convert LineWidthMax and the given contrast values into the input parameters
* Sigma, Low, and High required by lines_gauss
HalfWidth := MaxLineWidth / 2.0
Sigma := HalfWidth / sqrt(3.0)
Help := -2.0 * HalfWidth / (sqrt(6.283185307178) * pow(Sigma,3.0)) * exp(-0.5 * pow(HalfWidth / Sigma,2.0))
High := fabs(ContrastHigh * Help)
Low := fabs(ContrastLow * Help)
return ()

原图:血管X_光图像

检测效果

 

这篇关于halcon line_gauss 线状物提取 (by shany shang)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/787614

相关文章

使用Python在Excel中插入、修改、提取和删除超链接

《使用Python在Excel中插入、修改、提取和删除超链接》超链接是Excel中的常用功能,通过点击超链接可以快速跳转到外部网站、本地文件或工作表中的特定单元格,有效提升数据访问的效率和用户体验,这... 目录引言使用工具python在Excel中插入超链接Python修改Excel中的超链接Python

C#从XmlDocument提取完整字符串的方法

《C#从XmlDocument提取完整字符串的方法》文章介绍了两种生成格式化XML字符串的方法,方法一使用`XmlDocument`的`OuterXml`属性,但输出的XML字符串不带格式,可读性差,... 方法1:通过XMLDocument的OuterXml属性,见XmlDocument类该方法获得的xm

C#提取PDF表单数据的实现流程

《C#提取PDF表单数据的实现流程》PDF表单是一种常见的数据收集工具,广泛应用于调查问卷、业务合同等场景,凭借出色的跨平台兼容性和标准化特点,PDF表单在各行各业中得到了广泛应用,本文将探讨如何使用... 目录引言使用工具C# 提取多个PDF表单域的数据C# 提取特定PDF表单域的数据引言PDF表单是一

C#实现添加/替换/提取或删除Excel中的图片

《C#实现添加/替换/提取或删除Excel中的图片》在Excel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更加美观,下面我们来看看如何在C#中实现添加/替换/提取或删除E... 在Excandroidel中插入与数据相关的图片,能将关键数据或信息以更直观的方式呈现出来,使文档更

基于WinForm+Halcon实现图像缩放与交互功能

《基于WinForm+Halcon实现图像缩放与交互功能》本文主要讲述在WinForm中结合Halcon实现图像缩放、平移及实时显示灰度值等交互功能,包括初始化窗口的不同方式,以及通过特定事件添加相应... 目录前言初始化窗口添加图像缩放功能添加图像平移功能添加实时显示灰度值功能示例代码总结最后前言本文将

Java后端接口中提取请求头中的Cookie和Token的方法

《Java后端接口中提取请求头中的Cookie和Token的方法》在现代Web开发中,HTTP请求头(Header)是客户端与服务器之间传递信息的重要方式之一,本文将详细介绍如何在Java后端(以Sp... 目录引言1. 背景1.1 什么是 HTTP 请求头?1.2 为什么需要提取请求头?2. 使用 Spr

使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)

《使用Java解析JSON数据并提取特定字段的实现步骤(以提取mailNo为例)》在现代软件开发中,处理JSON数据是一项非常常见的任务,无论是从API接口获取数据,还是将数据存储为JSON格式,解析... 目录1. 背景介绍1.1 jsON简介1.2 实际案例2. 准备工作2.1 环境搭建2.1.1 添加

python解析HTML并提取span标签中的文本

《python解析HTML并提取span标签中的文本》在网页开发和数据抓取过程中,我们经常需要从HTML页面中提取信息,尤其是span元素中的文本,span标签是一个行内元素,通常用于包装一小段文本或... 目录一、安装相关依赖二、html 页面结构三、使用 BeautifulSoup javascript

ROS - C++实现RosBag包回放/提取

文章目录 1. 回放原理2. 回放/提取 多个话题3. 回放/提取数据包,并实时发布 1. 回放原理 #include <ros/ros.h>#include <rosbag/bag.h>#include <std_msgs/String.h>int main(int argc, char** argv){// 初始化ROS节点ros::init(argc, argv,

HalconDotNet中的图像特征与提取详解

文章目录 简介一、边缘特征提取二、角点特征提取三、区域特征提取四、纹理特征提取五、形状特征提取 简介   图像特征提取是图像处理中的一个重要步骤,用于从图像中提取有意义的特征,以便进行进一步的分析和处理。HalconDotNet提供了多种图像特征提取方法,每种方法都有其特定的应用场景和优缺点。 一、边缘特征提取   边缘特征提取是图像处理中最基本的特征提取方法之一,通过检