1、实例(fin.hdev)
目标:找出图片中的毛刺
知识点1:
*一次性读取三张图片(fin1,fin2,fin3),通过select_obj算子选定指定图片
read_image (Fins, 'ff' + [1:3])
知识点2:
1、 可以先用二进制自动阈值算子binary_threshold (Fin, Background, 'max_separability', 'light', UsedThreshold)找出背景,该算子适合目标与背景差异明显,该算子最后一个参数为系统输出的自动阈值用的最低灰度值,输出的亮的区域的灰度值在UsedThreshold和255之间
2、闭运算填充背景区域
closing_circle (Background, ClosedBackground, 250) 以圆形结构元素填充背景区域,小于250的全部空洞全部填充
3、利用填充后的区域减去筛选的背景区域得到毛刺区域,然后开运算去除毛刺多余的部分筛选出毛刺部分
*用闭合后的区域减去之前阈值提取的区域,得到多余的毛刺
difference (ClosedBackground, Background, RegionDifference)
4、*开运算去掉毛刺多余的边
opening_rectangle1 (RegionDifference, FinRegion, 5, 5)
* fin.hdev: Detection of a fin
*
dev_update_window ('off')
*读取三张图片(fin1,fin2,fin3)
read_image (Fins, 'ff' + [1:3])
get_image_size (Fins, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width[0], Height[0], 'black', WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
for I := 1 to 3 by 1
select_obj (Fins, Fin, I)
dev_display (Fin)
*threshold (Fin, Region, 142, 255)
binary_threshold (Fin, Background, 'max_separability', 'light', UsedThreshold)
dev_set_color ('blue')
dev_set_draw ('margin')
dev_set_line_width (4)
dev_display (Background)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*用圆形结构元素去闭合一个区域,区域内面积小于250的孔洞全部填充
closing_circle (Background, ClosedBackground, 250)
dev_set_color ('green')
dev_display (ClosedBackground)
disp_continue_message (WindowID, 'black', 'true')
stop ()
*用闭合后的区域减去之前阈值提取的区域,得到多余的毛刺
difference (ClosedBackground, Background, RegionDifference)
*开运算去掉毛刺多余的边
opening_rectangle1 (RegionDifference, FinRegion, 5, 5)
dev_display (Fin)
dev_set_color ('red')
dev_display (FinRegion)
area_center (FinRegion, FinArea, Row, Column)
count_obj (FinRegion, Number)
if (I < 3)
disp_continue_message (WindowID, 'black', 'true')
stop ()
endif
endfor