在谈纹理分析之前,先谈谈blog分析。
在halcon中,blog分析是最基础的图像处理方法。
read_image (Image, 'printer_chip/printer_chip_01') threshold (Image, Region, 128, 255) connection (Region, ConnectedRegions) area_center (ConnectedRegions, Area, Row, Column)
blog的方法一般很难应用于纹理分析。因为纹理往往意味着连通区域不明显。
纹理分析(Texture Analysis)
texture_laws(Image : ImageTexture : FilterTypes, Shift, FilterSize : ) 参数说明: 参数一Image:原始图像 参数二ImageTexture:输出图像,即laws纹理滤波结果 参数三FilterTypes:过滤器类型 参数四Shift:灰度值转换,滤波后的灰度值可能比较大,转换后的灰度值Gray=Gray/(Shift),要根据滤波器选择合适的灰度值转换 参数五FilterSize:过滤器大小,3、5、7可选 过滤器都是由l e s r w o这几个相邻构成,halcon帮助文档中单个向量都有原型,对于组合出来的滤波器矩阵,就是两个向量的点积。 The names of the filters are mnemonics for “level,” “edge,” “spot,” “wave,” “ripple,” “undulation,” and “oscillation.” 滤波器类型由滤波向量(vector)的两个字母组成,第一个字母表示在列方向的滤波器向量,第二个字母表示在行方向的滤波器向量。
* Calculate a co-occurrence matrix and derive gray value features thereof * read_image (Image, 'mreut') get_image_size (Image, Width, Height) dev_close_window () dev_open_window (0, 0, Width, Height, 'black', WindowID) dev_display (Image) dev_set_draw ('margin') * Create a rectangle parallel to the coordinate axes gen_rectangle1 (Rectangle1, 350, 100, 450, 200) gen_rectangle1 (Rectangle2, 100, 200, 200, 300) cooc_feature_image (Rectangle1, Image, 6, 0, Energy1, Correlation1, Homogenity1, Contrast1) cooc_feature_image (Rectangle2, Image, 6, 0, Energy2, Correlation2, Homogenity2, Contrast2)
* Find textured areas (trees and bushes) * dev_close_window () Interactive := 0 dev_close_window () read_image (MreutHill, 'mreut_y') get_image_size (MreutHill, Width, Height) dev_open_window (0, 0, Width, Height, 'black', WindowHandle) * Filter an image using a Laws texture filter 使用Laws纹理过滤器过滤图像 texture_laws (MreutHill, SS, 'ss', 0, 5) texture_laws (MreutHill, EE, 'ee', 2, 5) * Separated median filtering with rectangular masks 使用矩形掩膜进行中值滤波 median_separate (SS, SSMed, 25, 25, 'mirrored') median_separate (EE, EEMed, 25, 25, 'mirrored') dev_display (MreutHill) if (Interactive) draw_region (TestReg, WindowHandle) else gen_rectangle1 (TestReg, 376, 221, 466, 246) endif * Calculate the histogram of two-channel gray value images 计算双维度灰度值图像的直方图 histo_2dim (TestReg, SSMed, EEMed, Histo2Dim) threshold (Histo2Dim, RegionFeat, 3, 1000000) fill_up (RegionFeat, RegionFillUpFeat) opening_circle (RegionFillUpFeat, FeatOpen, 1.5) dilation_circle (FeatOpen, FeatureSpace, 1.5) * Segment an image 使用二维像素分类对图像进行分割 class_2dim_sup (SSMed, EEMed, FeatureSpace, RegionClass) opening_circle (RegionClass, ResultClass2, 3.5) dev_set_color ('red') dev_set_draw ('margin') dev_display (MreutHill) dev_display (ResultClass2) disp_continue_message (WindowHandle, 'black', 'true') stop () * Continue to view textured areas threshold (SSMed, RegionThre, 35, 255) connection (RegionThre, ConnectedRegions) select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 150.000000, 99999.000000) closing_circle (SelectedRegions, ResultClass1, 3.5) dev_display (MreutHill) dev_display (ResultClass1)
举例3:详情请参见书籍《Halcon机器视觉算法原理与编程实战》,9.3.5 提取图像的纹理特征,gen_cooc_matrix共生矩阵
dev_close_window () *读取输入的图片 read_image (Image, 'data/board') *将输入的彩色图像转为黑白图像 rgb1_to_gray (Image, GrayImage) get_image_size (GrayImage, Width, Height) *创建一个与输入图像同样大小的窗口 dev_open_window (0, 0, Width/4, Height/4, 'black', WindowID) *设定画笔宽度 dev_set_line_width (5) *创建两个窗口用于显示参数计算的结果 dev_open_window (0, 512, 320, 320, 'black', WindowID1) dev_open_window (512, 512, 320, 320, 'black', WindowID2) *分别设置两个矩阵,选择不同的两部分区域 gen_rectangle1 (Rectangle1, 200,10, 380, 190) gen_rectangle1 (Rectangle2, 580, 650, 730, 800) *分别对两个矩形求取灰度共生矩阵Matrix1和Matrix2 gen_cooc_matrix (Rectangle1, GrayImage, Matrix1, 6, 0) gen_cooc_matrix (Rectangle2, GrayImage, Matrix2, 6, 0) *分别对Matrix1和Matrix2提取灰度特征参数 cooc_feature_matrix (Matrix1, Energy1, Correlation1, Homogeneity1, Contrast1) cooc_feature_matrix (Matrix2, Energy2, Correlation2, Homogeneity2, Contrast2) *采取另一种方式,直接对矩阵2的图像求灰度特征参数,结果与上面两步计算出的参数是一致的 cooc_feature_image (Rectangle2, GrayImage, 6, 0, Energy3, Correlation3, Homogeneity3, Contrast3) *显示图像窗口和两个矩形的灰度共生矩阵 dev_set_window (WindowID) dev_set_draw ('margin') dev_display (GrayImage) dev_display (Rectangle1) dev_set_color('yellow') dev_display (Rectangle2) dev_set_window (WindowID1) dev_display (Matrix1) *以字符串的形式,分别在两个矩阵的对应窗口上显示灰度特征值的计算结果 String := ['Energy: ','Correlation: ','Homogeneity: ','Contrast: '] dev_set_color('red') disp_message (WindowID1, String$'-14s' + [Energy1,Correlation1,Homogeneity1,Contrast1]$'6.3f', 'window', 12, 12, 'white', 'false') dev_set_window (WindowID2) dev_display (Matrix2) dev_set_color('yellow') String := ['Energy: ','Correlation: ','Homogeneity: ','Contrast: '] disp_message (WindowID2, String$'-14s' + [Energy2,Correlation2,Homogeneity2,Contrast2]$'6.3f', 'window', 12, 12, 'white', 'false')
举例4:
光滑1
光滑2
光滑3
粗糙1
粗糙2
粗糙3
read_image (Image, '') *ROI gen_rectangle1 (Rectangle, 482.313, 458.083, 847.963, 1001.78) reduce_domain (Image, Rectangle, ImageReduced) crop_domain (ImageReduced, ImagePart) *使用Laws纹理过滤器过滤图像 texture_laws(ImagePart, ImageTexture, 'el', 3, 5) *计算灰度值的平均值和偏差 intensity(ImageTexture, ImageTexture, Mean, Deviation)
本文转载自《https://blog.csdn.net/libaineu2004/article/details/104908287》
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


