Halcon_二维测量_Angio

主要功能:通过使用calculate_lines_gauss_parameters与lines_gauss获取血管直径
原图
处理后的图
主要思路:
1、读取图片
2、使用calculate_lines_gauss_parameters获取lines_gauss函数所需的参数
3、使用lines_gauss提取血管骨架
4、获取每个轮廓点对应的线宽、对比度等信息
5、排序并显示

主要函数:
1、calculate_lines_gauss_parameters( : : MaxLineWidth, Contrast : Sigma, Low, High)
作用:用于生成lines_guass所需的参数
其中:
1、MaxlineWidth约束了线条捕捉的最大线宽
2、Contrast用于限定线条的灰度值,当其仅有一个数时,约束最大值,当时为一个二维数组时,分别约束最大最小值。
3、Sigma、Low、High为输出的lines_gauss所需参数

2、lines_gauss(Image : Lines : Sigma, Low, High, LightDark, ExtractWidth, LineModel,CompleteJunctions : )
作用:用于捕捉指定参数的线条
其中:
1、Image为输入图片
2、Lines为输出的捕获得到的线条
3、Sigma、Low、High为calculate_lines_gauss_parameters函数计算得到的参数
4、LightDark用于设置捕捉的线条为亮或暗
5、ExtractWidth,当其设置为True时,为每个点定义线宽属性:width_left与width_right;当其设置为False时,为每个点定义以下属性:angle、response、width_left、width_right、asymmetry和constrast
6、LineModel当其设置为非None时,可以根据设置的属性提取对应类型的线条,如条形线(LineModel =‘条形’)、抛物线(LineModel =‘抛物线’)和高斯线(LineModel =‘高斯’)
注意:参数LineModel只有在ExtractWidth='true’时才有意义
7、CompleteJunctions设置为True时,将联合多种LineModel进行线条获取

源码及注释如下:

*将dev_update_pc,dev_update_var和dev_update窗口切换到关闭
dev_update_off ()
*图片读取并赋值给Angio
read_image (Angio, 'angio-part')
*获取图片宽度、高度
get_image_size (Angio, Width, Height)
*关闭已打开的窗口
dev_close_window ()
*开启指定窗口
dev_open_window (0, 0, Width, Height, 'black', WindowID)
*设置显示格式
set_display_font (WindowID, 14, 'mono', 'true', 'false')
*在窗口中显示图片
dev_display (Angio)
*在窗口中显示信息
disp_message (WindowID, 'Original image', 'window', 12, 12, 'black', 'true')
*在荧幕上显示暂停程序继续操作的信息
disp_continue_message (WindowID, 'black', 'true')
*停止程序
stop ()
*获取lines_gauss计算所需的参数Sigma、Low、High
calculate_lines_gauss_parameters (8, [12,0], Sigma, Low, High)
*获取线条,并存入Lines,其中parabolic意为抛物线
lines_gauss (Angio, Lines, Sigma, Low, High, 'dark', 'true', 'parabolic', 'true')
*通过设置长度范围筛选获取的线段,筛选得到的线条存入RelLines
select_contours_xld (Lines, RelLines, 'length', 5.0, 999, 0, 0)
*设置12种显示颜色
dev_set_colored (12)
dev_display (Angio)
*显示筛选后的线条
dev_display (RelLines)
disp_message (WindowID, 'Extracted lines', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowID, 'black', 'true')
stop ()
*计算筛选后的线条数量,赋值给Number
count_obj (RelLines, Number)
*根据外接矩形的左下角坐标排序
sort_contours_xld (RelLines, RelLines, 'lower_left', 'true', 'row')
*生成一个空的object puble,用于存储用于已经打印了的线条数组
gen_empty_obj (PrintedLines)
for I := 1 to Number by 1
    dev_display (Angio)
    dev_set_color ('white')
    dev_display (PrintedLines)
	*选择ReLines中的第i条线条,赋值给Line,用于显示
    select_obj (RelLines, Line, I)
    dev_set_color ('green')
    dev_display (Line)
	*将单条Line显示完毕后,存入PrintedLines
    concat_obj (PrintedLines, Line, PrintedLines)
	*获取线条轮廓的坐标,其中Row为纵坐标的集合,Col为横坐标的集合
    get_contour_xld (Line, Row, Col)
	*求取线条纵坐标均值
    meanRow := sum(Row) / |Row|
	*求取线条横坐标均值
    meanCol := sum(Col) / |Col|
	*获取线条到左侧(从起始位置到终止位置的方向)轮廓的宽度
    get_contour_attrib_xld (Line, 'width_left', WidthL)
	*获取线条到右侧(从起始位置到终止位置的方向)轮廓的宽度
    get_contour_attrib_xld (Line, 'width_right', WidthR)
	*轮廓的对比度描述了线的灰度值与局部背景灰度值之间的差异。如果提取的是亮线,它是正的
	get_contour_attrib_xld (Line, 'contrast', Contrast)
	*求取线条对比度均值
    meanContrast := sum(Contrast) / |Contrast|
	*对于轮廓线上的每个点求取线宽
    Diameter := (WidthL + WidthR) * sqrt(0.75)
	*求取每个线条的平均线宽
    Diam := sum(Diameter) / |Diameter|
    if (meanRow > Height - 50)
        disp_message (WindowID, 'diam: ' + Diam, 'image', Height - 70, meanCol, 'yellow', 'false')
    else
        disp_message (WindowID, 'diam: ' + Diam, 'image', meanRow, meanCol, 'yellow', 'false')
    endif
    disp_message (WindowID, 'Diameters of line segments', 'window', 135, 60, 'black', 'true')
    if (I < 5)
		*对于前5条线段设置停止
        disp_continue_message (WindowID, 'black', 'true')
        stop ()
    else
		*对于其他的线段,每次画线后,停止0.2秒
        wait_seconds (0.2)
    endif
endfor
*将dev_update_pc,dev_update_var和dev_update窗口切换到开启
dev_update_on ()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值