上結果:
原圖如下:
上代碼:
dev_set_draw ('fill')
dev_set_line_width (2)
dev_set_colored (12)
read_image (ImageLogo, 'D:/HalconWorkplace/img/NBA logo.jpg')
dev_close_window ()
get_image_size (ImageLogo, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
dev_display (ImageLogo)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*高斯平滑濾波
gauss_filter (ImageLogo, ImageGauss, 9)
*計算圖像邊緣幅度
sobel_amp (ImageGauss, EdgeAmplitude, 'sum_abs', 3)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
*通過閾值實現圖像的分水嶺算法分割
watersheds_threshold (EdgeAmplitude, Basins, 14)
dev_display (Basins)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
return ()
參考
https://blog.csdn.net/Vichael_Chan/article/details/102576060
https://blog.csdn.net/liubing8609/article/details/85373420