threshold算子
*读取图片 read_image (Audi2, 'audi2') *这个算子看帮助是把奇数行或者偶数行的值用上下的平均值,有点类似滤波 fill_interlace (Audi2, ImageFilled, 'odd') *二值化 threshold (ImageFilled, Region, 0, 90) *分割成区域数组 connection (Region, ConnectedRegions) *根据车牌文字的宽和高进行筛选,然后显示文字的区域 select_shape (ConnectedRegions, SelectedRegions, 'width', 'and', 30, 70) select_shape (SelectedRegions, Letters, 'height', 'and', 60, 110) dev_clear_window () dev_set_colored (12) dev_display (ImageFilled) dev_display (Letters)
auto_threshold(Image:Regions:Sigma:)
作用:对单通道图像做自动阈值,多阈值分割。
其中Sigma为灰度直方图的高斯标准差,光滑消除噪声
read_image (Image, 'clip') rgb1_to_gray (Image, GrayImage) *使用灰度直方图分割 *计算灰度直方图 gray_histo (GrayImage, GrayImage, AbsoluteHisto, RelativeHisto) *生成直方图区域 gen_region_histo (Region, AbsoluteHisto, 255, 255, 1) *计算二值化阈值 histo_to_thresh (AbsoluteHisto, 4, MinThresh, MaxThresh) *二值化 threshold (GrayImage, Region1, MinThresh, MaxThresh) *区域连接成区域数组 connection (Region1, Connected1) *使用自动多阈值分割,也是根据灰度直方图的阈值分割 *上面的Region1和这里的Region2效果是一样的 auto_threshold (GrayImage, Region2, 4.0) *区域连接成区域数组 connection (Region2, Connected2)
dyn_threshold
动态阈值算子dyn_threshold理解起来稍微复杂一点,使用dyn_threshold算子的步骤基本是这样的:
1将原图进行滤波平滑处理。
2用原图和平滑后的图逐个像素做比较,它可以根据参数分割出原图比平滑后的图灰度高(或者低)若干个灰度值的区域。
read_image (Image, 'data/garlic') *将图像转换为灰度 rgb1_to_gray (Image, GrayImage) *使用平滑滤波器对原始图像进行适当平滑 mean_image (GrayImage, ImageMean, 30,30) *动态阈值分割,提取字符区域 dyn_threshold (GrayImage, ImageMean, RegionDynThresh, 30, 'not_equal')
binary_threshold 全自动二值化
是自动阈值算子,它可以自动选出暗(dark)的区域,或者自动选出亮(light)的区域
read_image (Clip, 'clip') get_image_size (Clip, Width, Height) *全自动二值化,取出暗区域 binary_threshold (Clip, Dark, 'max_separability', 'dark', UsedThreshold) connection (Dark, Single) *筛选回形针面积大小的区域 select_shape (Single, Selected, 'area', 'and', 5000, 10000)
char_threshold(Image,HistoRegion:Characters:Sigma,Percent:Threshold)
作用:阈值分割提取字符
Image:原图像,要做字符提取的图像
HistoRegion:要提取字符所在的region
Characters:提取到的region
Sigma:高斯光滑因子
Percent:灰度直方图中的灰度值差的百分比
Threshold:输出用于阈值处理的阈值
此方法关键在于找到直方图中的最大值,在最大值的左侧找到读取阈值
read_image (Image, 'letters') char_threshold (Image, Image, Seg, 5.0, 95, Threshold) connection (Seg, Connected)
var threshold(Image : Region : MaskWidth, MaskHeight, StdDevScale, AbsThreshold, LightDark:)
Image:输入图像;
MaskWidth, MaskHeight:是用于滤波平滑的掩膜单元
StdDevscale:是标准差乘数因子(简称标准差因子) ;
AbsThreshold:是设定的绝对阈值;
LightDark:有4个值可选:' light'、' dark'' equal'、' not equal'。
read_image (Image, 'label/label_01.png') * Threshold the image. var_threshold (Image, Region, 15, 15, 1.01, 40, 'dark') * Select regions of particular height and size. connection (Region, ConnectedRegions) select_shape (ConnectedRegions, SelectedRegions, ['height','area'], 'and', [20,100], [100,400]) * Display the results dev_display (Image) dev_display (SelectedRegions)
bin_threshold(Image:Region::)
作用:提取背景为白色,且前后背景较为分明,自动选取Sigma值进行高斯光滑处理,光滑直到最后只有一个最小值。例如提取白纸黑字,可以应用此算子。
read_image (Image, 'letters') bin_threshold (Image, Seg) connection (Seg, Connected)
dual_threshold(Image : RegionCrossings : MinSize, MinGray, Threshold : )
Threshold 表示用于分割的阈值数值,
MinSize表示分割出来的区域的最小面积(即数像素的数目个数),
MinGray表示分割出来的区域对应的原图中图像像素的最高灰度不能低于MinGray设定值。
*读取两张图片 read_image (Traffic1, 'traffic1') read_image (Traffic2, 'traffic2') *转成int2类型的图像, convert_image_type (Traffic1, ImageConverted1, 'int2') convert_image_type (Traffic2, ImageConverted2, 'int2') *两张图像相减 sub_image (ImageConverted1, ImageConverted2, ImageSub, 1, 0) *二值化 dual_threshold (ImageSub, RegionDiff, 500, 20, 10) *转成凸性区域 shape_trans (RegionDiff, RegionTrans, 'convex') *区域合并成一个区域 union1 (RegionTrans, RegionUnion)
浙公网安备 33010602011771号