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从Word文档中提取图片并生成PPT的操作代码

《Python从Word文档中提取图片并生成PPT的操作代码》在日常办公场景中,我们经常需要从Word文档中提取图片,并将这些图片整理到PowerPoint幻灯片中,手动完成这一任务既耗时又容易出错,... 目录引言背景与需求解决方案概述代码解析代码核心逻辑说明总结引言在日常办公场景中,我们经常需要从 W

Java+AI驱动实现PDF文件数据提取与解析

《Java+AI驱动实现PDF文件数据提取与解析》本文将和大家分享一套基于AI的体检报告智能评估方案,详细介绍从PDF上传、内容提取到AI分析、数据存储的全流程自动化实现方法,感兴趣的可以了解下... 目录一、核心流程:从上传到评估的完整链路二、第一步:解析 PDF,提取体检报告内容1. 引入依赖2. 封装

Java使用正则提取字符串中的内容的详细步骤

《Java使用正则提取字符串中的内容的详细步骤》:本文主要介绍Java中使用正则表达式提取字符串内容的方法,通过Pattern和Matcher类实现,涵盖编译正则、查找匹配、分组捕获、数字与邮箱提... 目录1. 基础流程2. 关键方法说明3. 常见场景示例场景1:提取所有数字场景2:提取邮箱地址4. 高级

Python 字符串裁切与提取全面且实用的解决方案

《Python字符串裁切与提取全面且实用的解决方案》本文梳理了Python字符串处理方法,涵盖基础切片、split/partition分割、正则匹配及结构化数据解析(如BeautifulSoup、j... 目录python 字符串裁切与提取的完整指南 基础切片方法1. 使用切片操作符[start:end]2

使用Python提取PDF大纲(书签)的完整指南

《使用Python提取PDF大纲(书签)的完整指南》PDF大纲(Outline)​​是PDF文档中的导航结构,通常显示在阅读器的侧边栏中,方便用户快速跳转到文档的不同部分,大纲通常以层级结构组织,包含... 目录一、PDF大纲简介二、准备工作所需工具常见安装问题三、代码实现完整代码核心功能解析四、使用效果控

Linux从文件中提取特定内容的实用技巧分享

《Linux从文件中提取特定内容的实用技巧分享》在日常数据处理和配置文件管理中,我们经常需要从大型文件中提取特定内容,本文介绍的提取特定行技术正是这些高级操作的基础,以提取含有1的简单需求为例,我们可... 目录引言1、方法一:使用 grep 命令1.1 grep 命令基础1.2 命令详解1.3 高级用法2

Python实现批量提取BLF文件时间戳

《Python实现批量提取BLF文件时间戳》BLF(BinaryLoggingFormat)作为Vector公司推出的CAN总线数据记录格式,被广泛用于存储车辆通信数据,本文将使用Python轻松提取... 目录一、为什么需要批量处理 BLF 文件二、核心代码解析:从文件遍历到数据导出1. 环境准备与依赖库

Python中提取文件名扩展名的多种方法实现

《Python中提取文件名扩展名的多种方法实现》在Python编程中,经常会遇到需要从文件名中提取扩展名的场景,Python提供了多种方法来实现这一功能,不同方法适用于不同的场景和需求,包括os.pa... 目录技术背景实现步骤方法一:使用os.path.splitext方法二:使用pathlib模块方法三

Python实现精准提取 PDF中的文本,表格与图片

《Python实现精准提取PDF中的文本,表格与图片》在实际的系统开发中,处理PDF文件不仅限于读取整页文本,还有提取文档中的表格数据,图片或特定区域的内容,下面我们来看看如何使用Python实... 目录安装 python 库提取 PDF 文本内容:获取整页文本与指定区域内容获取页面上的所有文本内容获取

C/C++的OpenCV 进行图像梯度提取的几种实现

《C/C++的OpenCV进行图像梯度提取的几种实现》本文主要介绍了C/C++的OpenCV进行图像梯度提取的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的... 目录预www.chinasem.cn备知识1. 图像加载与预处理2. Sobel 算子计算 X 和 Y