halcon知识:图像纹理特征提取cooc_feature_matrix
生活随笔
收集整理的這篇文章主要介紹了
halcon知识:图像纹理特征提取cooc_feature_matrix
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、關于共生矩陣?
????????如果不懂啥叫共生矩陣,將無法閱讀該文。如果試圖搞明白啥叫共生矩陣,請看我的另一篇博文,《hjalcon知識:共生矩陣》
? ? ? ? 本片介紹共生矩陣產生的其它屬性:能量、相關性、同質性(同類性)、對比度。
? ? ? ? halcon內關于共生矩陣有三個算子:
- gen_cooc_matrix、
- cooc_feature_matrix、
- cooc_feature_image
三個算子的其關系如下圖:
二、算子函數
cooc_feature_matrix(CoocMatrix : : : Energy, Correlation, Homogeneity, Contrast)
cooc_feature_matrix( | |
CoocMatrix | 圖標量輸入,這里是共生矩陣 |
| : | 無圖標輸出 |
| : | 無控制量輸入 |
Energy,Correlation,Homogeneity,Contrast ) | 四個控制量,決定圖像特征 |
?三、特征的數學原理
????????該算子根據共現矩陣(CoocMatrix)計算能量(能量)、相關性(相關性)、局部同質性(同質性)和對比度(對比度)。
????????運算符cooc_feature_matrix根據以下公式計算由gen_cooc_matrix生成的輸入矩陣中與參數LdGray和direction指示的方向矩陣相對應的部分的灰度值特征:
3.1 中間變量定義
width = 共生矩陣的寬度(灰度圖像為8)
?= 共生矩陣的元素值
??
3.2 特征數學模型
1)能量
? ? ? ? ? ? ? ?計量圖像的同質性,該值越大越不夠同質
2)相關性
?相關與獨立相反,該值越大越不獨立
?3)同質度
4)對比度
四、相關代碼
* This example shows how to calculate co-occurrence matrices * from given image regions and how to derive gray value features * from these co-occurrence matrices. dev_update_off () * * Read in an image and open and prepare the output windows read_image (Image, 'mreut') dev_close_window () get_image_size (Image, Width, Height) CoocWinSize := 320 Border := 10 dev_open_window (0, CoocWinSize + Border, Width, Height, 'black', WindowID) set_display_font (WindowID, 16, 'mono', 'true', 'false') dev_display (Image) dev_set_draw ('margin') dev_set_line_width (3) * dev_open_window (Height - CoocWinSize, 0, CoocWinSize, CoocWinSize, 'black', WindowID1) set_display_font (WindowID1, 16, 'mono', 'true', 'false') dev_set_lut ('temperature') dev_set_draw ('margin') dev_set_line_width (5) dev_set_color ('yellow') * dev_open_window (0, Width + CoocWinSize + 2 * Border, CoocWinSize, CoocWinSize, 'black', WindowID2) set_display_font (WindowID2, 16, 'mono', 'true', 'false') dev_set_lut ('temperature') dev_set_draw ('margin') dev_set_line_width (5) dev_set_color ('blue') * * Define the regions for which the co-occurance matrices will be calculated gen_rectangle1 (Rectangle1, 350, 100, 450, 200) gen_rectangle1 (Rectangle2, 100, 200, 200, 300) inner_circle (Rectangle1, Row1, Column1, Radius1) inner_circle (Rectangle2, Row2, Column2, Radius2) * * Loop over the four possible directions for Direction := 0 to 135 by 45* * Calculate the co-occurrence matrices for the given regionsgen_cooc_matrix (Rectangle1, Image, Matrix1, 6, Direction)gen_cooc_matrix (Rectangle2, Image, Matrix2, 6, Direction)* * Calculate the gray value features from the co-occurance matricescooc_feature_matrix (Matrix1, Energy1, Correlation1, Homogeneity1, Contrast1)cooc_feature_matrix (Matrix2, Energy2, Correlation2, Homogeneity2, Contrast2)* * Display the resultsdev_set_window (WindowID)dev_display (Image)disp_message (WindowID, 'Direction: ' + Direction$'3d' + ' degrees', 'window', 260, 100, 'black', 'true')dev_set_color ('yellow')dev_display (Rectangle1)gen_arrow_contour_xld (Arrow1, Row1, Column1, Row1 - sin(rad(Direction)) * 0.9 * Radius1, Column1 + cos(rad(Direction)) * 0.9 * Radius1, 8, 8)dev_display (Arrow1)dev_set_color ('blue')dev_display (Rectangle2)gen_arrow_contour_xld (Arrow2, Row2, Column2, Row2 - sin(rad(Direction)) * 0.9 * Radius2, Column2 + cos(rad(Direction)) * 0.9 * Radius2, 8, 8)dev_display (Arrow2)* String := ['Energy: ','Correlation: ','Homogeneity: ','Contrast: ']dev_set_window (WindowID1)dev_display (Matrix1)get_domain (Matrix1, Domain)dev_display (Domain)disp_message (WindowID1, String$'-14s' + [Energy1,Correlation1,Homogeneity1,Contrast1]$'6.3f', 'window', 12, 12, 'white', 'false')* dev_set_window (WindowID2)dev_display (Matrix2)get_domain (Matrix2, Domain)dev_display (Domain)disp_message (WindowID2, String$'-14s' + [Energy2,Correlation2,Homogeneity2,Contrast2]$'6.3f', 'window', 12, 12, 'white', 'false')* if (Direction < 135)disp_continue_message (WindowID, 'black', 'true')stop ()endif endfor五、結果
總結
以上是生活随笔為你收集整理的halcon知识:图像纹理特征提取cooc_feature_matrix的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: halcon知识:共生矩阵
- 下一篇: Halcon知识: XLD的概念