halcon中阈值分割算子用法
1.threshold(Image : Region : MinGray, MaxGray : ):通過(guò)給定的閾值區(qū)間對(duì)圖像進(jìn)行分割
效果圖:
? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? ? ? ? ?
read_image (Audi2, 'audi2')
fill_interlace (Audi2, ImageFilled, 'odd')
threshold (ImageFilled, Region, 0, 90)
?
2.binary_threshold(Image : Region : Method, LightDark : UsedThreshold):自動(dòng)閾值分割,可以自動(dòng)選擇出'light' 區(qū)域或'dark' 區(qū)域,使用自動(dòng)確定的全局閾值分割單通道圖像,使用閾值方法Method有'max_separability' 和'smooth_histo'兩個(gè)值,這兩個(gè)值都是只應(yīng)用在具有雙峰直方圖的圖像(bin_threshold是過(guò)去時(shí),新的應(yīng)用程序應(yīng)該使用binary_threshold)
? ? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
reduce_domain (Image, RegionROI, ImageReduced)
binary_threshold (ImageReduced, RegionBackground, 'max_separability', 'dark', UsedThreshold)
3.dyn_threshold(OrigImage, ThresholdImage : RegionDynThresh : Offset, LightDark : ):使用局部閾值分割圖像,首先需要對(duì)圖像進(jìn)行平滑處理(例如?mean_image, binomial_filter, gauss_filter等等),然后用原圖與平滑后的圖逐個(gè)像素作比較,可以根據(jù)參數(shù)分割出原圖比平滑后的圖灰度高(或者低)Offset個(gè)灰度值的區(qū)域。(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 : ):閾值分割有正負(fù)之分的圖像,將輸入圖像中灰度值>= Threshold的分為“positive”區(qū)域,將灰度值 <= -Threshold的分為“negative”區(qū)域,只有當(dāng)“positive”或“negative”區(qū)域的面積大于MinSize的區(qū)域才會(huì)考慮,區(qū)域的最大灰度值 <?MinGray時(shí),該區(qū)域被抑制。?“positive” 和“negative”區(qū)域不一定覆蓋整個(gè)區(qū)域,灰度值在-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 : ):使用從直方圖確定的閾值分割圖像,算法過(guò)程:1.獲取輸入圖像的灰度直方。
使用標(biāo)準(zhǔn)差為Sigma 的一維高斯濾波器對(duì)直方圖進(jìn)行濾波。3.計(jì)算濾波后的直方圖的極小值。4.以計(jì)算得到的極小值所對(duì)應(yīng)的灰度值為分割閾值對(duì)圖像進(jìn)行分割。
? ?? ?
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):為提取字符執(zhí)行閾值分割。主要應(yīng)用是在明亮的紙張上分割單通道的暗字符圖像。該算子工作如下:1.首先,對(duì)Image圖像的HistoRegion 內(nèi)的點(diǎn)計(jì)算灰度直方圖,用給定的Sigma高斯平滑對(duì)直方圖進(jìn)行平滑處理,減少噪音。在直方圖中,背景(白紙)在高灰度值處對(duì)應(yīng)一個(gè)大的峰值,而字符在低灰度值處形成一個(gè)小的峰值。與操作符binary_threshold (with 'Method'='smooth_histo')定位兩個(gè)峰值之間的最小值不同,這里分割的閾值是根據(jù)直方圖的最大值確定的,即,背景,條件如下:
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。該算子工作如下:首先,處理位于選定的水平線上的所有點(diǎn),這些點(diǎn)有它們的距離MinSize 指定,然后,處理所有先前選擇的點(diǎn)的鄰域(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 : ):對(duì)圖像執(zhí)行滯后閾值操作,輸入圖像中灰度值大于或等于Hight的所有點(diǎn)立即被接受(“secure” 安全點(diǎn)),相反,所有灰度值小于Low的點(diǎn)會(huì)立即被拒絕。如果某個(gè)點(diǎn)(灰度值在Low與High之間)連接到“secure”點(diǎn)的距離長(zhǎng)度不超過(guò)MaxLength,則該點(diǎn)為兩個(gè)閾值之間的灰度值的?“Potential” 潛在點(diǎn),這意味著安全點(diǎn)影響它們的環(huán)境(滯后)
? ? ? ? ? ? ? ? ? ? ?? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
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'方法,該算法是一種文本二值化技術(shù)。?Method = 'adapted_std_deviation',根據(jù)Sauvola調(diào)用基于局部均值和標(biāo)準(zhǔn)偏差的局部自適應(yīng)閾值。該算法能夠?qū)ξ臋n圖像進(jìn)行分割,即使圖像質(zhì)量下降,例如由于不均勻的光照或噪聲,它通過(guò)考慮局部對(duì)比度來(lái)實(shí)現(xiàn)非均勻背景下的文本二值化。
? ? ? ? ? ? ? ? ? ? ? ??? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?
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 : ):使用閾值從圖像中提取流域盆地。流域之間由一個(gè)高度至少為T(mén)hreshold的分水嶺間隔。在第一步中,watersheds_threshold計(jì)算流域而不應(yīng)用閾值,得到的流域與調(diào)用流域是得到的流域相同。在第二步中,如果流域被一個(gè)小于Threshold的分水嶺分隔開(kāi),則流域依次合并。
? ?? ??? ??
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
總結(jié)
以上是生活随笔為你收集整理的halcon中阈值分割算子用法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。