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 PDFInfo
- 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
- value
- 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
Links
- 238000004422 calculation algorithm Methods 0.000 title claims abstract description 60
- 238000000034 method Methods 0.000 title claims abstract description 60
- 239000011435 rock Substances 0.000 title claims abstract description 55
- 238000003708 edge detection Methods 0.000 title claims abstract description 43
- 150000003839 salts Chemical class 0.000 claims abstract description 20
- 238000012545 processing Methods 0.000 claims abstract description 15
- 238000001514 detection method Methods 0.000 claims abstract description 14
- 238000005457 optimization Methods 0.000 claims abstract description 10
- 238000012549 training Methods 0.000 claims abstract description 10
- 230000009466 transformation Effects 0.000 claims description 27
- 239000011159 matrix material Substances 0.000 claims description 21
- 235000002566 Capsicum Nutrition 0.000 claims description 16
- 239000006002 Pepper Substances 0.000 claims description 16
- 241000722363 Piper Species 0.000 claims description 16
- 235000016761 Piper aduncum Nutrition 0.000 claims description 16
- 235000017804 Piper guineense Nutrition 0.000 claims description 16
- 235000008184 Piper nigrum Nutrition 0.000 claims description 16
- 230000001186 cumulative effect Effects 0.000 claims description 15
- 230000001629 suppression Effects 0.000 claims description 13
- 238000001914 filtration Methods 0.000 claims description 12
- 230000000694 effects Effects 0.000 claims description 10
- 238000004364 calculation method Methods 0.000 claims description 6
- 238000013507 mapping Methods 0.000 claims description 6
- 238000003672 processing method Methods 0.000 claims description 6
- 238000012360 testing method Methods 0.000 claims description 6
- 238000005315 distribution function Methods 0.000 claims description 3
- 238000011426 transformation method Methods 0.000 claims description 3
- 238000013519 translation Methods 0.000 claims description 3
- 238000011160 research Methods 0.000 abstract description 4
- 239000002245 particle Substances 0.000 description 8
- 229910052500 inorganic mineral Inorganic materials 0.000 description 6
- 239000011707 mineral Substances 0.000 description 6
- 230000011218 segmentation Effects 0.000 description 4
- 238000000605 extraction Methods 0.000 description 3
- 238000004458 analytical method Methods 0.000 description 2
- 238000012986 modification Methods 0.000 description 2
- 230000004048 modification Effects 0.000 description 2
- 230000009286 beneficial effect Effects 0.000 description 1
- 239000003086 colorant Substances 0.000 description 1
- 230000007547 defect Effects 0.000 description 1
- 230000008021 deposition Effects 0.000 description 1
- 230000009977 dual effect Effects 0.000 description 1
- 230000003628 erosive effect Effects 0.000 description 1
- 238000011156 evaluation Methods 0.000 description 1
- 230000001788 irregular Effects 0.000 description 1
- 239000003208 petroleum Substances 0.000 description 1
- 239000011148 porous material Substances 0.000 description 1
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T7/00—Image analysis
- G06T7/10—Segmentation; Edge detection
- G06T7/13—Edge detection
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T5/00—Image enhancement or restoration
- G06T5/40—Image enhancement or restoration using histogram techniques
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/10—Image acquisition modality
- G06T2207/10024—Color image
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06T—IMAGE DATA PROCESSING OR GENERATION, IN GENERAL
- G06T2207/00—Indexing scheme for image analysis or image enhancement
- G06T2207/20—Special algorithmic details
- G06T2207/20076—Probabilistic 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
Technical Field
The invention relates to the technical field of image detection, in particular to a rock slice image edge detection method based on an improved canny algorithm.
Background
In the petroleum geological exploration industry, accurate edge recognition and particle segmentation are performed on rock slice sequence images, which are the preconditions for analysis and identification of rock mineral components. The pores, erosion and area structures in the rock minerals are complex and irregular, which makes difficult the edge extraction and particle segmentation of the rock minerals. To better distinguish between particles and edges of rock minerals, edge extraction and particle segmentation are performed on a sequence of rock slice images using digital image processing techniques. The accurate extraction of the particle edges is an important precondition for later particle segmentation and rock mineral analysis, and directly influences the accuracy of the next rock mineral characteristic research, oil and gas reservoir deposition and reservoir comprehensive evaluation.
According to the reference, the existing image edge detection method is mostly based on the traditional detection method, such as a gradient operator method, and only predicts edges based on colors, texts and other low-level features, and although the image edges can be extracted to a certain extent, problems still exist in noise suppression, edge positioning and fine edge processing. The canny algorithm is one of the most commonly used traditional detection methods, and after many scholars improve, the canny algorithm can realize image edge detection with higher precision, but if the canny algorithm is used for rock slice image edge detection, the problems still exist, such as: the primary task of the canny algorithm is denoising, the surface texture of rock particles in a rock slice image is complex, the number of noise points in the particle and near the edge is large, particularly, the canny algorithm is easily interfered by salt and pepper noise and Gaussian noise, and some improved methods of documents only filter one noise, so that the result is interfered by noise, and the edge detection precision is reduced; the threshold is set in the process of detecting the connecting edge by aiming at the double threshold, some documents adopt a manual experience threshold setting method which lacks adaptivity, and some documents adopt a global threshold method such as OTSU, etc., but the method cannot obtain clear and effective edge detection results on the image with uneven brightness distribution such as the rock slice image.
Aiming at the problems, the rock slice image edge detection method based on the improved canny algorithm is provided, and the accuracy, the effectiveness and the adaptivity of the rock slice image edge detection can be improved.
Disclosure of Invention
The invention aims to overcome the defects of the prior art and provides 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.
In order to achieve the technical effects, the following technical scheme is adopted:
a rock slice image edge detection method based on an improved canny algorithm comprises the following steps:
step S1: collecting original rock slice images, establishing a characteristic database, and selecting training set and testing set data;
step S2: original rock laminate image processing comprising the steps of:
s21: graying the collected original sheet image;
s22: performing image space transformation on the gray level image, unifying the size of the original image to 512 multiplied by 512 pixels, and obtaining a transformed image;
s23: performing image enhancement on the transformed image to obtain an enhanced image;
step S3: establishing a canny algorithm edge intelligent detection model based on bird waiting algorithm optimization:
inputting training set and testing set data, optimizing and setting the high and low threshold values of a canny edge detection algorithm by using a waiting bird algorithm, and obtaining a trained canny algorithm edge intelligent detection model optimized based on the waiting bird algorithm; the method specifically comprises the following steps:
s31: filtering the image by using a hybrid filter;
s32: calculating the mode and gradient direction of the gradient;
s33: performing non-maximum suppression on the gradient image;
s34: performing edge connection by using the optimized optimal double threshold value;
step S4: and obtaining an edge image according to the optimal high and low threshold value obtained by the model.
Further, in the step S21, a weighted average method is adopted to perform weighted average on the three RGB components with different weights to obtain a gray scale map, which specifically includes:
s211: reading pixel values of an original rock laminate image;
s212: carrying out weighted average on the red, green and blue components of each pixel to obtain a gray value;
s213: assigning gray values to the corresponding pixels;
f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)
wherein: f (x, y) represents a pixel located at a spatial position (x, y), the R, G, B component values of the pixel being R (x, y), G (x, y), B (x, y), respectively;
s214: and outputting a gray image.
Further, the image space transformation method in step S22 includes a deformation processing method and a bit transformation processing method of the image: the bit-shift processing includes image translation transformation, image mirror transformation and image rotation transformation; the deformation processing comprises image miscut transformation, clipping transformation and scaling transformation.
Further, the scaling transformation changes the size of the image, and the gray image size is unified to 512×512 pixels by the bicubic interpolation method, which comprises the following steps:
s221: assuming that the size of a source image A is m multiplied by n, m and n are the length and the width of the image respectively, the size of a scaled target image B is 512 multiplied by 512, and coordinates B (X, Y) on the scaled image B corresponding to the coordinates A are A (X, Y) =A [ X multiplied by (m/512), Y multiplied by (n/512) ];
s222: the coordinate position P of the corresponding image a in S221 may have a decimal part, at this time, the integer coordinate of the nearest pixel point is found, the coordinate is set as P (i+u, j+v), where i, j is an integer, u, v is a positive or negative decimal, at this time, P is the position of the image B in the corresponding source image at the (X, Y), and 16 pixel points nearest to P are selected as parameters for calculating the pixel value at the target of the target image;
s223: for example, assuming that the target point P found in S222 is located at (2, 2) in a 4×4 matrix of 16 pixels, the value ranges of the horizontal and vertical coordinates of the 16 points are [ i-1, i+2], [ j-1, j+2], and the subsequent calculation results are as follows;
s224: the pixel value of the P point is calculated as follows:
wherein: w (x) is a weight calculation formula, and the value of a is generally-1, -0.75 or-0.5; row is the abscissa value range of 16 pixel points; col is the ordinate value range of 16 pixel points; f (i+row, j+col) is the original pixel value of 16 pixel points; f (i+u, j+v) is the interpolated P-point pixel value; w (row-u) is the weight of the lateral distance; w (col-v) is the weight of the longitudinal distance.
Further, in the step S23, the image enhancement adopts a histogram equalization method to enhance the contrast of the image, and meanwhile, the overfitting is prevented, and the steps are as follows:
s231: counting the histogram of the original image, calculating the occurrence frequency of each pixel value, and normalizing the occurrence frequency to [0,1] to obtain the frequency of each pixel value;
s232: a Cumulative Distribution Function (CDF) is calculated, representing the probability of each pixel value occurring in the original image, as follows:
wherein: CDF (i) is the cumulative distribution of gray values i; p (j) represents the frequency with which pixels with a gray value j appear in the image.
S233: calculating equalized pixel values, and mapping each pixel value in the original image to a new pixel value, so that the equalized histogram approximates to a uniformly distributed histogram; this mapping function may be calculated by the following formula:
wherein: h (i) represents the mapped pixel value; l represents a range of pixel values; CDF (min) represents the cumulative distribution of the minimum pixel values in the original image; CDF (i) is the cumulative distribution of gray values i; round is used for rounding; CDF (i) is the cumulative distribution of gray values i.
Further, in the step S31, the specific method for performing the filtering processing on the image by using the hybrid filter is as follows:
the method has the advantages that the median-wiener mixed filter is adopted to filter the salt and pepper noise and Gaussian noise contained in the image, the median filter can well filter the salt and pepper noise, the image edge information is reserved, and the wiener filter can well filter the Gaussian noise; therefore, the gray value of the salt and pepper noise is the characteristic of gray extreme points in the field, the salt and pepper noise is distinguished from effective signal points, median filtering is carried out on the salt and pepper noise, the signal points are reserved, and finally, the whole image is filtered by wiener filtering.
Further, in the step S32, a sobel operator is adopted to calculate the modulus of the gradient, and the specific formula is as follows:
wherein: s is S x And S is y Is a sobel operator; g x Is a matrix of pixel gradients in the x-direction of the image; g y Is a matrix of pixel gradients in the y-direction of the image; i is a gray image matrix; here, the x represents a cross correlation operation, and the origin of the coordinate system of the image matrix is at the upper left corner, the positive x direction is from left to right, and the positive y direction is from top to bottom;
wherein: m (x, y) represents the gradient intensity of the pixel point; θ (x, y) represents the gradient direction of the pixel point; g x Is a matrix of pixel gradients in the x-direction of the image; g y Is a matrix of pixel gradients in the y-direction of the image.
Further, the specific method for performing non-maximum suppression on the gradient image in the step S33 is as follows:
comparing the gradient modulus value of the current pixel with the gradient modulus values of two adjacent pixels along the direction, wherein the direction is 8 areas, and each area is in a range of 45 degrees: if the gradient modulus value of the current pixel is larger than the gradient modulus value of the neighboring pixel in the same direction, the point is possibly an edge point, and the pixel value of the point is reserved; otherwise, the pixel value is marked as 0 by suppressing the non-maximum value.
Further, in the step S34, the specific method for performing edge connection by using the optimized optimal dual threshold value is as follows:
after non-maximum suppression, non-edge points are marked as 0, and possible edge points retain pixel values, but the result still contains a lot of false edges caused by noise or other reasons, and at the moment, a bird waiting optimization algorithm is adopted to optimize and set the double threshold value of the canny algorithm, and the method comprises the following steps:
s341: initializing population, initializing individual collar flying birds, individual follow flying birds and number of rounds K, and setting maximum iteration number U max Maximum value K of number of rounds max Dividing the population structure into collar birds and left and right queues, and assuming that the collar birds are initial high and low threshold T H And T L Wherein the fixed high-low threshold ratio is T H :T L =3:1;
S342: the collar flyer evolves, searches for its own neighborhood solution, replaces itself with the double threshold value that can obtain the best edge detection effect, and transmits the remaining unused neighborhood solution to the next individual;
s343: evolving with the flying bird, searching a neighborhood solution of the flying bird and an unused neighborhood solution set generated in the last searching process of individuals arranged in front of the flying bird, finding a double-threshold optimal solution capable of obtaining an optimal edge detection effect in the neighborhood solution sets to replace the flying bird, and transmitting the unused neighborhood solution generated by each flying bird to the next individual;
s344: judging whether the number of rounds reaches the maximum value of the number of rounds: if the number of rounds K is less than or equal to K max Then go to step S342; if the number of rounds K is greater than K max Then go to step S345;
s345: when the number of rounds reaches the maximum value, moving the initial collar flyer to the tail of a team, selecting a left queue or a right queue of heel flyers behind the initial collar flyer as a new collar flyer according to the edge detection effect of the selected double threshold value, initializing the number of rounds, and then starting the next searching process;
s346: judging whether the iteration number reaches the maximum value of the maximum iteration number or not: if the iteration number U is less than or equal to U max Go to stepStep S342; if the iteration number U is greater than U max The double threshold value of the bird-catching index in the population is the global optimal high threshold value T H And a global optimum low threshold T L The termination condition is satisfied;
s347: selecting S346 a preferred optimal high-low threshold T H And T L Judging: let points (x, y), g N (x, y) is the pixel value of the point (x, y) in the image after non-maximum suppression of the image, if the point pixel value g N (x,y)≥T H The point is marked as a strong edge point, i.e. 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, suppressing it; t (T) L ≤g N (x,y)<T H And marking as a weak edge point, judging whether pixels higher than a high threshold value exist in the 8 neighborhood of the point, if so, judging the point as the edge point, and otherwise, judging the point as not the edge point.
The beneficial effects of the invention are as follows:
compared with the prior art, the rock slice image edge detection method based on the improved canny algorithm has the following characteristics: 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 the 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 the image edge to be blurred is effectively solved, and as many edge characteristics as possible are reserved; and the double thresholds of the canny algorithm are automatically optimized and set through the bird waiting algorithm, so that the self-adaptability of the algorithm is enhanced, and the accuracy of the edge detection result is improved.
Drawings
FIG. 1 is a flow chart of a rock slice image edge detection method based on an improved canny algorithm provided by an embodiment of the invention;
fig. 2 is a training flow chart of a canny algorithm edge intelligent detection model based on bird waiting algorithm optimization provided by the embodiment of the invention.
Detailed Description
The present invention will be described in further detail with reference to the following examples in order to make the objects, technical solutions and advantages of the present invention more apparent. It should be understood that the specific embodiments described herein are for purposes of illustration only and are not intended to limit the scope of the invention.
It should be noted that the following detailed description is exemplary and is intended to provide further explanation of the 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 is noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of exemplary embodiments according to the present invention. As used herein, the singular forms also are intended to include the plural forms unless the context clearly indicates otherwise, and furthermore, it should be understood that when the terms "comprises" and/or "comprising" are used in this specification, they specify the presence of stated features, steps, operations, and/or combinations thereof.
Example 1:
as shown in fig. 1, the rock slice image edge detection method based on the improved canny algorithm provided by the invention comprises the following steps:
step S1: collecting original rock slice images, establishing a characteristic database, and selecting training set and testing set data;
step S2: original rock laminate image processing comprising the steps of:
s21: graying the collected original sheet image;
in the step S21, a weighted average method is adopted to perform weighted average on the three RGB components with different weights to obtain a gray scale map, which specifically includes:
s211: reading pixel values of an original rock laminate image;
s212: carrying out weighted average on the red, green and blue components of each pixel to obtain a gray value;
s213: assigning gray values to the corresponding pixels;
f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)
wherein: f (x, y) represents a pixel located at a spatial position (x, y), the R, G, B component values of the pixel being R (x, y), G (x, y), B (x, y), respectively;
s214: and outputting a gray image.
S22: performing image space transformation on the gray level image, unifying the size of the original image to 512 multiplied by 512 pixels, and obtaining a transformed image;
the image space transformation method in the step S22 includes a deformation processing method and a bit transformation processing method of an image: the bit-shift processing includes image translation transformation, image mirror transformation and image rotation transformation; the deformation processing comprises image miscut transformation, clipping transformation and scaling transformation.
The scaling transformation changes the size of the image, and the gray image size is unified to 512×512 pixels by the bicubic interpolation method, which comprises the following steps:
s221: assuming that the size of a source image A is m multiplied by n, m and n are the length and the width of the image respectively, the size of a scaled target image B is 512 multiplied by 512, and coordinates B (X, Y) on the scaled image B corresponding to the coordinates A are A (X, Y) =A [ X multiplied by (m/512), Y multiplied by (n/512) ];
s222: the coordinate position P of the corresponding image a in S221 may have a decimal part, at this time, the integer coordinate of the nearest pixel point is found, the coordinate is set as P (i+u, j+v), where i, j is an integer, u, v is a positive or negative decimal, at this time, P is the position of the image B in the corresponding source image at the (X, Y), and 16 pixel points nearest to P are selected as parameters for calculating the pixel value at the target of the target image;
s223: for example, assuming that the target point P found in S222 is located at (2, 2) in a 4×4 matrix of 16 pixels, the value ranges of the horizontal and vertical coordinates of the 16 points are [ i-1, i+2], [ j-1, j+2], and the subsequent calculation results are as follows;
s224: the pixel value of the P point is calculated as follows:
wherein: w (x) is a weight calculation formula, and the value of a is generally-1, -0.75 or-0.5; row is the abscissa value range of 16 pixel points; col is the ordinate value range of 16 pixel points; f (i+row, j+col) is the original pixel value of 16 pixel points; f (i+u, j+v) is the interpolated P-point pixel value; w (row-u) is the weight of the lateral distance; w (col-v) is the weight of the longitudinal distance.
S23: performing image enhancement on the transformed image to obtain an enhanced image;
in the step S23, the image enhancement adopts a histogram equalization method to enhance the contrast of the image, and meanwhile, the overfitting is prevented, and the steps are as follows:
s231: counting the histogram of the original image, calculating the occurrence frequency of each pixel value, and normalizing the occurrence frequency to [0,1] to obtain the frequency of each pixel value;
s232: a Cumulative Distribution Function (CDF) is calculated, representing the probability of each pixel value occurring in the original image, as follows:
wherein: CDF (i) is the cumulative distribution of gray values i; p (j) represents the frequency with which pixels with a gray value j appear in the image.
S233: calculating equalized pixel values, and mapping each pixel value in the original image to a new pixel value, so that the equalized histogram approximates to a uniformly distributed histogram; this mapping function may be calculated by the following formula:
wherein: h (i) represents the mapped pixel value; l represents a range of pixel values; CDF (min) represents the cumulative distribution of the minimum pixel values in the original image; CDF (i) is the cumulative distribution of gray values i; round is used for rounding; CDF (i) is the cumulative distribution of gray values i.
Step S3: establishing a canny algorithm edge intelligent detection model based on bird waiting algorithm optimization:
inputting training set and testing set data, optimizing and setting the high and low threshold values of a canny edge detection algorithm by using a waiting bird algorithm, and obtaining a trained canny algorithm edge intelligent detection model optimized based on the waiting bird algorithm; the method specifically comprises the following steps:
s31: filtering the image by using a hybrid filter;
the specific method for filtering the image by using the hybrid filter in the step S31 is as follows:
the method has the advantages that the median-wiener mixed filter is adopted to filter the salt and pepper noise and Gaussian noise contained in the image, the median filter can well filter the salt and pepper noise, the image edge information is reserved, and the wiener filter can well filter the Gaussian noise; therefore, the gray value of the salt and pepper noise is the characteristic of gray extreme points in the field, the salt and pepper noise is distinguished from effective signal points, median filtering is carried out on the salt and pepper noise, the signal points are reserved, and finally, the whole image is filtered by wiener filtering.
S32: calculating the mode and gradient direction of the gradient;
in the step S32, a sobel operator is adopted to calculate the modulus of the gradient, and the specific formula is as follows:
wherein: s is S x And S is y Is a sobel operator; g x Is a matrix of pixel gradients in the x-direction of the image; g y Is an imageA matrix of pixel gradients in the y-direction; i is a gray image matrix; here, the x represents a cross correlation operation, and the origin of the coordinate system of the image matrix is at the upper left corner, the positive x direction is from left to right, and the positive y direction is from top to bottom;
wherein: m (x, y) represents the gradient intensity of the pixel point; θ (x, y) represents the gradient direction of the pixel point; g x Is a matrix of pixel gradients in the x-direction of the image; g y Is a matrix of pixel gradients in the y-direction of the image
S33: performing non-maximum suppression on the gradient image;
the specific method for performing non-maximum suppression on the gradient image in the step S33 is as follows:
comparing the gradient modulus value of the current pixel with the gradient modulus values of two adjacent pixels along the direction, wherein the direction is 8 areas, and each area is in a range of 45 degrees: if the gradient modulus value of the current pixel is larger than the gradient modulus value of the neighboring pixel in the same direction, the point is possibly an edge point, and the pixel value of the point is reserved; otherwise, the pixel value is marked as 0 by suppressing the non-maximum value.
S34: performing edge connection by using the optimized optimal double threshold value;
the specific method for performing edge connection by using the optimized optimal double threshold in the step S34 is as follows:
after non-maximum suppression, non-edge points are marked as 0, and possible edge points retain pixel values, but the result still contains a lot of false edges caused by noise or other reasons, and at the moment, a bird waiting optimization algorithm is adopted to optimize and set the double threshold value of the canny algorithm, and the method comprises the following steps:
s341: initializing population, initializing individual collar flying birds, individual follow flying birds,Number of rounds K, set maximum number of iterations U max Maximum value K of number of rounds max Dividing the population structure into collar birds and left and right queues, and assuming that the collar birds are initial high and low threshold T H And T L Wherein the fixed high-low threshold ratio is T H :T L =3:1;
S342: the collar flyer evolves, searches for its own neighborhood solution, replaces itself with the double threshold value that can obtain the best edge detection effect, and transmits the remaining unused neighborhood solution to the next individual;
s343: evolving with the flying bird, searching a neighborhood solution of the flying bird and an unused neighborhood solution set generated in the last searching process of individuals arranged in front of the flying bird, finding a double-threshold optimal solution capable of obtaining an optimal edge detection effect in the neighborhood solution sets to replace the flying bird, and transmitting the unused neighborhood solution generated by each flying bird to the next individual;
s344: judging whether the number of rounds reaches the maximum value of the number of rounds: if the number of rounds K is less than or equal to K max Then go to step S342; if the number of rounds K is greater than K max Then go to step S345;
s345: when the number of rounds reaches the maximum value, moving the initial collar flyer to the tail of a team, selecting a left queue or a right queue of heel flyers behind the initial collar flyer as a new collar flyer according to the edge detection effect of the selected double threshold value, initializing the number of rounds, and then starting the next searching process;
s346: judging whether the iteration number reaches the maximum value of the maximum iteration number or not: if the iteration number U is less than or equal to U max Then go to step S342; if the iteration number U is greater than U max The double threshold value of the bird-catching index in the population is the global optimal high threshold value T H And a global optimum low threshold T L The termination condition is satisfied;
s347: selecting S346 a preferred optimal high-low threshold T H And T L Judging: let points (x, y), g N (x, y) is the pixel value of the point (x, y) in the image after non-maximum suppression of the image, if the point pixel valueg N (x,y)≥T H The point is marked as a strong edge point, i.e. the point must be a point on the edge; the dot pixel value g N (x,y)<T L Then the point must not be a point on the edge, suppressing it; t (T) L ≤g N (x,y)<T H And marking as a weak edge point, judging whether pixels higher than a high threshold value exist in the 8 neighborhood of the point, if so, judging the point as the edge point, and otherwise, judging the point as not the edge point.
Step S4: and obtaining an edge image according to the optimal high and low threshold value obtained by the model.
In summary, 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.
So far, those skilled in the art will recognize that while embodiments of the present invention have been shown and described in detail herein, many other variations or modifications that are in accordance with the principles of the present invention may be directly ascertained or inferred from the present disclosure without departing from the spirit and scope of the present invention. Accordingly, the scope of the present invention should be understood and deemed to cover all such other variations or modifications.
Claims (9)
1. A rock laminate image edge detection method based on an improved canny algorithm, the detection method comprising the steps of:
step S1: collecting original rock slice images, establishing a characteristic database, and selecting training set and testing set data;
step S2: original rock laminate image processing comprising the steps of:
s21: graying the collected original sheet image;
s22: performing image space transformation on the gray level image, unifying the size of the original image to 512 multiplied by 512 pixels, and obtaining a transformed image;
s23: performing image enhancement on the transformed image to obtain an enhanced image;
step S3: establishing a canny algorithm edge intelligent detection model based on bird waiting algorithm optimization:
inputting training set and testing set data, optimizing and setting the high and low threshold values of a canny edge detection algorithm by using a waiting bird algorithm, and obtaining a trained canny algorithm edge intelligent detection model optimized based on the waiting bird algorithm; the method specifically comprises the following steps:
s31: filtering the image by using a hybrid filter;
s32: calculating the mode and gradient direction of the gradient;
s33: performing non-maximum suppression on the gradient image;
s34: performing edge connection by using the optimized optimal double threshold value;
step S4: and obtaining an edge image according to the optimal high and low threshold value obtained by the model.
2. The method for detecting the edge of the rock slice image based on the improved canny algorithm as claimed in claim 1, wherein in the step S21, a weighted average method is adopted to perform weighted average on three components of RGB with different weights to obtain a gray scale map, specifically:
s211: reading pixel values of an original rock laminate image;
s212: carrying out weighted average on the red, green and blue components of each pixel to obtain a gray value;
s213: assigning gray values to the corresponding pixels;
f(x,y)=0.299R(x,y)+0.578G(x,y)+0.114B(x,y)
wherein: f (x, y) represents a pixel located at a spatial position (x, y), the R, G, B component values of the pixel being R (x, y), G (x, y), B (x, y), respectively;
s214: and outputting a gray image.
3. The method for detecting the edge of the rock slice image based on the improved canny algorithm as claimed in claim 1, wherein the image space transformation method in the step S22 comprises a deformation processing method and a bit transformation processing method of the image: the bit-shift processing includes image translation transformation, image mirror transformation and image rotation transformation; the deformation processing comprises image miscut transformation, clipping transformation and scaling transformation.
4. A rock laminate image edge detection method based on the modified canny algorithm as claimed in claim 3, wherein the scaling transformation changes the size of the image, and the gray scale image size is unified to 512x512 pixels by bicubic interpolation, comprising the steps of:
s221: assuming that the size of a source image A is m multiplied by n, m and n are the length and the width of the image respectively, the size of a scaled target image B is 512X512, and coordinates B (X, Y) on the scaled image B corresponding to the coordinates A are A (X, Y) =A [ X multiplied by (m/512), Y multiplied by (n/512) ];
s222: the coordinate position P of the corresponding image a in S221 may have a decimal part, at this time, the integer coordinate of the nearest pixel point is found, the coordinate is set as P (i+u, j+v), where i, j is an integer, u, v is a positive or negative decimal, at this time, P is the position of the image B in the corresponding source image at the (X, Y), and 16 pixel points nearest to P are selected as parameters for calculating the pixel value at the target of the target image;
s223: for example, assuming that the target point P found in S222 is located at (2, 2) in a 4×4 matrix of 16 pixels, the values of the horizontal and vertical coordinates of the 16 points are respectively [ i-1, i+2], [ j-1, j+2], where i, j is an integer, and the subsequent calculation results are as follows;
s224: the pixel value of the P point is calculated as follows:
wherein: w (x) is a weight calculation formula, and the value of a is generally-1, -0.75 or-0.5; row is the abscissa value range of 16 pixel points; col is the ordinate value range of 16 pixel points; f (i+row, j+col) is the original pixel value of 16 pixel points; f (i+u, j+v) is the interpolated P-point pixel value; w (row-u) is the weight of the lateral distance; w (col-v) is the weight of the longitudinal distance.
5. The method for detecting the edges of the rock laminate image based on the improved canny algorithm as claimed in claim 1, wherein the image enhancement in the step S23 adopts a histogram equalization method to enhance the contrast of the image while preventing the overfitting, and comprises the following steps:
s231: counting the histogram of the original image, calculating the occurrence frequency of each pixel value, and normalizing the occurrence frequency to [0,1] to obtain the frequency of each pixel value;
s232: a Cumulative Distribution Function (CDF) is calculated, representing the probability of each pixel value occurring in the original image, as follows:
wherein: CDF (i) is the cumulative distribution of gray values i; p (j) represents the frequency with which pixels with a gray value j appear in the image.
S233: calculating equalized pixel values, and mapping each pixel value in the original image to a new pixel value, so that the equalized histogram approximates to a uniformly distributed histogram; this mapping function may be calculated by the following formula:
wherein: h (i) represents the mapped pixel value; l represents a range of pixel values; CDF (min) represents the cumulative distribution of the minimum pixel values in the original image; CDF (i) is the cumulative distribution of gray values i; round is used for rounding; CDF (i) is the cumulative distribution of gray values i.
6. The method for detecting the edge of the rock slice image based on the improved canny algorithm as claimed in claim 1, wherein the specific method for filtering the image by using the hybrid filter in the step S31 is as follows:
the method has the advantages that the median-wiener mixed filter is adopted to filter the salt and pepper noise and Gaussian noise contained in the image, the median filter can well filter the salt and pepper noise, the image edge information is reserved, and the wiener filter can well filter the Gaussian noise; therefore, the gray value of the salt and pepper noise is the characteristic of gray extreme points in the field, the salt and pepper noise is distinguished from effective signal points, median filtering is carried out on the salt and pepper noise, the signal points are reserved, and finally, the whole image is filtered by wiener filtering.
7. The method for detecting the edge of the rock slice image based on the improved canny algorithm as claimed in claim 1, wherein the mode of calculating the gradient by using the sobel operator in the step S32 is as follows:
wherein: s is S x And S is y Is a sobel operator; g x Is a matrix of pixel gradients in the x-direction of the image; g y Is a matrix of pixel gradients in the y-direction of the image; i is a gray image matrix; here, the x represents a cross correlation operation, and the origin of the coordinate system of the image matrix is at the upper left corner, the positive x direction is from left to right, and the positive y direction is from top to bottom;
wherein: m (x, y) represents the gradient intensity of the pixel point; θ (x, y) represents the gradient direction of the pixel point; g x Is a matrix of pixel gradients in the x-direction of the image; g y Is a matrix of pixel gradients in the y-direction of the image.
8. The rock slice image edge detection method based on the improved canny algorithm as claimed in claim 1, wherein the specific method for performing non-maximum suppression on the gradient image in the step S33 is as follows:
comparing the gradient modulus value of the current pixel with the gradient modulus values of two adjacent pixels along the direction, wherein the direction is 8 areas, and each area is in a range of 45 degrees: if the gradient modulus value of the current pixel is larger than the gradient modulus value of the neighboring pixel in the same direction, the point is possibly an edge point, and the pixel value of the point is reserved; otherwise, the pixel value is marked as 0 by suppressing the non-maximum value.
9. The method for detecting the edge of the rock slice image based on the improved canny algorithm as claimed in claim 1, wherein the specific method for edge connection by using the optimized optimal double threshold in the step S34 is as follows:
after non-maximum suppression, non-edge points are marked as 0, and possible edge points retain pixel values, but the result still contains a lot of false edges caused by noise or other reasons, and at the moment, a bird waiting optimization algorithm is adopted to optimize and set the double threshold value of the canny algorithm, and the method comprises the following steps:
s341: initializing population, initializing individual collar flying birds, individual follow flying birds and number of rounds K, and setting maximum iteration number U max Maximum value K of number of rounds max Dividing the population structure into collar birds and left and right queues, and assuming that the collar birds are initial high and low threshold T H And T L Wherein the fixed high-low threshold ratio is T H ∶T L =3∶1;
S342: the collar flyer evolves, searches for its own neighborhood solution, replaces itself with the double threshold value that can obtain the best edge detection effect, and transmits the remaining unused neighborhood solution to the next individual;
s343: evolving with the flying bird, searching a neighborhood solution of the flying bird and an unused neighborhood solution set generated in the last searching process of individuals arranged in front of the flying bird, finding a double-threshold optimal solution capable of obtaining an optimal edge detection effect in the neighborhood solution sets to replace the flying bird, and transmitting the unused neighborhood solution generated by each flying bird to the next individual;
s344: judging whether the number of rounds reaches the maximum value of the number of rounds: if the number of rounds K is less than or equal to K max Then go to step S342; if the number of rounds K is less than or equal to K max Then go to step S345;
s345: when the number of rounds reaches the maximum value, moving the initial collar flyer to the tail of a team, selecting a left queue or a right queue of heel flyers behind the initial collar flyer as a new collar flyer according to the edge detection effect of the selected double threshold value, initializing the number of rounds, and then starting the next searching process;
s346: judging whether the iteration number reaches the maximum value of the maximum iteration number or not: if the iteration number U is less than or equal to U max Then go to step S342; if the iteration number U is less than or equal to U max The double threshold value of the bird-catching index in the population is the global optimal high threshold value T H And global bestExcellent low threshold T L The termination condition is satisfied;
s347: selecting S346 a preferred optimal high-low threshold T H And T L Judging: let points (x, y), g N(x,y) Is the pixel value of the point (x, y) in the image after non-maximum suppression of the image, if the point pixel value g N (x,y)≥T H The point is marked as a strong edge point, i.e. 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, suppressing it; t (T) L <g N (x,y)<T H And marking as a weak edge point, judging whether pixels higher than a high threshold value exist in the 8 neighborhood of the point, if so, judging the point as the edge point, and otherwise, judging the point as not the edge point.
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)
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 |
-
2023
- 2023-11-28 CN CN202311614512.2A patent/CN117576137A/en active Pending
Cited By (1)
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 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN115457041B (en) | Road quality identification and detection method | |
CN111340824B (en) | Image feature segmentation method based on data mining | |
CN106934386B (en) | A kind of natural scene character detecting method and system based on from heuristic strategies | |
WO2018068599A1 (en) | Image processing method and system for gene sequencing | |
CN111915704A (en) | Apple hierarchical identification method based on deep learning | |
CN107784669A (en) | A kind of method that hot spot extraction and its barycenter determine | |
CN113177456B (en) | Remote sensing target detection method based on single-stage full convolution network and multi-feature fusion | |
CN109975196B (en) | Reticulocyte detection method and system | |
CN109598681B (en) | No-reference quality evaluation method for image after repairing of symmetrical Thangka | |
CN117576137A (en) | Rock slice image edge detection method based on improved canny algorithm | |
CN106815851B (en) | A kind of grid circle oil level indicator automatic reading method of view-based access control model measurement | |
CN114677525B (en) | Edge detection method based on binary image processing | |
CN108205678B (en) | Nameplate character recognition processing method containing bright spot interference | |
CN106384103A (en) | Vehicle face recognition method and device | |
CN100371944C (en) | Greyscale image partition method based on light distribution character of reflection or penetrance | |
CN117765287A (en) | Image target extraction method combining LWR and density clustering | |
CN114842235B (en) | Infrared dim and small target identification method based on shape prior segmentation and multi-scale feature aggregation | |
CN115631179A (en) | Pneumonia image edge detection method based on improved Canny algorithm | |
CN115359003A (en) | Two-step tunnel gray image crack identification method, system, medium and equipment | |
CN108133467B (en) | Underwater image enhancement system and method based on particle calculation | |
CN112949389A (en) | Haze image target detection method based on improved target detection network | |
CN116934776B (en) | FISH microscopic image signal point region extraction method, device, equipment and medium | |
CN117974706B (en) | Rock slice particle pit segmentation method based on dynamic threshold and local search | |
CN114240988B (en) | Image segmentation method based on nonlinear scale space | |
CN114842309B (en) | Optimized recognition method for familiar targets in familiar scene |
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 |