小哥哥小姐姐觉得有用点个赞呗!
HALCON示例程序vessel.hdev血管的分割与测量
示例程序源码(加注释)
- 关于显示类函数解释
dev_update_window (‘off’)
dev_close_window ()
dev_open_window (0, 0, 512, 512, ‘black’, WindowID)
set_display_font (WindowID, 14, ‘mono’, ‘true’, ‘false’)
read_image (Image, ‘vessel’)
dev_display (Image)
disp_continue_message (WindowID, ‘black’, ‘true’)
stop ()
dev_set_draw (‘fill’)
dev_set_color (‘green’)
dev_set_line_width (3) - 使用Laws纹理过滤器过滤图像
texture_laws (Image, Texture, ‘el’, 2, 5)
dev_display (Texture)
disp_continue_message (WindowID, ‘black’, ‘true’)
stop ()
mean_image (Texture, Energy, 211, 61)
dev_display (Energy)
disp_continue_message (WindowID, ‘black’, ‘true’)
stop ()
dev_display (Image) - 使用二进制阈值分割图像
binary_threshold (Energy, Vessel, ‘smooth_histo’, ‘dark’, UsedThreshold)
dev_display (Vessel)
disp_continue_message (WindowID, ‘black’, ‘true’)
stop ()
dev_set_draw (‘margin’) - 返回区域位置
get_region_contour (Vessel, VesselRows, VesselColumns) - 生成一个用点表示的区域
gen_region_points (VesselBoundary, VesselRows, VesselColumns)
dev_display (Image) - 实用矩形剪切区域
clip_region (VesselBoundary, Boundaries, 0, 2, 511, 509)
dev_display (Boundaries) - 求最小外接矩形
smallest_rectangle1 (Boundaries, UpperRow, Column1, LowerRow, Column2)
disp_continue_message (WindowID, ‘black’, ‘true’)
stop ()
Diameter := []
dev_set_color (‘red’)
dev_update_var (‘off’)
dev_update_time (‘off’)
dev_update_pc (‘off’)
for i := 2 to 509 by 1
* 生成一个由线表示的区域gen_region_line (ScanLine, UpperRow, i, LowerRow, i)dev_display (ScanLine)* 求交集intersection (Boundaries, ScanLine, BoundaryPoints)* 访问区域的像素get_region_points (BoundaryPoints, Rows, Columns)Diameter := [Diameter,abs(Rows[|Rows| - 1] - Rows[0])]
endfor
dev_update_pc (‘on’)
dev_update_time (‘on’)
dev_update_var (‘on’)
Diameter := Diameter
meanDiameter := sum(Diameter) / |Diameter|
minDiameter := min(Diameter)
dev_set_color (‘green’)
dev_display (Image)
dev_display (Boundaries)
dev_set_color (‘yellow’)
get_image_size (Image, Width, Height)
- 获取字符串空间的大小
get_string_extents (WindowID, 'meanDiam: ’ + meanDiameter + ', minDiameter: ’ + minDiameter, Ascent, Descent, TxtWidth, TxtHeight)
disp_message (WindowID, 'meanDiam: ’ + meanDiameter + ', minDiameter: ’ + minDiameter, ‘image’, (UpperRow + LowerRow) / 2, (Width - TxtWidth) / 2, ‘yellow’, ‘false’)
dev_set_draw (‘fill’)
dev_set_line_width (1)
dev_update_window (‘on’)
处理思路
这个例子是主要讲解了血管的分割与测量。使用Laws纹理过滤器过滤图像,使用二进制阈值分割图像。
后记
大家有什么问题可以向我提问哈,我看到了第一时间回复,希望在学习的路上多多结交良师益友。