Nothing Special   »   [go: up one dir, main page]

CN117576137A - Rock slice image edge detection method based on improved canny algorithm - Google Patents

Rock slice image edge detection method based on improved canny algorithm Download PDF

Info

Publication number
CN117576137A
CN117576137A CN202311614512.2A CN202311614512A CN117576137A CN 117576137 A CN117576137 A CN 117576137A CN 202311614512 A CN202311614512 A CN 202311614512A CN 117576137 A CN117576137 A CN 117576137A
Authority
CN
China
Prior art keywords
image
edge
pixel
point
bird
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311614512.2A
Other languages
Chinese (zh)
Inventor
梁海波
雷雅婷
张禾
邹佳玲
杨海
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Southwest Petroleum University
Original Assignee
Southwest Petroleum University
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Southwest Petroleum University filed Critical Southwest Petroleum University
Priority to CN202311614512.2A priority Critical patent/CN117576137A/en
Publication of CN117576137A publication Critical patent/CN117576137A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T7/00Image analysis
    • G06T7/10Segmentation; Edge detection
    • G06T7/13Edge detection
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/40Image enhancement or restoration using histogram techniques
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/10Image acquisition modality
    • G06T2207/10024Color image
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T2207/00Indexing scheme for image analysis or image enhancement
    • G06T2207/20Special algorithmic details
    • G06T2207/20076Probabilistic image processing

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Image Processing (AREA)

Abstract

The invention discloses a rock slice image edge detection method based on an improved canny algorithm, which comprises the steps of collecting an original rock slice image and performing image processing; establishing and training a canny algorithm edge intelligent detection model based on bird waiting algorithm optimization; searching an optimal threshold of the target image by using the model, so as to obtain an edge image; the Gaussian noise and the spiced salt noise contained in the rock slice image are effectively removed through the median-wiener mixed filter, the interference of the noise on an edge detection result is reduced, meanwhile, the mixed filter is used for replacing the traditional Gaussian filter, the edge of the image can be well reserved, the problem that the Gaussian filter causes blurring of the edge of the image is effectively solved, and as many edge characteristics as possible are reserved; the accuracy, the effectiveness and the self-adaptability of the rock slice image edge detection can be improved; provides a new idea for the research and engineering application of the subsequent rock slice image edge detection.

Description

一种基于改进canny算法的岩石薄片图像边缘检测方法An edge detection method for rock slice images based on improved canny algorithm

技术领域Technical field

本发明涉及图像检测技术领域,具体涉及一种基于改进canny算法的岩石薄片图像边缘检测方法。The invention relates to the field of image detection technology, and specifically relates to an edge detection method for rock slice images based on an improved canny algorithm.

背景技术Background technique

在石油地质勘探行业中,对岩石薄片序列图像进行精确的边缘识别和颗粒分割,是对岩石矿物成分进行分析鉴定的前提。岩石矿物中孔隙、溶蚀和区域结构复杂且无规律,给岩石矿物的边缘提取和颗粒分割造成困难。为了更好地区分岩石矿物的颗粒和边缘,使用数字图像处理技术对岩石薄片图像序列进行边缘提取和颗粒分割。颗粒边缘的精确提取是后期颗粒分割及岩石矿物分析的重要前提,直接影响下一步岩石矿物特性研究、油气藏沉积、储层综合评价的准确性。In the petroleum geological exploration industry, accurate edge identification and particle segmentation of rock thin section sequence images are the prerequisite for the analysis and identification of rock mineral components. The pores, dissolution and regional structures in rock minerals are complex and irregular, which makes edge extraction and particle segmentation of rock minerals difficult. In order to better distinguish the particles and edges of rock minerals, digital image processing technology is used to perform edge extraction and particle segmentation on rock thin section image sequences. The accurate extraction of particle edges is an important prerequisite for later particle segmentation and rock mineral analysis, which directly affects the accuracy of the next step of rock mineral properties research, oil and gas reservoir deposition, and reservoir comprehensive evaluation.

根据查阅的文献,目前现有的图像边缘检测方法大多是基于传统检测方法,如梯度算子方法,仅基于颜色、文本和其他低级特征来预测边缘,虽能够一定程度上提取图像边缘,但在噪声抑制、边缘定位和精细边缘的处理仍存在问题。其中,canny算法就是最常用的传统检测方法之一,经过诸多学者改进后,canny算法能够实现较高精度的图像边缘检测,但若用于岩石薄片图像边缘检测仍存在不可忽视的问题,比如:canny算法的首要任务是去噪,岩石薄片图像中岩石颗粒表面纹理复杂,颗粒内部以及边缘附近的噪点较多,特别的,canny算法易受椒盐噪声和高斯噪声干扰,有些文献的改进方法只针对其中一种噪声进行滤波,导致结果受噪声干扰,降低边缘检测精度;针对双阈值检测连接边缘的过程中设置阈值,有些文献采用缺乏自适应性的手动按经验设置阈值方法,有些文献采用OTSU等全局阈值法,但这种方法对岩石薄片图像这种亮度分布不匀的图像无法得到清晰有效的边缘检测结果。According to the literature reviewed, most of the existing image edge detection methods are based on traditional detection methods, such as the gradient operator method, which only predicts edges based on color, text and other low-level features. Although it can extract image edges to a certain extent, it has There are still problems with noise suppression, edge localization and handling of fine edges. Among them, the canny algorithm is one of the most commonly used traditional detection methods. After improvements by many scholars, the canny algorithm can achieve higher-precision image edge detection. However, there are still problems that cannot be ignored if used for edge detection of rock thin slice images, such as: The primary task of the canny algorithm is to remove noise. The surface texture of rock particles in rock thin section images is complex, and there are many noise points inside the particles and near the edges. In particular, the canny algorithm is susceptible to interference from salt-and-pepper noise and Gaussian noise. Some improved methods in the literature only target One of the noises is filtered, causing the results to be interfered by noise and reducing the edge detection accuracy; for setting thresholds in the process of connecting edges in dual-threshold detection, some literature uses a manual threshold setting method that lacks adaptability and is based on experience, and some literature uses OTSU, etc. Global threshold method, but this method cannot obtain clear and effective edge detection results for images with uneven brightness distribution such as rock slice images.

针对以上问题,提出一种基于改进canny算法的岩石薄片图像边缘检测方法,能够提高岩石薄片图像边缘检测的准确性、有效性和自适应性。In response to the above problems, an edge detection method for rock slice images based on the improved canny algorithm is proposed, which can improve the accuracy, effectiveness and adaptability of edge detection for rock slice images.

发明内容Contents of the invention

本发明的目的在于克服现有技术的缺点,提供一种基于改进canny算法的岩石薄片图像边缘检测方法,包括采集原始岩石薄片图像并进行图像处理;基于候鸟算法优化的canny算法边缘智能检测模型的建立和训练;利用模型寻找目标图像的最佳阈值,从而得到边缘图像;通过中值-维纳混合滤波器实现对岩石薄片图像中含有的高斯噪声和椒盐噪声的有效去除,降低噪音对边缘检测结果的干扰,同时用该混合滤波器替代传统的高斯滤波器,还能很好的保留图像的边缘,有效解决了高斯滤波器会导致图像边缘模糊的问题,保留了尽可能多的边缘特征;能够提高岩石薄片图像边缘检测的准确性、有效性和自适应性;为后续岩石薄片图像边缘检测的研究以及工程应用提供了新的思路。The purpose of the present invention is to overcome the shortcomings of the existing technology and provide an edge detection method for rock slice images based on an improved canny algorithm, which includes collecting original rock slice images and performing image processing; and an intelligent edge detection model based on the canny algorithm optimized by the migratory bird algorithm. Establish and train; use the model to find the optimal threshold of the target image to obtain the edge image; use the median-Wiener hybrid filter to effectively remove Gaussian noise and salt-and-pepper noise contained in rock slice images, reducing noise for edge detection At the same time, using this hybrid filter to replace the traditional Gaussian filter can also well preserve the edges of the image, effectively solving the problem that the Gaussian filter will cause blurred image edges, and retaining as many edge features as possible; It can improve the accuracy, effectiveness and adaptability of edge detection in rock thin section images; it provides new ideas for subsequent research on edge detection in rock thin section images and engineering applications.

为实现以上技术效果,采用如下技术方案:In order to achieve the above technical effects, the following technical solutions are adopted:

一种基于改进canny算法的岩石薄片图像边缘检测方法,包括以下步骤:An edge detection method for rock slice images based on an improved canny algorithm, including the following steps:

步骤S1:采集原始岩石薄片图像,建立特征数据库,并选择训练集和测试集数据;Step S1: Collect original rock slice images, establish a feature database, and select training set and test set data;

步骤S2:原始岩石薄片图像处理,包括以下步骤:Step S2: Original rock slice image processing, including the following steps:

S21:对采集的原始薄片图像灰度化;S21: Grayscale the collected original thin section image;

S22:对灰度图像进行图像空间变换,统一原始图像尺寸大小为512×512像素,获得变换后的图像;S22: Perform image space transformation on the grayscale image, unify the original image size to 512×512 pixels, and obtain the transformed image;

S23:对变换后的图像进行图像增强,获得增强图像;S23: Perform image enhancement on the transformed image to obtain an enhanced image;

步骤S3:建立基于候鸟算法优化的canny算法边缘智能检测模型:Step S3: Establish a canny algorithm edge intelligent detection model based on the migratory bird algorithm optimization:

输入训练集和测试集数据,利用候鸟算法对canny边缘检测算法的高低阈值进行寻优和设定,得到训练后的基于候鸟算法优化后的canny算法边缘智能检测模型;具体包括:Input the training set and test set data, use the migratory bird algorithm to optimize and set the high and low thresholds of the canny edge detection algorithm, and obtain the trained canny algorithm edge intelligent detection model optimized based on the migratory bird algorithm; specifically including:

S31:利用混合滤波器对图像进行滤波处理;S31: Filter the image using a hybrid filter;

S32:计算梯度的模和梯度方向;S32: Calculate the module and gradient direction of the gradient;

S33:对梯度图像进行非极大值抑制;S33: Perform non-maximum suppression on gradient images;

S34:使用寻优后的最佳双阈值进行边缘连接;S34: Use the optimal double threshold after optimization for edge connection;

步骤S4:根据模型得到的最佳高低阈值,得到边缘图像。Step S4: Obtain the edge image based on the best high and low thresholds obtained by the model.

进一步的,所述步骤S21中采用加权平均法,将RGB三个分量以不同的权值进行加权平均得到灰度图,具体为:Further, in step S21, a weighted average method is used to weight and average the three RGB components with different weights to obtain a grayscale image, specifically as follows:

S211:读取原始岩石薄片图像的像素值;S211: Read the pixel value of the original rock slice image;

S212:对每个像素的红、绿、蓝三个分量进行加权平均,得到灰度值;S212: Perform a weighted average of the red, green, and blue components of each pixel to obtain the grayscale value;

S213:将灰度值赋给相应的像素;S213: Assign the gray value to the corresponding pixel;

f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)

其中:f(x,y)表示位于空间位置(x,y)处的像素,该像素的R分量、G分量、B分量值分别为R(x,y)、G(x,y)、B(x,y);Among them: f (x, y) represents the pixel located at the spatial position (x, y). The R component, G component, and B component values of the pixel are R (x, y), G (x, y), and B respectively. (x, y);

S214:输出灰度图像。S214: Output grayscale image.

进一步的,所述步骤S22中图像空间变换方法包括图像的形变处理方法和位变处理方法:位变处理包括图像平移变换、图像镜像变换和图像旋转变换;形变处理包括图像错切变换、裁剪变换、缩放变换。Further, the image space transformation method in step S22 includes an image deformation processing method and a displacement processing method: the displacement processing includes image translation transformation, image mirror transformation and image rotation transformation; the deformation processing includes image miscut transformation and cropping transformation. , scaling transformation.

进一步的,所述缩放变换会改变图像的尺寸大小,通过双立方插值法将灰度图像尺寸统一为512×512像素,其步骤如下:Further, the scaling transformation will change the size of the image, and the grayscale image size is unified to 512×512 pixels through the bicubic interpolation method. The steps are as follows:

S221:假设源图像A大小为m×n,m和n分别为图像的长和宽,缩放后的目标图像B大小为512×512,根据比例得到缩放后图像B上的坐标B(x,y)对应A上的坐标为A(x,y)=A[X×(m/512,),Y×(n/512,)];S221: Assume that the size of the source image A is m×n, m and n are the length and width of the image respectively, the size of the scaled target image B is 512×512, and the coordinates B(x, y) on the scaled image B are obtained according to the ratio. ) corresponds to the coordinates on A as A(x, y)=A[X×(m/512,), Y×(n/512,)];

S222:S221中对应图像A的坐标位置P可能出现小数部分,此时找距离其最近的像素点的整数坐标,设坐标为P(i+u,j+v),其中i,j为整数,u,v为正或负的小数,此时P就是图像B在(X,Y)处对应源图像中的位置,选取离P最近的16个像素点作为计算目标图像目标处像素值的参数;S222: The coordinate position P corresponding to image A in S221 may have a decimal part. At this time, find the integer coordinate of the pixel closest to it. Let the coordinate be P(i+u, j+v), where i and j are integers. u, v are positive or negative decimals. At this time, P is the position of image B in the corresponding source image at (X, Y). The 16 pixels closest to P are selected as parameters for calculating the pixel value of the target image;

S223:举例假设16个像素点构成的4×4的矩阵,S222中找到的目标点P位于(2,2),则16个点的横、纵坐标的取值范围分别是[i-1,i+2],[j-1,j+2],后续计算结果如下;S223: For example, assume a 4×4 matrix composed of 16 pixel points. The target point P found in S222 is located at (2, 2). Then the value ranges of the horizontal and vertical coordinates of the 16 points are [i-1, i+2], [j-1, j+2], the subsequent calculation results are as follows;

S224:计算P点的像素值,公式如下:S224: Calculate the pixel value of point P, the formula is as follows:

其中:w(x)为权重计算公式,a取值一般为-1、-0.75或-0.5;row为16个像素点的横坐标取值范围;col为16个像素点的纵坐标取值范围;f(i+row,j+col)为16个像素点的原始像素值;F(i+u,j+v)为插值后的P点像素值;w(row-u)为横向距离的权重;w(col-v)为纵向距离的权重。Among them: w(x) is the weight calculation formula, the value of a is generally -1, -0.75 or -0.5; row is the abscissa value range of 16 pixels; col is the ordinate value range of 16 pixels ; f(i+row, j+col) is the original pixel value of 16 pixels; F(i+u, j+v) is the interpolated pixel value of P point; w(row-u) is the lateral distance Weight; w(col-v) is the weight of vertical distance.

进一步的,所述步骤S23中图像增强采用直方图均衡化方法增强图像的对比度,同时预防过拟合,其步骤如下:Further, in step S23, the image enhancement uses a histogram equalization method to enhance the contrast of the image while preventing overfitting. The steps are as follows:

S231:统计原始图像的直方图,计算每个像素值出现的次数,将其归一化到[0,1],得到每个像素值的频率;S231: Count the histogram of the original image, calculate the number of occurrences of each pixel value, normalize it to [0, 1], and obtain the frequency of each pixel value;

S232:计算累计分布函数(CDF),表示每个像素值在原始图像中出现的概率,其公式如下:S232: Calculate the cumulative distribution function (CDF), which represents the probability of each pixel value appearing in the original image. The formula is as follows:

其中:CDF(i)为灰度值i的累积分布;P(j)表示灰度值为j的像素在图像中出现的频率。Among them: CDF(i) is the cumulative distribution of gray value i; P(j) represents the frequency of pixels with gray value j appearing in the image.

S233:计算均衡化后的像素值,将原始图像中的每个像素值映射到一个新的像素值,使得均衡化后的直方图近似为一个均匀分布的直方图;这个映射函数可以通过以下公式计算:S233: Calculate the equalized pixel value, map each pixel value in the original image to a new pixel value, so that the equalized histogram is approximately a uniformly distributed histogram; this mapping function can be calculated by the following formula calculate:

其中:H(i)表示映射后的像素值;L表示像素值的范围;CDF(min)表示原始图像中的最小像素值的累积分布;CDF(i)为灰度值i的累积分布;round用于四舍五入;CDF(i)为灰度值i的累积分布。Among them: H(i) represents the mapped pixel value; L represents the range of pixel values; CDF(min) represents the cumulative distribution of the minimum pixel value in the original image; CDF(i) is the cumulative distribution of the gray value i; round Used for rounding; CDF(i) is the cumulative distribution of gray value i.

进一步的,所述步骤S31中利用混合滤波器对图像进行滤波处理的具体方法为:Further, the specific method of using a hybrid filter to filter the image in step S31 is:

采用中值-维纳混合滤波器对图像中包含的椒盐噪声和高斯噪声进行滤除,中值滤波器可以很好的滤除椒盐噪声并且保留图像边缘信息,维纳滤波器能够很好的滤除高斯噪声;所以基于椒盐噪声的灰度值是其领域中的灰度极值点的特征,区分椒盐噪声和有效信号点,对椒盐噪声进行中值滤波,保留信号点,最后再利用维纳滤波对整个图像进行滤波。The median-Wiener hybrid filter is used to filter out the salt-and-pepper noise and Gaussian noise contained in the image. The median filter can filter out the salt-and-pepper noise well and retain the edge information of the image. The Wiener filter can filter out the salt-and-pepper noise well and retain the edge information of the image. Remove Gaussian noise; therefore, the gray value based on salt and pepper noise is the characteristic of the gray extreme point in its field. Distinguish the salt and pepper noise from the effective signal points, perform median filtering on the salt and pepper noise, retain the signal points, and finally use Wiener Filter filters the entire image.

进一步的,所述步骤S32中采用sobel算子计算梯度的模,具体公式如下:Further, in step S32, the sobel operator is used to calculate the module of the gradient. The specific formula is as follows:

式中:Sx和Sy是sobel算子;Gx是图像x方向上的像素梯度矩阵;Gy是图像y方向上的像素梯度矩阵;I为灰度图像矩阵;此处的*表示互相关运算,且图像矩阵坐标系原点在左上角,且x正方向为从左到右,y正方向为从上到下;In the formula: S x and S y are sobel operators; G x is the pixel gradient matrix in the x direction of the image; G y is the pixel gradient matrix in the y direction of the image; I is the grayscale image matrix; * here means mutual Correlation operation, and the origin of the image matrix coordinate system is at the upper left corner, and the positive x direction is from left to right, and the positive y direction is from top to bottom;

式中:M(x,y)表示该像素点的梯度强度;θ(x,y)表示该像素点的梯度方向;Gx是图像x方向上的像素梯度矩阵;Gy是图像y方向上的像素梯度矩阵。In the formula: M (x, y) represents the gradient strength of the pixel; θ (x, y) represents the gradient direction of the pixel; G x is the pixel gradient matrix in the x direction of the image; G y is the y direction of the image pixel gradient matrix.

进一步的,所述步骤S33中对梯度图像进行非极大值抑制的具体方法为:Further, the specific method for performing non-maximum suppression on the gradient image in step S33 is:

比较当前像素的梯度模值和其沿方向的两个邻域像素梯度模值,所述方向为8个区域,每个区域为45°的范围:如果当前像素的梯度模值大于同方向邻域像素梯度模值,则说明该点可能为边缘点,保留该点像素值;否则为伪边缘,对非极大值进行抑制,将该点像素值标记为0。Compare the gradient modulus value of the current pixel with the gradient modulus value of its two neighbor pixels along the direction. The direction is 8 areas, each area is a range of 45°: If the gradient modulus value of the current pixel is greater than the neighborhood in the same direction If the pixel gradient modulus value indicates that the point may be an edge point, the pixel value of the point is retained; otherwise, it is a pseudo edge, and non-maximum values are suppressed and the pixel value of the point is marked as 0.

进一步的,所述步骤S34中使用寻优后的最佳双阈值进行边缘连接的具体方法为:Further, the specific method of using the optimal double threshold after optimization to perform edge connection in step S34 is:

通过非极大值抑制后,非边缘的点均被标记为0,可能的边缘点保留像素值,但是结果中仍包含很多由噪音或其他原因造成的假边缘,此时采用候鸟优化算法对canny算法的双阈值进行寻优和设定,其步骤如下:After non-maximum suppression, non-edge points are marked as 0, and possible edge points retain their pixel values. However, the results still contain many false edges caused by noise or other reasons. At this time, the migratory bird optimization algorithm is used to The double thresholds of the algorithm are optimized and set. The steps are as follows:

S341:初始化种群,初始化领飞鸟个体、跟飞鸟个体、巡回次数K,设置最大迭代次数Umax、巡回次数最大值Kmax,并将种群结构划分为领飞鸟和左、右队列,假设领飞鸟为初始高低阈值TH和TL,其中,固定高低阈值比值为TH:TL=3:1;S341: Initialize the population, initialize the leading bird individual, the following bird individual, the number of tours K, set the maximum number of iterations U max and the maximum number of tours K max , and divide the population structure into the leading bird and the left and right queues. Assume that the leading bird is Initial high and low thresholds TH and TL , where the fixed high and low threshold ratio is TH : TL = 3:1;

S342:领飞鸟进化,领飞鸟搜索自己的邻域解,并用能够获得最佳边缘检测效果的双阈值替换自身,剩下未使用的领域解传递给下一个体;S342: The leader bird evolves. The leader bird searches for its own neighborhood solution and replaces itself with a double threshold that can obtain the best edge detection effect. The remaining unused domain solutions are passed to the next individual;

S343:跟飞鸟进化,跟飞鸟搜索自己的邻域解以及排在自己前面的个体在上一次搜索过程中产生的未使用的邻域解集,并在这些邻域解集中找到能够获得最佳边缘检测效果的双阈值最优解来替换自身,同样,每个跟飞鸟产生的未使用的邻域解传递给下一个体;S343: Follow Feiyao to evolve, search with Feiyao for its own neighborhood solutions and the unused neighborhood solution sets generated by the individuals ahead of itself during the last search process, and find the best edge in these neighborhood solution sets. The double-threshold optimal solution of the detection effect is used to replace itself. Similarly, each unused neighborhood solution generated by the flying bird is passed to the next individual;

S344:判断巡回次数是否达到巡回次数最大值:若巡回次数K≤Kmax,则转到步骤S342;若巡回次数K>Kmax,则转到步骤S345;S344: Determine whether the number of tours reaches the maximum number of tours: if the number of tours K ≤ K max , go to step S342; if the number of tours K > K max , go to step S345;

S345:领飞鸟替换,当巡回次数达到最大值时,将初始领飞鸟移动到队伍的队尾,根据所选双阈值的边缘检测效果,选择初始领飞鸟后方左队列或右队列的跟飞鸟作为新一任的领飞鸟,且初始化巡回次数,然后开始下一次搜索过程;S345: Replacement of the leading bird. When the number of tours reaches the maximum, the initial leading bird is moved to the end of the team. According to the edge detection effect of the selected dual threshold, the following bird in the left queue or the right queue behind the initial leading bird is selected as the new One leader leads the bird, initializes the number of tours, and then starts the next search process;

S346:判断迭代次数是否达到最大迭代次数最大值:若迭代次数U≤Umax,则转到步骤S342;若迭代次数U>Umax,表示此时种群中的领飞鸟指代的双阈值为全局最优高阈值TH和全局最优低阈值TL,满足终止条件;S346: Determine whether the number of iterations reaches the maximum number of iterations: if the number of iterations U≤U max , go to step S342; if the number of iterations U>U max , it means that the double threshold of the leader bird reference in the population is global at this time The optimal high threshold T H and the global optimal low threshold T L satisfy the termination condition;

S347:选取S346优选的最佳高低阈值TH和TL,判断:令点(x,y),gN(x,y)是对图像进行非极大值抑制后的图像中点(x,y)的像素值,如果该点像素值gN(x,y)≥TH,则该点被标为强边缘点,即该点一定是边缘上的点;gN(x,y)<TL,则该点一定不是边缘上的点,将其抑制;TL≤gN(x,y)<TH,则被标记为弱边缘点,判断该点的8邻域中是否有高于高阈值的像素,如果有,那么该点就是边缘点,否则就不是边缘点。S347: Select the best high and low thresholds T H and T L selected in S346, and judge: Let the point (x, y), g N (x, y) be the image midpoint (x, y) after non-maximum suppression of the image. y), if the pixel value g N (x, y) ≥ T H , the point is marked as a strong edge point, that is, the point must be a point on the edge; g N (x, y) < T L , then the point must not be a point on the edge, and suppress it; T L ≤ g N (x, y) < T H , then it is marked as a weak edge point, and it is judged whether there are high-level points in the 8 neighborhoods of the point. If there is a pixel with a high threshold, then the point is an edge point, otherwise it is not an edge point.

本发明的有益效果为:The beneficial effects of the present invention are:

本发明提供的一种基于改进canny算法的岩石薄片图像边缘检测方法,相比于现有的技术方案具有以下的特点:通过中值-维纳混合滤波器实现对岩石薄片图像中含有的高斯噪声和椒盐噪声的有效去除,降低噪音对边缘检测结果的干扰,同时用该混合滤波器替代传统的高斯滤波器,还能很好的保留图像的边缘,有效解决了高斯滤波器会导致图像边缘模糊会的问题,保留了尽可能多的边缘特征;通过候鸟算法对canny算法的双阈值进行自动寻优和设定,增强算法的自适应性,提高边缘检测结果的精度。The present invention provides an edge detection method for rock slice images based on an improved canny algorithm. Compared with the existing technical solutions, the invention has the following characteristics: the Gaussian noise contained in the rock slice image is detected through a median-Wiener hybrid filter. The effective removal of salt and pepper noise reduces the interference of noise on edge detection results. At the same time, using this hybrid filter to replace the traditional Gaussian filter can also well retain the edges of the image, effectively solving the problem that the Gaussian filter will cause blurred image edges. solve the problem and retain as many edge features as possible; the migratory bird algorithm is used to automatically optimize and set the double threshold of the canny algorithm to enhance the adaptability of the algorithm and improve the accuracy of edge detection results.

附图说明Description of the drawings

图1为本发明实施例提供的一种基于改进canny算法的岩石薄片图像边缘检测方法的流程图;Figure 1 is a flow chart of a rock thin section image edge detection method based on an improved canny algorithm provided by an embodiment of the present invention;

图2为本发明实施例提供的基于候鸟算法优化的canny算法边缘智能检测模型训练流程图。Figure 2 is a training flow chart of the canny algorithm edge intelligent detection model based on the optimization of the migratory bird algorithm provided by the embodiment of the present invention.

具体实施方式Detailed ways

为了使本发明的目的、技术方案及优点更加清楚明白,以下结合实施例,对本发明进行进一步详细说明。应当理解,此处所描述的具体实施例仅仅用以解释本发明,并不用于限定本发明。In order to make the purpose, technical solutions and advantages of the present invention clearer, the present invention will be further described in detail below in conjunction with examples. It should be understood that the specific embodiments described here are only used to explain the present invention and are not intended to limit the present invention.

应该指出,以下详细说明都是示例性的,旨在对本发明提供进一步的说明。除非另有指明,本文使用的所有技术和科学术语具有与本发明所属技术领域的普通技术人员通常理解的相同含义。It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the present invention. Unless defined otherwise, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention belongs.

需要注意的是,这里所使用的术语仅是为了描述具体实施方式,而非意图限制根据本发明的示例性实施方式。如在这里所使用的,除非上下文另外明确指出,否则单数形式也意图包括复数形式,此外,还应当理解的是,当在本说明书中使用术语“包含”和/或“包括”时,其指明存在特征、步骤、操作和/或它们的组合。It should be noted that the terms used herein are for the purpose of describing specific embodiments only, and are not intended to limit the exemplary embodiments according to the present invention. As used herein, the singular forms are also intended to include the plural forms unless the context clearly indicates otherwise. Furthermore, it will be understood that when the terms "comprises" and/or "includes" are used in this specification, they indicate There are features, steps, operations and/or combinations thereof.

实施例1:Example 1:

如图1所示,本发明提供的一种基于改进canny算法的岩石薄片图像边缘检测方法,包括以下步骤:As shown in Figure 1, the present invention provides a rock slice image edge detection method based on an improved canny algorithm, including the following steps:

步骤S1:采集原始岩石薄片图像,建立特征数据库,并选择训练集和测试集数据;Step S1: Collect original rock slice images, establish a feature database, and select training set and test set data;

步骤S2:原始岩石薄片图像处理,包括以下步骤:Step S2: Original rock slice image processing, including the following steps:

S21:对采集的原始薄片图像灰度化;S21: Grayscale the collected original thin section image;

所述步骤S21中采用加权平均法,将RGB三个分量以不同的权值进行加权平均得到灰度图,具体为:In step S21, a weighted average method is used to weight and average the three RGB components with different weights to obtain a grayscale image, specifically as follows:

S211:读取原始岩石薄片图像的像素值;S211: Read the pixel value of the original rock slice image;

S212:对每个像素的红、绿、蓝三个分量进行加权平均,得到灰度值;S212: Perform a weighted average of the red, green, and blue components of each pixel to obtain the grayscale value;

S213:将灰度值赋给相应的像素;S213: Assign the gray value to the corresponding pixel;

f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)

其中:f(x,y)表示位于空间位置(x,y)处的像素,该像素的R分量、G分量、B分量值分别为R(x,y)、G(x,y)、B(x,y);Among them: f (x, y) represents the pixel located at the spatial position (x, y). The R component, G component, and B component values of the pixel are R (x, y), G (x, y), and B respectively. (x, y);

S214:输出灰度图像。S214: Output grayscale image.

S22:对灰度图像进行图像空间变换,统一原始图像尺寸大小为512×512像素,获得变换后的图像;S22: Perform image space transformation on the grayscale image, unify the original image size to 512×512 pixels, and obtain the transformed image;

所述步骤S22中图像空间变换方法包括图像的形变处理方法和位变处理方法:位变处理包括图像平移变换、图像镜像变换和图像旋转变换;形变处理包括图像错切变换、裁剪变换、缩放变换。The image space transformation method in step S22 includes an image deformation processing method and a displacement processing method: the displacement processing includes image translation transformation, image mirror transformation and image rotation transformation; the deformation processing includes image miscut transformation, cropping transformation, and scaling transformation. .

所述缩放变换会改变图像的尺寸大小,通过双立方插值法将灰度图像尺寸统一为512×512像素,其步骤如下:The scaling transformation will change the size of the image, and the grayscale image size is unified to 512×512 pixels through the bicubic interpolation method. The steps are as follows:

S221:假设源图像A大小为m×n,m和n分别为图像的长和宽,缩放后的目标图像B大小为512×512,根据比例得到缩放后图像B上的坐标B(x,y)对应A上的坐标为A(x,y)=A[X×(m/512,),Y×(n/512,)];S221: Assume that the size of the source image A is m×n, m and n are the length and width of the image respectively, the size of the scaled target image B is 512×512, and the coordinates B(x, y) on the scaled image B are obtained according to the ratio. ) corresponds to the coordinates on A as A(x, y)=A[X×(m/512,), Y×(n/512,)];

S222:S221中对应图像A的坐标位置P可能出现小数部分,此时找距离其最近的像素点的整数坐标,设坐标为P(i+u,j+v),其中i,j为整数,u,v为正或负的小数,此时P就是图像B在(X,Y)处对应源图像中的位置,选取离P最近的16个像素点作为计算目标图像目标处像素值的参数;S222: The coordinate position P corresponding to image A in S221 may have a decimal part. At this time, find the integer coordinate of the pixel closest to it. Let the coordinate be P(i+u, j+v), where i and j are integers. u, v are positive or negative decimals. At this time, P is the position of image B in the corresponding source image at (X, Y). The 16 pixels closest to P are selected as parameters for calculating the pixel value of the target image;

S223:举例假设16个像素点构成的4×4的矩阵,S222中找到的目标点P位于(2,2),则16个点的横、纵坐标的取值范围分别是[i-1,i+2],[j-1,j+2],后续计算结果如下;S223: For example, assume a 4×4 matrix composed of 16 pixel points. The target point P found in S222 is located at (2, 2). Then the value ranges of the horizontal and vertical coordinates of the 16 points are [i-1, i+2], [j-1, j+2], the subsequent calculation results are as follows;

S224:计算P点的像素值,公式如下:S224: Calculate the pixel value of point P, the formula is as follows:

其中:w(x)为权重计算公式,a取值一般为-1、-0.75或-0.5;row为16个像素点的横坐标取值范围;col为16个像素点的纵坐标取值范围;f(i+row,j+col)为16个像素点的原始像素值;F(i+u,j+v)为插值后的P点像素值;w(row-u)为横向距离的权重;w(col-v)为纵向距离的权重。Among them: w(x) is the weight calculation formula, the value of a is generally -1, -0.75 or -0.5; row is the abscissa value range of 16 pixels; col is the ordinate value range of 16 pixels ; f(i+row, j+col) is the original pixel value of 16 pixels; F(i+u, j+v) is the interpolated pixel value of P point; w(row-u) is the lateral distance Weight; w(col-v) is the weight of vertical distance.

S23:对变换后的图像进行图像增强,获得增强图像;S23: Perform image enhancement on the transformed image to obtain an enhanced image;

所述步骤S23中图像增强采用直方图均衡化方法增强图像的对比度,同时预防过拟合,其步骤如下:In step S23, the image enhancement uses a histogram equalization method to enhance the contrast of the image while preventing overfitting. The steps are as follows:

S231:统计原始图像的直方图,计算每个像素值出现的次数,将其归一化到[0,1],得到每个像素值的频率;S231: Count the histogram of the original image, calculate the number of occurrences of each pixel value, normalize it to [0, 1], and obtain the frequency of each pixel value;

S232:计算累计分布函数(CDF),表示每个像素值在原始图像中出现的概率,其公式如下:S232: Calculate the cumulative distribution function (CDF), which represents the probability of each pixel value appearing in the original image. The formula is as follows:

其中:CDF(i)为灰度值i的累积分布;P(j)表示灰度值为j的像素在图像中出现的频率。Among them: CDF(i) is the cumulative distribution of gray value i; P(j) represents the frequency of pixels with gray value j appearing in the image.

S233:计算均衡化后的像素值,将原始图像中的每个像素值映射到一个新的像素值,使得均衡化后的直方图近似为一个均匀分布的直方图;这个映射函数可以通过以下公式计算:S233: Calculate the equalized pixel value, map each pixel value in the original image to a new pixel value, so that the equalized histogram is approximately a uniformly distributed histogram; this mapping function can be calculated by the following formula calculate:

其中:H(i)表示映射后的像素值;L表示像素值的范围;CDF(min)表示原始图像中的最小像素值的累积分布;CDF(i)为灰度值i的累积分布;round用于四舍五入;CDF(i)为灰度值i的累积分布。Among them: H(i) represents the mapped pixel value; L represents the range of pixel values; CDF(min) represents the cumulative distribution of the minimum pixel value in the original image; CDF(i) is the cumulative distribution of the gray value i; round Used for rounding; CDF(i) is the cumulative distribution of gray value i.

步骤S3:建立基于候鸟算法优化的canny算法边缘智能检测模型:Step S3: Establish a canny algorithm edge intelligent detection model based on the migratory bird algorithm optimization:

输入训练集和测试集数据,利用候鸟算法对canny边缘检测算法的高低阈值进行寻优和设定,得到训练后的基于候鸟算法优化后的canny算法边缘智能检测模型;具体包括:Input the training set and test set data, use the migratory bird algorithm to optimize and set the high and low thresholds of the canny edge detection algorithm, and obtain the trained canny algorithm edge intelligent detection model optimized based on the migratory bird algorithm; specifically including:

S31:利用混合滤波器对图像进行滤波处理;S31: Filter the image using a hybrid filter;

所述步骤S31中利用混合滤波器对图像进行滤波处理的具体方法为:The specific method of filtering the image using a hybrid filter in step S31 is:

采用中值-维纳混合滤波器对图像中包含的椒盐噪声和高斯噪声进行滤除,中值滤波器可以很好的滤除椒盐噪声并且保留图像边缘信息,维纳滤波器能够很好的滤除高斯噪声;所以基于椒盐噪声的灰度值是其领域中的灰度极值点的特征,区分椒盐噪声和有效信号点,对椒盐噪声进行中值滤波,保留信号点,最后再利用维纳滤波对整个图像进行滤波。The median-Wiener hybrid filter is used to filter out the salt-and-pepper noise and Gaussian noise contained in the image. The median filter can filter out the salt-and-pepper noise well and retain the edge information of the image. The Wiener filter can filter out the salt-and-pepper noise well and retain the edge information of the image. Remove Gaussian noise; therefore, the gray value based on salt and pepper noise is the characteristic of the gray extreme point in its field. Distinguish the salt and pepper noise from the effective signal points, perform median filtering on the salt and pepper noise, retain the signal points, and finally use Wiener Filter filters the entire image.

S32:计算梯度的模和梯度方向;S32: Calculate the module and gradient direction of the gradient;

所述步骤S32中采用sobel算子计算梯度的模,具体公式如下:In step S32, the sobel operator is used to calculate the module of the gradient. The specific formula is as follows:

式中:Sx和Sy是sobel算子;Gx是图像x方向上的像素梯度矩阵;Gy是图像y方向上的像素梯度矩阵;I为灰度图像矩阵;此处的*表示互相关运算,且图像矩阵坐标系原点在左上角,且x正方向为从左到右,y正方向为从上到下;In the formula: S x and S y are sobel operators; G x is the pixel gradient matrix in the x direction of the image; G y is the pixel gradient matrix in the y direction of the image; I is the grayscale image matrix; * here means mutual Correlation operation, and the origin of the image matrix coordinate system is at the upper left corner, and the positive x direction is from left to right, and the positive y direction is from top to bottom;

式中:M(x,y)表示该像素点的梯度强度;θ(x,y)表示该像素点的梯度方向;Gx是图像x方向上的像素梯度矩阵;Gy是图像y方向上的像素梯度矩阵In the formula: M (x, y) represents the gradient strength of the pixel; θ (x, y) represents the gradient direction of the pixel; G x is the pixel gradient matrix in the x direction of the image; G y is the y direction of the image pixel gradient matrix

S33:对梯度图像进行非极大值抑制;S33: Perform non-maximum suppression on gradient images;

所述步骤S33中对梯度图像进行非极大值抑制的具体方法为:The specific method for non-maximum suppression of the gradient image in step S33 is:

比较当前像素的梯度模值和其沿方向的两个邻域像素梯度模值,所述方向为8个区域,每个区域为45°的范围:如果当前像素的梯度模值大于同方向邻域像素梯度模值,则说明该点可能为边缘点,保留该点像素值;否则为伪边缘,对非极大值进行抑制,将该点像素值标记为0。Compare the gradient modulus value of the current pixel with the gradient modulus value of its two neighbor pixels along the direction. The direction is 8 areas, each area is a range of 45°: If the gradient modulus value of the current pixel is greater than the neighborhood in the same direction If the pixel gradient modulus value indicates that the point may be an edge point, the pixel value of the point is retained; otherwise, it is a pseudo edge, and non-maximum values are suppressed and the pixel value of the point is marked as 0.

S34:使用寻优后的最佳双阈值进行边缘连接;S34: Use the optimal double threshold after optimization for edge connection;

所述步骤S34中使用寻优后的最佳双阈值进行边缘连接的具体方法为:The specific method of using the optimal double threshold after optimization to perform edge connection in step S34 is:

通过非极大值抑制后,非边缘的点均被标记为0,可能的边缘点保留像素值,但是结果中仍包含很多由噪音或其他原因造成的假边缘,此时采用候鸟优化算法对canny算法的双阈值进行寻优和设定,其步骤如下:After non-maximum suppression, non-edge points are marked as 0, and possible edge points retain their pixel values. However, the results still contain many false edges caused by noise or other reasons. At this time, the migratory bird optimization algorithm is used to The double thresholds of the algorithm are optimized and set. The steps are as follows:

S341:初始化种群,初始化领飞鸟个体、跟飞鸟个体、巡回次数K,设置最大迭代次数Umax、巡回次数最大值Kmax,并将种群结构划分为领飞鸟和左、右队列,假设领飞鸟为初始高低阈值TH和TL,其中,固定高低阈值比值为TH:TL=3:1;S341: Initialize the population, initialize the leading bird individual, the following bird individual, the number of tours K, set the maximum number of iterations U max and the maximum number of tours K max , and divide the population structure into the leading bird and the left and right queues. Assume that the leading bird is Initial high and low thresholds TH and TL , where the fixed high and low threshold ratio is TH : TL = 3:1;

S342:领飞鸟进化,领飞鸟搜索自己的邻域解,并用能够获得最佳边缘检测效果的双阈值替换自身,剩下未使用的领域解传递给下一个体;S342: The leader bird evolves. The leader bird searches for its own neighborhood solution and replaces itself with a double threshold that can obtain the best edge detection effect. The remaining unused domain solutions are passed to the next individual;

S343:跟飞鸟进化,跟飞鸟搜索自己的邻域解以及排在自己前面的个体在上一次搜索过程中产生的未使用的邻域解集,并在这些邻域解集中找到能够获得最佳边缘检测效果的双阈值最优解来替换自身,同样,每个跟飞鸟产生的未使用的邻域解传递给下一个体;S343: Follow Feiyao to evolve, search with Feiyao for its own neighborhood solutions and the unused neighborhood solution sets generated by the individuals ahead of itself during the last search process, and find the best edge in these neighborhood solution sets. The double-threshold optimal solution of the detection effect is used to replace itself. Similarly, each unused neighborhood solution generated by the flying bird is passed to the next individual;

S344:判断巡回次数是否达到巡回次数最大值:若巡回次数K≤Kmax,则转到步骤S342;若巡回次数K>Kmax,则转到步骤S345;S344: Determine whether the number of tours reaches the maximum number of tours: if the number of tours K ≤ K max , go to step S342; if the number of tours K > K max , go to step S345;

S345:领飞鸟替换,当巡回次数达到最大值时,将初始领飞鸟移动到队伍的队尾,根据所选双阈值的边缘检测效果,选择初始领飞鸟后方左队列或右队列的跟飞鸟作为新一任的领飞鸟,且初始化巡回次数,然后开始下一次搜索过程;S345: Replacement of the leading bird. When the number of tours reaches the maximum, the initial leading bird is moved to the end of the team. According to the edge detection effect of the selected dual threshold, the following bird in the left queue or the right queue behind the initial leading bird is selected as the new One leader leads the bird, initializes the number of tours, and then starts the next search process;

S346:判断迭代次数是否达到最大迭代次数最大值:若迭代次数U≤Umax,则转到步骤S342;若迭代次数U>Umax,表示此时种群中的领飞鸟指代的双阈值为全局最优高阈值TH和全局最优低阈值TL,满足终止条件;S346: Determine whether the number of iterations reaches the maximum number of iterations: if the number of iterations U≤U max , go to step S342; if the number of iterations U>U max , it means that the double threshold of the leader bird reference in the population is global at this time The optimal high threshold T H and the global optimal low threshold T L satisfy the termination condition;

S347:选取S346优选的最佳高低阈值TH和TL,判断:令点(x,y),gN(x,y)是对图像进行非极大值抑制后的图像中点(x,y)的像素值,如果该点像素值gN(x,y)≥TH,则该点被标为强边缘点,即该点一定是边缘上的点;该点像素值gN(x,y)<TL,则该点一定不是边缘上的点,将其抑制;TL≤gN(x,y)<TH,则被标记为弱边缘点,判断该点的8邻域中是否有高于高阈值的像素,如果有,那么该点就是边缘点,否则就不是边缘点。S347: Select the best high and low thresholds T H and T L selected in S346, and judge: Let the point (x, y), g N (x, y) be the image midpoint (x, y) after non-maximum suppression of the image. y), if the pixel value g N (x, y) ≥ T H , then the point is marked as a strong edge point, that is, the point must be a point on the edge; the pixel value g N (x , y)<T L , then the point must not be a point on the edge, suppress it; T L ≤ g N (x, y)<T H , then it is marked as a weak edge point, and the 8-neighborhood of the point is determined Is there a pixel in the pixel that is higher than the high threshold? If so, then the point is an edge point, otherwise it is not an edge point.

步骤S4:根据模型得到的最佳高低阈值,得到边缘图像。Step S4: Obtain the edge image based on the best high and low thresholds obtained by the model.

综上所述,本发明公开了一种基于改进canny算法的岩石薄片图像边缘检测方法,包括采集原始岩石薄片图像并进行图像处理;基于候鸟算法优化的canny算法边缘智能检测模型的建立和训练;利用模型寻找目标图像的最佳阈值,从而得到边缘图像;通过中值-维纳混合滤波器实现对岩石薄片图像中含有的高斯噪声和椒盐噪声的有效去除,降低噪音对边缘检测结果的干扰,同时用该混合滤波器替代传统的高斯滤波器,还能很好的保留图像的边缘,有效解决了高斯滤波器会导致图像边缘模糊的问题,保留了尽可能多的边缘特征;能够提高岩石薄片图像边缘检测的准确性、有效性和自适应性;为后续岩石薄片图像边缘检测的研究以及工程应用提供了新的思路。In summary, the present invention discloses an edge detection method for rock slice images based on an improved canny algorithm, which includes collecting original rock slice images and performing image processing; establishing and training an intelligent edge detection model of the canny algorithm based on the optimization of the migratory bird algorithm; Use the model to find the optimal threshold of the target image to obtain the edge image; use the median-Wiener hybrid filter to effectively remove the Gaussian noise and salt-and-pepper noise contained in the rock slice image, reducing the interference of noise on the edge detection results. At the same time, using this hybrid filter to replace the traditional Gaussian filter can also well retain the edges of the image, effectively solving the problem that the Gaussian filter will cause blurred image edges, retaining as many edge features as possible; it can improve rock thin sections The accuracy, effectiveness and adaptability of image edge detection provide new ideas for subsequent research on edge detection of rock thin section images and engineering applications.

至此,本领域技术人员认识到,虽然本文已详尽展示和描述了本发明的实施例,但是,在不脱离本发明精神和范围的情况下,仍可根据本发明公开的内容直接确定或推导符合本发明原理的许多其他变形或修改。因此,本发明的范围应被理解和认定为覆盖了所有这些其他变形或修改。At this point, those skilled in the art realize that although the embodiments of the present invention have been shown and described in detail herein, without departing from the spirit and scope of the present invention, the content of the disclosure of the present invention can still be directly determined or deduced. There are many other variations or modifications of the principles of the invention. Accordingly, the scope of the invention should be understood and deemed to cover all such other variations or modifications.

Claims (9)

1.一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述检测方法包括以下步骤:1. A rock slice image edge detection method based on an improved canny algorithm, characterized in that the detection method includes the following steps: 步骤S1:采集原始岩石薄片图像,建立特征数据库,并选择训练集和测试集数据;Step S1: Collect original rock slice images, establish a feature database, and select training set and test set data; 步骤S2:原始岩石薄片图像处理,包括以下步骤:Step S2: Original rock slice image processing, including the following steps: S21:对采集的原始薄片图像灰度化;S21: Grayscale the collected original thin section images; S22:对灰度图像进行图像空间变换,统一原始图像尺寸大小为512×512像素,获得变换后的图像;S22: Perform image space transformation on the grayscale image, unify the original image size to 512×512 pixels, and obtain the transformed image; S23:对变换后的图像进行图像增强,获得增强图像;S23: Perform image enhancement on the transformed image to obtain an enhanced image; 步骤S3:建立基于候鸟算法优化的canny算法边缘智能检测模型:Step S3: Establish a canny algorithm edge intelligent detection model based on the migratory bird algorithm optimization: 输入训练集和测试集数据,利用候鸟算法对canny边缘检测算法的高低阈值进行寻优和设定,得到训练后的基于候鸟算法优化后的canny算法边缘智能检测模型;具体包括:Input the training set and test set data, use the migratory bird algorithm to optimize and set the high and low thresholds of the canny edge detection algorithm, and obtain the trained canny algorithm edge intelligent detection model optimized based on the migratory bird algorithm; specifically including: S31:利用混合滤波器对图像进行滤波处理;S31: Filter the image using a hybrid filter; S32:计算梯度的模和梯度方向;S32: Calculate the module and gradient direction of the gradient; S33:对梯度图像进行非极大值抑制;S33: Perform non-maximum suppression on gradient images; S34:使用寻优后的最佳双阈值进行边缘连接;S34: Use the optimal double threshold after optimization for edge connection; 步骤S4:根据模型得到的最佳高低阈值,得到边缘图像。Step S4: Obtain the edge image based on the best high and low thresholds obtained by the model. 2.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S21中采用加权平均法,将RGB三个分量以不同的权值进行加权平均得到灰度图,具体为:2. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 1, characterized in that, in step S21, a weighted average method is used to weight the three components of RGB with different weights. Get the grayscale image, specifically: S211:读取原始岩石薄片图像的像素值;S211: Read the pixel value of the original rock slice image; S212:对每个像素的红、绿、蓝三个分量进行加权平均,得到灰度值;S212: Perform a weighted average of the red, green, and blue components of each pixel to obtain the grayscale value; S213:将灰度值赋给相应的像素;S213: Assign the gray value to the corresponding pixel; f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y) 其中:f(x,y)表示位于空间位置(x,y)处的像素,该像素的R分量、G分量、B分量值分别为R(x,y)、G(x,y)、B(x,y);Among them: f (x, y) represents the pixel located at the spatial position (x, y). The R component, G component, and B component values of the pixel are R (x, y), G (x, y), and B respectively. (x, y); S214:输出灰度图像。S214: Output grayscale image. 3.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S22中图像空间变换方法包括图像的形变处理方法和位变处理方法:位变处理包括图像平移变换、图像镜像变换和图像旋转变换;形变处理包括图像错切变换、裁剪变换、缩放变换。3. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 1, characterized in that the image space transformation method in step S22 includes an image deformation processing method and a displacement processing method: displacement processing. The processing includes image translation transformation, image mirror transformation and image rotation transformation; the deformation processing includes image miscut transformation, cropping transformation and scaling transformation. 4.如权利要求3所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述缩放变换会改变图像的尺寸大小,通过双立方插值法将灰度图像尺寸统一为512×512像素,其步骤如下:4. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 3, characterized in that the scaling transformation changes the size of the image, and the grayscale image size is unified by the bicubic interpolation method. 512×512 pixels, the steps are as follows: S221:假设源图像A大小为m×n,m和n分别为图像的长和宽,缩放后的目标图像B大小为512x512,根据比例得到缩放后图像B上的坐标B(x,y)对应A上的坐标为A(x,y)=A[X×(m/512,),Y×(n/512,)];S221: Assume that the size of the source image A is m×n, m and n are the length and width of the image respectively, and the size of the scaled target image B is 512x512. According to the ratio, the corresponding coordinates B(x, y) on the scaled image B are obtained. The coordinates on A are A(x, y)=A[X×(m/512,), Y×(n/512,)]; S222:S221中对应图像A的坐标位置P可能出现小数部分,此时找距离其最近的像素点的整数坐标,设坐标为P(i+u,j+v),其中i,j为整数,u,v为正或负的小数,此时P就是图像B在(X,Y)处对应源图像中的位置,选取离P最近的16个像素点作为计算目标图像目标处像素值的参数;S222: The coordinate position P corresponding to image A in S221 may have a decimal part. At this time, find the integer coordinate of the pixel closest to it. Let the coordinate be P(i+u,j+v), where i and j are integers. u, v are positive or negative decimals. At this time, P is the position of image B in the corresponding source image at (X, Y). The 16 pixels closest to P are selected as parameters for calculating the pixel value of the target image; S223:举例假设16个像素点构成的4×4的矩阵,S222中找到的目标点P位于(2,2),则16个点的横、纵坐标的取值范围分别是[i-1,i+2],[j-1,j+2],其中i,j为整数,后续计算结果如下;S223: For example, assume a 4×4 matrix composed of 16 pixel points. The target point P found in S222 is located at (2,2). Then the value ranges of the horizontal and vertical coordinates of the 16 points are [i-1, i+2],[j-1,j+2], where i and j are integers, and the subsequent calculation results are as follows; S224:计算P点的像素值,公式如下:S224: Calculate the pixel value of point P, the formula is as follows: 其中:w(x)为权重计算公式,a取值一般为-1、-0.75或-0.5;row为16个像素点的横坐标取值范围;col为16个像素点的纵坐标取值范围;f(i+row,j+col)为16个像素点的原始像素值;F(i+u,j+v)为插值后的P点像素值;w(row-u)为横向距离的权重;w(col-v)为纵向距离的权重。Among them: w(x) is the weight calculation formula, the value of a is generally -1, -0.75 or -0.5; row is the abscissa value range of 16 pixels; col is the ordinate value range of 16 pixels ; f(i+row,j+col) is the original pixel value of 16 pixels; F(i+u,j+v) is the interpolated pixel value of P point; w(row-u) is the lateral distance Weight; w(col-v) is the weight of vertical distance. 5.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S23中图像增强采用直方图均衡化方法增强图像的对比度,同时预防过拟合,其步骤如下:5. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 1, characterized in that the image enhancement in step S23 adopts a histogram equalization method to enhance the contrast of the image while preventing overfitting. , the steps are as follows: S231:统计原始图像的直方图,计算每个像素值出现的次数,将其归一化到[0,1],得到每个像素值的频率;S231: Count the histogram of the original image, calculate the number of occurrences of each pixel value, normalize it to [0, 1], and obtain the frequency of each pixel value; S232:计算累计分布函数(CDF),表示每个像素值在原始图像中出现的概率,其公式如下:S232: Calculate the cumulative distribution function (CDF), which represents the probability of each pixel value appearing in the original image. The formula is as follows: 其中:CDF(i)为灰度值i的累积分布;P(j)表示灰度值为j的像素在图像中出现的频率。Among them: CDF(i) is the cumulative distribution of gray value i; P(j) represents the frequency of pixels with gray value j appearing in the image. S233:计算均衡化后的像素值,将原始图像中的每个像素值映射到一个新的像素值,使得均衡化后的直方图近似为一个均匀分布的直方图;这个映射函数可以通过以下公式计算:S233: Calculate the equalized pixel value, map each pixel value in the original image to a new pixel value, so that the equalized histogram is approximately a uniformly distributed histogram; this mapping function can be expressed by the following formula calculate: 其中:H(i)表示映射后的像素值;L表示像素值的范围;CDF(min)表示原始图像中的最小像素值的累积分布;CDF(i)为灰度值i的累积分布;round用于四舍五入;CDF(i)为灰度值i的累积分布。Among them: H(i) represents the mapped pixel value; L represents the range of pixel values; CDF(min) represents the cumulative distribution of the minimum pixel value in the original image; CDF(i) is the cumulative distribution of the gray value i; round Used for rounding; CDF(i) is the cumulative distribution of gray value i. 6.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S31中利用混合滤波器对图像进行滤波处理的具体方法为:6. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 1, characterized in that the specific method of filtering the image using a hybrid filter in step S31 is: 采用中值—维纳混合滤波器对图像中包含的椒盐噪声和高斯噪声进行滤除,中值滤波器可以很好的滤除椒盐噪声并且保留图像边缘信息,维纳滤波器能够很好的滤除高斯噪声;所以基于椒盐噪声的灰度值是其领域中的灰度极值点的特征,区分椒盐噪声和有效信号点,对椒盐噪声进行中值滤波,保留信号点,最后再利用维纳滤波对整个图像进行滤波。The median-Wiener hybrid filter is used to filter out the salt-and-pepper noise and Gaussian noise contained in the image. The median filter can filter out the salt-and-pepper noise well and retain the edge information of the image. The Wiener filter can filter out the salt-and-pepper noise well and preserve the edge information of the image. Remove Gaussian noise; therefore, the gray value based on salt and pepper noise is the characteristic of the gray extreme point in its field. Distinguish the salt and pepper noise from the effective signal points, perform median filtering on the salt and pepper noise, retain the signal points, and finally use Wiener Filter filters the entire image. 7.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S32中采用sobel算子计算梯度的模,具体公式如下:7. A kind of rock slice image edge detection method based on improved canny algorithm as claimed in claim 1, characterized in that, in the step S32, the sobel operator is used to calculate the module of the gradient, and the specific formula is as follows: 式中:Sx和Sy是sobel算子;Gx是图像x方向上的像素梯度矩阵;Gy是图像y方向上的像素梯度矩阵;I为灰度图像矩阵;此处的*表示互相关运算,且图像矩阵坐标系原点在左上角,且x正方向为从左到右,y正方向为从上到下;In the formula: S x and S y are sobel operators; G x is the pixel gradient matrix in the x direction of the image; G y is the pixel gradient matrix in the y direction of the image; I is the grayscale image matrix; * here means mutual Correlation operation, and the origin of the image matrix coordinate system is at the upper left corner, and the positive x direction is from left to right, and the positive y direction is from top to bottom; 式中:M(x,y)表示该像素点的梯度强度;θ(x,y)表示该像素点的梯度方向;Gx是图像x方向上的像素梯度矩阵;Gy是图像y方向上的像素梯度矩阵。In the formula: M (x, y) represents the gradient strength of the pixel; θ (x, y) represents the gradient direction of the pixel; G x is the pixel gradient matrix in the x direction of the image; G y is the y direction of the image pixel gradient matrix. 8.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S33中对梯度图像进行非极大值抑制的具体方法为:8. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 1, characterized in that the specific method for non-maximum suppression of the gradient image in step S33 is: 比较当前像素的梯度模值和其沿方向的两个邻域像素梯度模值,所述方向为8个区域,每个区域为45°的范围:如果当前像素的梯度模值大于同方向邻域像素梯度模值,则说明该点可能为边缘点,保留该点像素值;否则为伪边缘,对非极大值进行抑制,将该点像素值标记为0。Compare the gradient modulus value of the current pixel with the gradient modulus value of its two neighbor pixels along the direction. The direction is 8 areas, each area is a range of 45°: If the gradient modulus value of the current pixel is greater than the neighborhood in the same direction If the pixel gradient modulus value indicates that the point may be an edge point, the pixel value of the point is retained; otherwise, it is a pseudo edge, and non-maximum values are suppressed and the pixel value of the point is marked as 0. 9.如权利要求1所述的一种基于改进canny算法的岩石薄片图像边缘检测方法,其特征在于,所述步骤S34中使用寻优后的最佳双阈值进行边缘连接的具体方法为:9. A rock slice image edge detection method based on an improved canny algorithm as claimed in claim 1, characterized in that the specific method for edge connection using the optimal double threshold after optimization in step S34 is: 通过非极大值抑制后,非边缘的点均被标记为0,可能的边缘点保留像素值,但是结果中仍包含很多由噪音或其他原因造成的假边缘,此时采用候鸟优化算法对canny算法的双阈值进行寻优和设定,其步骤如下:After non-maximum suppression, non-edge points are marked as 0, and possible edge points retain their pixel values. However, the results still contain many false edges caused by noise or other reasons. At this time, the migratory bird optimization algorithm is used to The double thresholds of the algorithm are optimized and set. The steps are as follows: S341:初始化种群,初始化领飞鸟个体、跟飞鸟个体、巡回次数K,设置最大迭代次数Umax、巡回次数最大值Kmax,并将种群结构划分为领飞鸟和左、右队列,假设领飞鸟为初始高低阈值TH和TL,其中,固定高低阈值比值为TH∶TL=3∶1;S341: Initialize the population, initialize the leading bird individual, the following bird individual, the number of tours K, set the maximum number of iterations U max and the maximum number of tours K max , and divide the population structure into the leading bird and the left and right queues. Assume that the leading bird is Initial high and low thresholds TH and TL , where the fixed high and low threshold ratio is TH:TL = 3:1; S342:领飞鸟进化,领飞鸟搜索自己的邻域解,并用能够获得最佳边缘检测效果的双阈值替换自身,剩下未使用的领域解传递给下一个体;S342: The leader bird evolves. The leader bird searches for its own neighborhood solution and replaces itself with a double threshold that can obtain the best edge detection effect. The remaining unused domain solutions are passed to the next individual; S343:跟飞鸟进化,跟飞鸟搜索自己的邻域解以及排在自己前面的个体在上一次搜索过程中产生的未使用的邻域解集,并在这些邻域解集中找到能够获得最佳边缘检测效果的双阈值最优解来替换自身,同样,每个跟飞鸟产生的未使用的邻域解传递给下一个体;S343: Follow Feiyao to evolve, search with Feiyao for its own neighborhood solutions and the unused neighborhood solution sets generated by the individuals ahead of itself during the last search process, and find the best edge in these neighborhood solution sets. The double-threshold optimal solution of the detection effect is used to replace itself. Similarly, each unused neighborhood solution generated by the flying bird is passed to the next individual; S344:判断巡回次数是否达到巡回次数最大值:若巡回次数K≤Kmax,则转到步骤S342;若巡回次数K≤Kmax,则转到步骤S345;S344: Determine whether the number of tours reaches the maximum number of tours: if the number of tours K ≤ K max , go to step S342; if the number of tours K ≤ K max , go to step S345; S345:领飞鸟替换,当巡回次数达到最大值时,将初始领飞鸟移动到队伍的队尾,根据所选双阈值的边缘检测效果,选择初始领飞鸟后方左队列或右队列的跟飞鸟作为新一任的领飞鸟,且初始化巡回次数,然后开始下一次搜索过程;S345: Replacement of the leading bird. When the number of tours reaches the maximum value, the initial leading bird is moved to the end of the team. According to the edge detection effect of the selected dual threshold, the following bird in the left queue or the right queue behind the initial leading bird is selected as the new One leader leads the bird, initializes the number of tours, and then starts the next search process; S346:判断迭代次数是否达到最大迭代次数最大值:若迭代次数U≤Umax,则转到步骤S342;若迭代次数U≤Umax,表示此时种群中的领飞鸟指代的双阈值为全局最优高阈值TH和全局最优低阈值TL,满足终止条件;S346: Determine whether the number of iterations reaches the maximum number of iterations: if the number of iterations U ≤ U max , go to step S342; if the number of iterations U ≤ U max , it means that the double threshold of the leading bird in the population is global at this time. The optimal high threshold T H and the global optimal low threshold T L satisfy the termination condition; S347:选取S346优选的最佳高低阈值TH和TL,判断:令点(x,y),gN(x,y)是对图像进行非极大值抑制后的图像中点(x,y)的像素值,如果该点像素值gN(x,y)≥TH,则该点被标为强边缘点,即该点一定是边缘上的点;gN(x,y)<TL,则该点一定不是边缘上的点,将其抑制;TL<gN(x,y)<TH,则被标记为弱边缘点,判断该点的8邻域中是否有高于高阈值的像素,如果有,那么该点就是边缘点,否则就不是边缘点。S347: Select the best high and low thresholds T H and T L selected in S346, and judge: Let the points (x, y), g N (x, y) be the image midpoint (x, y) after non-maximum suppression of the image. y), if the pixel value g N (x, y) ≥ T H , the point is marked as a strong edge point, that is, the point must be a point on the edge; g N (x, y) < T L , then the point must not be a point on the edge, and suppress it; T L <g N (x, y) < T H , then it is marked as a weak edge point, and it is judged whether there is a high point in the 8 neighborhoods of the point If there is a pixel with a high threshold, then the point is an edge point, otherwise it is not an edge point.
CN202311614512.2A 2023-11-28 2023-11-28 Rock slice image edge detection method based on improved canny algorithm Pending CN117576137A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311614512.2A CN117576137A (en) 2023-11-28 2023-11-28 Rock slice image edge detection method based on improved canny algorithm

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311614512.2A CN117576137A (en) 2023-11-28 2023-11-28 Rock slice image edge detection method based on improved canny algorithm

Publications (1)

Publication Number Publication Date
CN117576137A true CN117576137A (en) 2024-02-20

Family

ID=89891516

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311614512.2A Pending CN117576137A (en) 2023-11-28 2023-11-28 Rock slice image edge detection method based on improved canny algorithm

Country Status (1)

Country Link
CN (1) CN117576137A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118570072A (en) * 2024-08-01 2024-08-30 宝鸡拓普达钛业有限公司 Burr detection method and system in titanium metal processing process

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN118570072A (en) * 2024-08-01 2024-08-30 宝鸡拓普达钛业有限公司 Burr detection method and system in titanium metal processing process
CN118570072B (en) * 2024-08-01 2024-11-22 宝鸡拓普达钛业有限公司 A burr detection method and system during titanium metal processing

Similar Documents

Publication Publication Date Title
CN114399522B (en) An edge detection method based on Canny operator with high and low thresholds
CN112036254B (en) Moving vehicle foreground detection method based on video image
CN110008954B (en) A method and system for extracting complex background text images based on multi-threshold fusion
CN111260616A (en) Insulator crack detection method based on Canny operator two-dimensional threshold segmentation optimization
WO2022099598A1 (en) Video dynamic target detection method based on relative statistical features of image pixels
CN110033471A (en) A kind of wire detection method based on connected domain analysis and morphological operation
WO2021109697A1 (en) Character segmentation method and apparatus, and computer-readable storage medium
US7574304B2 (en) Chromatin segmentation
CN105654445A (en) Mobile phone image denoising method based on wavelet transform edge detection
CN111369570B (en) Multi-target detection tracking method for video image
CN114677601A (en) Dam crack detection method based on unmanned aerial vehicle inspection and combined with deep learning
CN109975196B (en) A kind of reticulocyte detection method and system thereof
CN104751422B (en) A kind of photocopy file and picture strengthens and binarization method
CN111127498B (en) Canny edge detection method based on edge self-growth
CN112200742A (en) Filtering and denoising method applied to edge detection
CN106934819A (en) A kind of method of moving object segmentation precision in raising image
CN117576137A (en) Rock slice image edge detection method based on improved canny algorithm
CN111539980A (en) Multi-target tracking method based on visible light
CN112017109B (en) Online ferrographic video image bubble elimination method
CN107992875B (en) A kind of well-marked target detection method based on image bandpass filtering
CN114677525B (en) Edge detection method based on binary image processing
CN114519694A (en) Seven-segment digital tube liquid crystal display screen identification method and system based on deep learning
CN113516627A (en) Device and method for detecting foreign matter in wine bottle
EP4332879A1 (en) Method and apparatus for processing graphic symbol, and computer-readable storage medium
CN117765287A (en) Image target extraction method combining LWR and density clustering

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination