自动阈值,顾名思义就是自己计算阈值.原理很简单,输入一张图像,截取有效区域,生成灰度直方图,根据中值法自动计算出阈值分割范围的平均值,从而得到阈值.
有了阈值就很轻松的进行阈值分割:
read_image (Image, ‘chip.bmp’)
get_image_pointer1 (Image, Pointer, Type, Width, Height)
gen_rectangle1 (Rectangle, 0,0, Width, Height)
gray_histo (Rectangle, Image, AbsoluteHisto, RelativeHisto)
histo_to_thresh (RelativeHisto, 2, MinThresh, MaxThresh)
tuple_max (MinThresh, Max)
FindThreshold (RelativeHisto, Width, Height, Max, T0, i, T1, T2, num1, num2, T)
threshold (Image, Region, T, 255)
dev_set_draw (‘margin’)
dev_display (Image)
connection (Region, ConnectedRegions)
select_shape_std (ConnectedRegions, SelectedRegions, ‘max_area’, 70)
dev_display (Image)
dev_display (SelectedRegions)