halcon中阈值分割算子用法
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
總結
以上是生活随笔為你收集整理的halcon中阈值分割算子用法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 国王发金币
- 下一篇: 重返设计模式--命令模式