halcon學習之圖像分割

同樣大家看看原理和halcon的說明文檔,這裏推薦一本書叫做《機器視覺算法原理與編程實踐》,我是跟着這個學的,感覺不難學習,然後就可以看大量的官方例程了

*1.基於直方圖的自動閾值分割方法
read_image (Image, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/shapes')
rgb1_to_gray (Image, GrayImage)
auto_threshold (GrayImage, Regions, 8)
*畫直方圖
gray_histo (GrayImage, GrayImage, AbsoluteHisto, RelativeHisto)
*平滑前的直方圖
gen_region_histo (Region, AbsoluteHisto, 255, 15, 1)
create_funct_1d_array (AbsoluteHisto, Function)
smooth_funct_1d_gauss (Function, 8.0, SmoothedFunction)
dev_set_color ('red')
*平滑後的直方圖,平滑的目的主要是減少波峯,便於得到圖像邊緣
funct_1d_to_pairs (SmoothedFunction, XValues, YValues)
gen_region_histo (Histo2, YValues, 255, 255, 1)

*2.自動全局閾值分割
read_image (Image1, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/codes')
rgb1_to_gray (Image1, GrayImage1)
binary_threshold (GrayImage1, Region1, 'max_separability', 'dark', UsedThreshold)

 

*3.局部閾值分割
read_image (Image2, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/text')
rgb1_to_gray (Image2, GrayImage2)
*因爲對比度較低,因此使用圖像相乘,增強對比度
mult_image (GrayImage2, GrayImage2, ImageResult, 0.005, 0)
*使用平滑濾波器對原始圖像進行適當的平滑
mean_image (ImageResult, ImageMean, 50, 50)
*動態閾值分割,提取字符區域
dyn_threshold (ImageResult, ImageMean, RegionDynThresh, 4, 'not_equal')
*開運算
opening_circle (RegionDynThresh, RegionOpening, 1.5)

*再舉一個例子
read_image (Image3, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/garlic')
rgb1_to_gray (Image3, GrayImage3)

*先平滑一下
mean_image (GrayImage3, ImageMean1, 30, 30)

*動態閾值分割,然後提取
dyn_threshold (GrayImage3, ImageMean1, RegionDynThresh1, 30, 'not_equal')

*腐蝕
erosion_circle (RegionDynThresh1, RegionErosion, 1.5)

 

*其他閾值分割方法
*var_threshold
read_image (Image4, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/holes')
rgb1_to_gray (Image4, GrayImage4)
var_threshold (GrayImage4, Region2, 15, 15, 0.2, 32, 'dark')

char_threshold (GrayImage4, Region2, Characters, 2, 95, Threshold)
dual_threshold (GrayImage4, RegionCrossings, 20, 5, 2)

 

 

*2.區域生長法,該算法主要是通過相似區域的相連區域,以此找到符合條件的像素點集合,因此需要現在圖像中選擇一個種子點的像素
*以此種子的領域開始搜索,符合條件就添加進來,,最終代表同一個物體就在同一個種子區域了
*主要算子爲regiongrowing
read_image (Image5, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/village')
mean_image (Image5, ImageMean2, 5, 5)
regiongrowing (ImageMean2, Regions1, 1, 1, 3, 100)
closing_circle (Regions1, RegionClosing, 3.5)
connection (RegionClosing, ConnectedRegions)
*regiongrowing_mean算子
*和上面的不同是需要輸入的均值後的圖像
read_image (Image5, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/village')
median_image (Image5, ImageMedian, 'circle', 2, 'mirrored')
*先通過regiongrowing粗略定位種子區域,然後使用regiongrowing_mean在細節分割
regiongrowing (ImageMedian, Regions1, 1, 1, 3, 100)
closing_circle (Regions1, RegionClosing, 3.5)
shape_trans (RegionClosing, RegionTrans, 'inner_circle')
connection (RegionTrans, ConnectedRegions)
area_center (ConnectedRegions, Area, Row, Column)
regiongrowing_mean (ImageMedian, Regions2, Row, Column, 25, 100)

 

*3.分水嶺算法
read_image (Image, 'F:/機器視覺/Halcon機器視覺算法原理與編程實戰/code/code/data/woodboard')
rgb1_to_gray (Image, GrayImage)
gauss_filter (GrayImage, ImageGauss, 11)
watersheds (ImageGauss, Basins, Watersheds)
watersheds_threshold (ImageGauss, Basins1, 50)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章