* 关闭窗口更新
dev_update_off ()
* 读取图像
read_image (Angio, 'angio-part')
get_image_size (Angio, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 14, 'mono', 'true', 'false')
dev_display (Angio)
disp_message (WindowHandle, 'Original image', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
* 根据最大线宽和对比度计算lines_gauss的三个参数
* 第1个参数:最大线宽
* 第2个参数:对比度,若有2个值,第2个值为最小对比度且一定小于第1个值;若
* 仅有1个值,则最小对比度为最大对比度的1/3
calculate_lines_gauss_parameters (8, [12, 0], Sigma, Low, High)
* 计算高斯直线
lines_gauss (Angio, Lines, Sigma, Low, High, 'dark', 'true', 'parabolic', 'true')
select_contours_xld (Lines, RelLines, 'length', 5.0, 999, 0, 0)
dev_set_colored (12)
dev_display (Angio)
dev_display (RelLines)
disp_message (WindowHandle, 'Extacted lines', 'window', 12, 12, 'black', 'true')
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
count_obj (RelLines, Number)
* 轮廓按照一定规则排序
sort_contours_xld (RelLines, RelLines, 'lower_left', 'true', 'row')
gen_empty_obj (PrintedLines)
for Index := 1 to Number by 1
dev_display (Angio)
dev_set_color ('white')
dev_display (PrintedLines)
select_obj (RelLines, Line, Index)
dev_set_color ('green')
dev_display (Line)
concat_obj (PrintedLines, Line, PrintedLines)
* 获取轮廓点
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|
* 为了显示线宽,只有线和背景在该点的灰度差达到25%才会显示,
* 该点是通过抛物线乘以sqrt(3/4)给出
Diameter := (WidthL + WidthR) * sqrt(0.75)
Diam := sum(Diameter) / |Diameter|
if (meanRow > Height - 50)
disp_message (WindowHandle, 'Diam: ' + Diam, 'image', Height - 70,\
meanCol, 'yellow', 'false')
else
disp_message (WindowHandle, 'Diam: ' + Diam, 'image', meanRow, meanCol, \
'yellow', 'false')
endif
disp_message (WindowHandle, 'Diameters of line segments', 'window', 135, 60,\
'black', 'true')
if (Index < 5)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
else
wait_seconds (0.2)
endif
endfor
dev_update_on ()
lines_gauss(Image : Lines : Sigma, Low, High, LightDark, ExtractWidth, LineModel, CompleteJunctions : )
[https://www.mvtec.com/doc/halcon/13/en/lines_gauss.html]: