本文主要是介绍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)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!