1.threshold(Image : Region : MinGray, MaxGray : ):通过给定的阈值区间对图像进行分割
效果图:
read_image (Audi2, 'audi2')
fill_interlace (Audi2, ImageFilled, 'odd')
threshold (ImageFilled, Region, 0, 90)
2.binary_threshold(Image : Region : Method, LightDark : UsedThreshold):自动阈值分割,可以自动选择出'light' 区域或'dark' 区域,使用自动确定的全局阈值分割单通道图像,使用阈值方法Method有'max_separability' 和'smooth_histo'两个值,这两个值都是只应用在具有双峰直方图的图像(bin_threshold是过去时,新的应用程序应该使用binary_threshold)
reduce_domain (Image, RegionROI, ImageReduced)
binary_threshold (ImageReduced, RegionBackground, 'max_separability', 'dark', UsedThreshold)
3.dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : ):使用局部阈值分割图像,首先需要对图像进行平滑处理(例如 mean_image, binomial_filter, gauss_filter等等),然后用原图与平滑后的图逐个像素作比较,可以根据参数分割出原图比平滑后的图灰度高(或者低)Offset个灰度值的区域。(Offset的值最好是在5到40之间)
read_image (Image, 'surface_scratch')
mean_image (Image, ImageMean, 7, 7)
dyn_threshold (Image, ImageMean, DarkPixels, 5, 'dark')
4.dual_threshold(Image : RegionCrossings : MinSize, MinGray, Threshold : ):阈值分割有正负之分的图像,将输入图像中灰度值>= Threshold的分为“positive”区域,将灰度值 <= -Threshold的分为“negative”区域,只有当“positive”或“negative”区域的面积大于MinSize的区域才会考虑,区域的最大灰度值 < MinGray时,该区域被抑制。 “positive” 和“negative”区域不一定覆盖整个区域,灰度值在-Threshold 与Threshold和-MinGray 与 MinGray之间是不被考虑的。
read_image (Traffic1, 'traffic1')
read_image (Traffic2, 'traffic2')
convert_image_type (Traffic1, ImageConverted1, 'int2')
convert_image_type (Traffic2, ImageConverted2, 'int2')
* Subtract two images.
sub_image (ImageConverted1, ImageConverted2, ImageSub, 1, 0)
dual_threshold (ImageSub, RegionDiff, 500, 20, 10)
5.auto_threshold(Image : Regions : Sigma : ):使用从直方图确定的阈值分割图像,算法过程:1.获取输入图像的灰度直方。
使用标准差为Sigma 的一维高斯滤波器对直方图进行滤波。3.计算滤波后的直方图的极小值。4.以计算得到的极小值所对应的灰度值为分割阈值对图像进行分割。
read_image (Aegypt1, 'egypt1')
get_image_size (Aegypt1, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
set_display_font (WindowID, 14, 'mono', 'true', 'false')
dev_set_colored (6)
dev_clear_window ()
Sigma := 4
auto_threshold (Aegypt1, Regions, Sigma)
6.char_threshold(Image, HistoRegion : Characters : Sigma, Percent : Threshold):为提取字符执行阈值分割。主要应用是在明亮的纸张上分割单通道的暗字符图像。该算子工作如下:1.首先,对Image图像的HistoRegion 内的点计算灰度直方图,用给定的Sigma高斯平滑对直方图进行平滑处理,减少噪音。在直方图中,背景(白纸)在高灰度值处对应一个大的峰值,而字符在低灰度值处形成一个小的峰值。与操作符binary_threshold (with 'Method'='smooth_histo')定位两个峰值之间的最小值不同,这里分割的阈值是根据直方图的最大值确定的,即,背景,条件如下:
histogram[threshold] * 100.0 < histogram[maximum] * (100.0 - Percent)
read_image (Alpha1, 'alpha1')
get_image_size (Alpha1, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
dev_display (Alpha1)
dev_set_color ('white')
dev_clear_window ()
char_threshold (Alpha1, Alpha1, Characters, 6, 95, Threshold)
7.fast_threshold(Image : Region : MinGray, MaxGray, MinSize : ):利用全局阈值快速阈值化图像,从输入图像中选取灰度值g满足一下条件的像素MinGray < g < MaxGray。该算子工作如下:首先,处理位于选定的水平线上的所有点,这些点有它们的距离MinSize 指定,然后,处理所有先前选择的点的邻域(size(2*MinSize + 1)*(2*MinSize + 1)),速度比threshold快
read_image (Image, 'particle')
dev_close_window ()
get_image_size (Image, Width, Height)
dev_open_window (0, 0, Width, Height, 'black', WindowID)
dev_display (Image)
dev_set_color ('red')
dev_set_draw ('fill')
dev_update_var ('off')
dev_update_window ('off')
dev_update_pc ('off')
count_seconds (Seconds1)
fast_threshold (Image, Region, 128, 255, 10)
8.hysteresis_threshold(Image : RegionHysteresis : Low, High, MaxLength : ):对图像执行滞后阈值操作,输入图像中灰度值大于或等于Hight的所有点立即被接受(“secure” 安全点),相反,所有灰度值小于Low的点会立即被拒绝。如果某个点(灰度值在Low与High之间)连接到“secure”点的距离长度不超过MaxLength,则该点为两个阈值之间的灰度值的 “Potential” 潜在点,这意味着安全点影响它们的环境(滞后)
decompose3 (ImageReduced, ImageR, ImageG, ImageB)
invert_image (ImageB, ImageInvert)
hysteresis_threshold (ImageInvert, RegionHysteresis2, 190, 200, 5)
9.local_threshold(Image : Region : Method, LightDark, GenParamName, GenParamValue : ):使用局部阈值分割图像。使用method中给出的阈值方法分割单通道图像,目前该算子只提供'adapted_std_deviation'方法,该算法是一种文本二值化技术。 Method = 'adapted_std_deviation',根据Sauvola调用基于局部均值和标准偏差的局部自适应阈值。该算法能够对文档图像进行分割,即使图像质量下降,例如由于不均匀的光照或噪声,它通过考虑局部对比度来实现非均匀背景下的文本二值化。
read_image (Letters, 'letters')
dev_open_window_fit_image (Letters, 0, 0, -1, -1, WindowHandle)
set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
get_image_size (Letters, Width, Height)
gen_image_surface_first_order (ImageSurface, 'byte', 0.5, 0.5, 0.5, Width / 2, Height / 2, Width, Height)
add_image (Letters, ImageSurface, ImageCombined, 0.5, 0)
local_threshold (ImageCombined, Region, 'adapted_std_deviation', 'dark', [], [])
10.watersheds_threshold(Image : Basins : Threshold : ):使用阈值从图像中提取流域盆地。流域之间由一个高度至少为Threshold的分水岭间隔。在第一步中,watersheds_threshold计算流域而不应用阈值,得到的流域与调用流域是得到的流域相同。在第二步中,如果流域被一个小于Threshold的分水岭分隔开,则流域依次合并。
read_image (ImageLogo, 'mvtec_logo.png')
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)
watersheds (EdgeAmplitude, Basins1, Watersheds)
dev_display (Basins1)
disp_continue_message (WindowHandle, 'black', 'true')
stop ()
watersheds_threshold (EdgeAmplitude, Basins2, 14)
参考文章:https://blog.csdn.net/qq_29187197/article/details/82780566
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)