Grid ball-based density peak clustering method applied to image segmentation

By adopting the density peak clustering method based on grid spheres in image segmentation, the problems of large amount of computing and long segmentation time on high-resolution images are solved, and efficient image segmentation is achieved.

CN119762824APending Publication Date: 2025-04-04SHANDONG NORMAL UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411795886.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-09
Publication Date
2025-04-04

AI Technical Summary

Technical Problem

Traditional density peak clustering algorithms require multiple iterations on high-resolution images, resulting in large amounts of operations and long segmentation time.

Method used

The density peak clustering method based on grid balls is adopted, and pixel points are mapped to grid cells through a two-stage strategy, and multiple grid cells are aggregated into grid balls, using grid balls instead of pixel points as basic data units to reduce the data scale.

Benefits of technology

It effectively reduces the data scale, improves the algorithm speed, and realizes efficient image segmentation, avoiding the problem of segmentation time-consuming due to the large data scale in traditional methods.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure BDA0005176682500000063
    Figure BDA0005176682500000063
  • Figure BDA0005176682500000132
    Figure BDA0005176682500000132
  • Figure FDA0005176682490000021
    Figure FDA0005176682490000021
Patent Text Reader

Abstract

A grid ball-based density peak value clustering method applied to image segmentation relates to the field of image segmentation, and comprises the following steps: pre-processing an image to obtain pixel points with a plurality of features, mapping the pixel points to grid units divided by a grid space in a first stage, and then on the basis of the first stage, carrying out clustering on the pixel points with a plurality of features; according to the method, grid balls with the number far smaller than that of original pixel points are generated by using a proposed multi-stage diffusion search neighbor strategy, then the grid balls are used as basic data units, the relation of the pixel points with feature similarity is found by using the advantages of a density peak clustering method, image region division is completed, and a good segmentation result is achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the fields of image segmentation and data mining, and in particular to a density peak value clustering method based on a grid ball and applied to image segmentation. Background Art

[0002] Image segmentation refers to dividing an image into several non-intersecting regions based on features such as grayscale, color, spatial texture, and geometric shape, so that these features show consistency or similarity in the same region, but show obvious differences between different regions. Image segmentation is an important image analysis method in image processing, the basis for subsequent image processing, and a research hotspot in the field of computer vision. Today, international researchers have proposed supervised and unsupervised segmentation methods. The unsupervised method has been widely used due to its advantages such as not requiring training samples. Cluster analysis, as a commonly used image segmentation method, is an unsupervised method. The density peak clustering algorithm is a density-based clustering method. It clusters by considering the connectivity of density and can better handle images with complex structures and noise such as "non-spherical". However, the traditional density peak clustering algorithm cannot adaptively select the cutoff distance parameter and needs to manually select the cluster center. Although many improved algorithms have solved these problems to a certain extent, another problem has arisen. On images with high resolution, the algorithm requires multiple iterations, which results in a very large amount of computation, resulting in a long segmentation time.

[0003] In solving this problem, the existing clustering algorithms used in image segmentation can no longer effectively deal with it, and there is an urgent need to develop a new clustering method to solve this problem. Summary of the invention

[0004] In order to overcome the shortcomings of the above technologies, the present invention provides a grid ball-based density peak clustering method for image segmentation. A two-stage strategy is used to map pixel points to grid units, and then several grid units are aggregated into a grid ball. The grid ball is used instead of pixel points as the basic data unit, thereby effectively reducing the data scale.

[0005] The technical solution adopted by the present invention to overcome the technical problems is:

[0006] A density peak clustering method based on grid sphere for image segmentation comprises the following steps:

[0007] a) Input image I, extract pixel features from image I, and obtain pixel feature matrix D;

[0008] b) creating a grid space S based on the pixel feature matrix D, and obtaining a grid unit set G according to the grid space S;

[0009] c) obtaining a descending sorted grid cell list G′ according to the grid cell set G, and generating a grid ball set GB based on the grid cell list G′;

[0010] d) Calculate the primary level density and the secondary level density of each grid ball in the grid ball set GB to obtain the density set R of the grid ball, use the density set R of the grid ball to calculate the weight of the grid unit of each grid ball in the grid ball set GB, and use the weighted average method to calculate the center of mass set C of the grid ball;

[0011] e) using the centroid set C of the grid balls and the density set R of the grid balls to calculate the relative distance set δ of all the grid balls; f) calculating the decision value according to the relative distance set δ and the density set R, selecting the cluster center based on the decision value, assigning a unique label to the cluster center, and obtaining the label set CL of the cluster center;

[0012] g) Obtain the segmented image I′ based on the label set CL.

[0013] Further, step a) comprises the following steps:

[0014] a-1) Use the imread function of the cv2 module in the OpenCV library to read image I, and obtain the characteristic values ​​of the red channel, the green channel, and the blue channel of n pixels of image I. The i-th pixel x i The eigenvalue of the red channel is x i1 , the i-th pixel x of image I i The eigenvalue of the green channel is x i2 , the i-th pixel x of image I i The eigenvalue of the blue channel is x i3 , i∈{1,...,n};

[0015] a-2) Use the cvtColor function of the cv2 module in the OpenCV library to convert image I into a grayscale image, and use the local_binary_pattern function of the feature module in the skimage library to calculate the LBP feature values ​​of n pixels of image I. The i-th pixel x i The LBP eigenvalue of i4 ; a-3) using the concatenate function in the numpy library to combine the eigenvalues ​​of the red channel, the eigenvalues ​​of the green channel, the eigenvalues ​​of the blue channel, and the LBP eigenvalues ​​of all pixels to obtain a three-dimensional eigenvalue matrix of shape (d, h, 4), where d is the width of the image I and h is the height of the image I;

[0016] a-4) Use the resize function of the cv2 module in the OpenCv library to rearrange the three-dimensional eigenvalue matrix of shape (d, h, 4) into a two-dimensional pixel feature matrix D of shape (d*h, 4). The pixel feature matrix D consists of d*h rows and 4 columns. The i-th row of the pixel feature matrix D represents the i-th pixel x of image I. i Sample, the i-th row and the first column is the i-th pixel x i The eigenvalue x of the red channel i1 , the i-th row and the second column is the i-th pixel x i The eigenvalue x of the green channel i2 , the ith row and third column is the ith pixel x i The eigenvalue x of the blue channel i3 , the ith row and 4th column is the ith pixel x i The LBP eigenvalue x i4 .

[0017] Further, step b) comprises the following steps:

[0018] b-1) Extract the minimum value min(x) of the four feature dimensions from the pixel feature matrix D ij ), j∈{1,2,3,4}, extract the maximum value of the four feature dimensions max(x ij ), the minimum value min(x ij ) as the minimum boundary, and the maximum value max(x ij ) as the maximum boundary, the minimum boundary and the maximum boundary together form a 4-dimensional grid space S;

[0019] b-2) Divide the grid space S into s grid units in each dimension by setting the grid size parameter s, and obtain s 4 grid cells;

[0020] b-3) s 4 grid units are combined into a grid unit set G, G = {G1, G2, ..., G i ,...,G s4}, G i is the i-th grid unit, i∈{1,...,s 4}. Further, step c) comprises the following steps:

[0021] c-1) Through the formula Calculate the i-th grid unit G i The first-level density g i1 , where x j represents the j-th pixel of image I, j∈{1,...,n}, F(x j) is the jth pixel x j The discriminant function of j In the i-th grid cell G i In the above equation, F(x j )=1, if the jth pixel x j Not in the i-th grid cell G i In the above equation, F(x j )=0;

[0022] c-2) Through the formula

[0023] Calculate the i-th grid unit G i The secondary level density g i2 , where x p is the i-th grid unit G i The pth pixel point of G, p∈{1,...,e}, e is the i-th grid unit G i The number of all pixels in x q is the i-th grid unit G i The qth pixel of , q∈{1,...,e}, is the i-th grid unit G i The pth pixel x p With the qth pixel x q Euclidean distance, p≠q;

[0024] c-3) Construct the local density T of the grid cells, g i is the i-th tuple, i∈{1,...,s 4}, g i =(g i1 ,g i2 ), delete the tuples with zero first-level density in the local density T of the grid cell, and use the lexsort function in the numpy library to sort the m tuples with non-zero first-level density in the local density T of the grid cell in descending order according to the values ​​of their corresponding first-level density. If the values ​​of the first-level density of two tuples are equal, they are sorted in descending order according to the values ​​of their corresponding second-level density to obtain a descending grid cell list G′, G′={G′1,G′2,...,G′ i ,...,G′ m},G′ i is the i-th grid unit after descending sorting, i∈{1,...,m};

[0025] c-4) Take the first grid cell from the grid cell list G′ and check whether the first grid cell has been visited. If yes, end the process. If not, execute step c-5);

[0026] c-5) Create a grid ball list GB1 and an empty queue Q;

[0027] c-6) Add the first grid cell to the empty queue Q;

[0028] c-7) Check whether the queue Q is empty, if so, output the grid ball list GB1, if not, execute step c-8);

[0029] c-8) Take the first grid cell from the queue Q and add it to the grid ball list GB1 and mark the grid cell as visited. Then use the product function in the itertools library to calculate all offset combinations with an offset length of 4 (-1, 0, 1). Add each offset in the combination to the vector coordinates of the grid cell to obtain all neighbors of the grid cell, create a neighbor list, and add all neighbors to the neighbor list.

[0030] c-9) Check if the neighbor list is empty, if not, take out the first grid cell from the neighbor list and execute step c-10), if yes, return to execute step c-7);

[0031] c-10) Check whether the first grid cell taken out from the neighbor list is not in the grid cell set G and whether the first grid cell taken out has been visited and whether the first level density of the first grid cell taken out is zero. If one of the judgment conditions is yes, the first grid cell taken out is discarded and the process returns to step c-9). If all the judgment conditions are no, the first grid cell taken out is added to the queue Q and the process returns to step c-9);

[0032] c-11) Repeat steps c-4) to c-10) until all m grid cells in the grid cell list G′ have executed steps c-4) to c-10). After the repetition is completed, the grid ball list corresponding to the l grid cells that meet the judgment condition in step c-7) constitutes a grid ball set GB, GB={GB1,GB2,...,GB l}.

[0033] Further, step d) comprises the following steps:

[0034] d-1) Through the formula Calculate the i-th grid ball GB i The first-order density ρ i1 , i∈{1,...,l}, where g j1 is the i-th grid ball GB i The jth grid cell G j The first-level density, Gj ∈GB i , c is the i-th grid ball GB i The number of grid cells in; d-2) by the formula Calculate the i-th grid ball GB i The secondary level density ρ i2 , where g j2 is the i-th grid ball GB i The jth grid cell G j The secondary level density of all grid balls constitutes the density set R of the grid ball, R = {g′1, g′2, ..., g′ i ,...,g′ l}, g′ i is the i-th tuple, i∈{1,...,l}, g′ i =(ρ i1 ,ρ i2 );

[0035] d-3) Through the formula Calculate the i-th grid ball GB i The jth grid cell G j The weight ω j , where g j1 The local density T of the grid cell represents the jth grid cell G j The primary level density of

[0036] d-4) Through the formula Calculate the i-th grid ball GB i The centroid c i , the centroids of all l grid balls constitute the grid ball centroid set C, C = {c1, c2, ..., c i ,...,c l}.

[0037] Further, step e) comprises the following steps:

[0038] e-1) through the formula d(GB i ,GB j )=d(c i ,c j ) Calculate the i-th grid ball GB i With the jth grid ball GB j The distance between i ,GB j ), where d(c i ,c j ) is the i-th grid ball GB i The centroid c i With the jth grid ball GBj The centroid c j The Euclidean distance between

[0039] e-2) Through the formula

[0040]

[0041] Calculate the i-th grid ball GB i The relative distance δ i , ρ j1 is the jth tuple g′ in the density set R of the grid sphere j The jth grid ball GB in j The first-level density, ρ j2 is the jth tuple g′ in the density set R of the grid sphere j The jth grid ball GB in j The second-level density, i∈{1,...,l}, j∈{1,...,l}, i≠j, ρ1 is the first-level density set, ρ1={ρ 11 ,ρ 21 ,...,ρ i1 ,...,ρ l1}, ρ2 is the secondary level density set, ρ2={ρ 12 ,ρ 22 ,...,ρ i2 ,...,ρ l2}, j: [·] indicates that the condition must be met, ∨ indicates or, ∧ indicates and, the relative distances of all grid balls constitute the relative distance set δ, δ = {δ1, δ2, ..., δ i ,...,δ l}.

[0042] Further, step f) comprises the following steps:

[0043] f-1) through the formula γ i =ρ i1 ·δ i Calculate the i-th grid ball GB i The decision value of γ i ;

[0044] f-2) Sort the decision values ​​of all l grid balls in descending order, select the grid balls corresponding to the first k decision values ​​after descending order, each grid ball is a cluster center, assign a unique label to the cluster center, and obtain the cluster center label set CL, CL = {CL1, CL2, ..., CL i ,...,CL k}, CL i is the label value of the i-th cluster center, i∈{1,...,k}.

[0045] Further, step g) comprises the following steps:

[0046] g-1) Select the grid balls corresponding to the last lk decision values ​​sorted in descending order in step f-2), each grid ball is a non-clustering center, and use the label propagation strategy of the density peak clustering algorithm to assign a unique label value to the non-clustering center to obtain the non-clustering center label set FCL, FCL = {FCL1, FCL2, ..., FCL i ,...,FCL l-k}, FCL i is the label value of the i-th non-cluster center, i∈{1,...,lk};

[0047] g-2) The label set of all l grid balls is GBL, GBL = {CL, FCL}, and the label value of the i-th grid ball in the label set GBL is GBL i , i∈{1,...,l}, the label value of the jth grid cell of the i-th grid ball is The label set of all grid cells of the i-th grid sphere is GL i , j∈{1,...,c}, the label values ​​of all grid cells of all grid spheres constitute the grid cell label set GL, GL={GL1,GL2,...,GL i ,...,GL l};

[0048] g-3) The label value of the p-th pixel in the j-th grid cell of the i-th grid ball is i∈{1,...,l}, the label set of all pixels in the jth grid cell of the i-th grid ball is j∈{1,...,c}, p∈{1,...,e}, the label set of all pixel label values ​​of all grid cells of the i-th grid sphere is L i , The label set of all pixel label values ​​of all grid balls is L, L = {L1, L2, ..., L i ,...,L l};

[0049] g-4) Obtain the segmented image I′ based on the label set L.

[0050] Furthermore, in step g-4), the set L of all pixel label values ​​of all grid balls is reshaped into the form of image I using the reshape function to obtain the segmented image I′.

[0051] The beneficial effects of the present invention are as follows: the density peak clustering algorithm based on grid balls proposed by the present invention overcomes the problem of long segmentation time of the improved density peak clustering algorithm on high-resolution images. The idea of ​​grid clustering is introduced to propose a density peak clustering algorithm based on grid balls. The proposed algorithm only inputs a unique grid size parameter for clustering, and the density calculation does not require any parameters, which improves the problem of the density peak clustering algorithm relying on the truncation distance parameter and greatly improves the speed of the algorithm. It is simple and easy to use. Through a two-stage strategy, the pixel points used for clustering are replaced with grid balls, so that the actual clustering data is greatly reduced. While maintaining the clustering quality, the amount of calculation can be reduced to improve the algorithm speed, and a good image segmentation result can be achieved. For feature data sets with high dimensions, the present invention uses PCA dimensionality reduction technology, which can reduce the feature dimensions of pixel points from which multiple features are extracted, thereby achieving rapid segmentation. DETAILED DESCRIPTION

[0052] The present invention is further described below.

[0053] A density peak clustering method based on grid sphere for image segmentation comprises the following steps:

[0054] a) Input image I, extract pixel features from image I, and obtain pixel feature matrix D.

[0055] b) Create a grid space S based on the pixel feature matrix D, and obtain a grid unit set G according to the grid space S.

[0056] c) Obtaining a descending sorted grid cell list G′ according to the grid cell set G, and generating a grid ball set GB based on the grid cell list G′.

[0057] d) Calculate the primary and secondary horizontal densities of each grid ball in the grid ball set GB to obtain the density set R of the grid ball. Use the density set R of the grid ball to calculate the weight of the grid cells of each grid ball in the grid ball set GB. Use the weighted average method to calculate the centroid set C of the grid ball.

[0058] e) Calculate the relative distance set δ of all grid balls using the centroid set C of the grid balls and the density set R of the grid balls. f) Calculate the decision value based on the relative distance set δ and the density set R, select the cluster center based on the decision value, assign a unique label to the cluster center, and obtain the label set CL of the cluster center.

[0059] g) Obtain the segmented image I′ based on the label set CL.

[0060] The grid ball-based density peak clustering method is a feasible solution. It can map pixels to grid cells through a two-stage strategy, and then aggregate several grid cells into a grid ball, using grid balls instead of pixels as the basic data units, thereby effectively reducing the data size. It is considered to be the most feasible design solution for fast image segmentation.

[0061] A two-stage strategy is used to quickly generate grid balls, which can replace the pixels directly extracted from the image as the basic clustering object, avoiding the problem of long segmentation time caused by the large data scale. Based on the image segmentation of density peak clustering, the present invention proposes a density peak clustering method based on grid balls, which obtains pixel points with multiple features after pre-processing the image, and maps them to grid units divided by the grid space in the first stage. Then, on this basis, the proposed multi-level diffusion search neighbor strategy is used to generate grid balls with a number far less than the number of original pixel points. Then, the grid balls are used as the basic data units to use the advantages of the density peak clustering method to find the relationship between pixel points with feature similarity, complete the division of the image area, and achieve good segmentation results.

[0062] In one embodiment of the present invention, step a) comprises the following steps:

[0063] a-1) Use the imread function of the cv2 module in the OpenCV library to read image I, and obtain the characteristic values ​​of the red channel, the green channel, and the blue channel of n pixels of image I. The i-th pixel x i The eigenvalue of the red channel is x i1 , the i-th pixel x of image I i The eigenvalue of the green channel is x i2 , the i-th pixel x of image I i The eigenvalue of the blue channel is x i3 , i∈{1,...,n}.

[0064] a-2) Use the cvtColor function of the cv2 module in the OpenCV library to convert image I into a grayscale image, and use the local_binary_pattern function of the feature module in the skimage library to calculate the LBP feature values ​​of n pixels of image I. The i-th pixel x i The LBP eigenvalue of i4 .

[0065] a-3) Use the concatenate function in the numpy library to combine the eigenvalues ​​of the red channel, the eigenvalues ​​of the green channel, the eigenvalues ​​of the blue channel, and the LBP eigenvalues ​​of all pixels to obtain a three-dimensional eigenvalue matrix of shape (d, h, 4), where d is the width of image I and h is the height of image I.

[0066] a-4) Use the resize function of the cv2 module in the OpenCv library to rearrange the three-dimensional eigenvalue matrix of shape (d, h, 4) into a two-dimensional pixel feature matrix D of shape (d*h, 4). The pixel feature matrix D consists of d*h rows and 4 columns. The i-th row of the pixel feature matrix D represents the i-th pixel x of image I. i Sample, the i-th row and the first column is the i-th pixel x i The eigenvalue x of the red channel i1 , the i-th row and the second column is the i-th pixel x i The eigenvalue x of the green channel i2 , the ith row and third column is the ith pixel x i The eigenvalue x of the blue channel i3 , the ith row and 4th column is the ith pixel x i The LBP eigenvalue x i4 .

[0067] In one embodiment of the present invention, step b) comprises the following steps:

[0068] b-1) Extract the minimum value min(x) of the four feature dimensions from the pixel feature matrix D ij ), j∈{1,2,3,4}, extract the maximum value of the four feature dimensions max(x ij ), the minimum value min(x ij ) as the minimum boundary, and the maximum value max(x ij ) is used as the maximum boundary, and the minimum boundary and the maximum boundary together form a 4-dimensional grid space S.

[0069] b-2) Divide the grid space S into s grid units in each dimension by setting the grid size parameter s, and obtain s 4 grid cells.

[0070] b-3) s 4 grid cells are combined into a grid cell set G, G i is the i-th grid unit, i∈{1,...,s 4 In one embodiment of the present invention, step c) comprises the following steps:

[0071] c-1) Through the formula Calculate the i-th grid unit G i The first-level density g i1 , where x j represents the j-th pixel of image I, j∈{1,...,n}, F(x j ) is the jth pixel x j The discriminant function of j In the i-th grid cell G i In the above equation, F(x j )=1, if the jth pixel x j Not in the i-th grid cell G i In the above equation, F(x j )=0.

[0072] c-2) Through the formula

[0073] Calculate the i-th grid unit G i The secondary level density g i2 , where x p is the i-th grid unit G i The p-th pixel point, p∈{1,...,e}, e is the i-th grid unit G i The number of all pixels in x q is the i-th grid unit G i The qth pixel of , q∈{1,...,e}, is the i-th grid unit G i The pth pixel x p With the qth pixel x q The Euclidean distance, x q ∈G i Represents the qth pixel x q In the i-th grid cell G i , p≠q.

[0074] c-3) Construct the local density T of the grid cells, g i is the i-th tuple, i∈{1,...,s 4}, g i =(g i1 ,g i2), delete the tuples with zero first-level density in the local density T of the grid cell, and use the lexsort function in the numpy library to sort the m tuples with non-zero first-level density in the local density T of the grid cell in descending order according to the values ​​of their corresponding first-level density. If the values ​​of the first-level density of two tuples are equal, they are sorted in descending order according to the values ​​of their corresponding second-level density to obtain a descending grid cell list G′, G′={G′1,G′2,...,G′ i ,...,G′ m},G′ i is the i-th grid cell after sorting in descending order, i∈{1,...,m}.

[0075] c-4) Take out the first grid cell from the grid cell list G′ and check whether the first grid cell has been visited. If yes, end the process. If not, execute step c-5).

[0076] c-5) Create a grid ball list GB1 and an empty queue Q.

[0077] c-6) Add the first grid cell to the empty queue Q.

[0078] c-7) Check whether the queue Q is empty, if so, output the grid ball list GB1, if not, execute step c-8);

[0079] c-8) Take the first grid cell from the queue Q and add it to the grid ball list GB1 and mark the grid cell as visited. Then use the product function in the itertools library to calculate all offset combinations with an offset length of 4 (-1, 0, 1). Add each offset in the combination to the vector coordinates of the grid cell to obtain all neighbors of the grid cell, create a neighbor list, and add all neighbors to the neighbor list.

[0080] c-9) Check if the neighbor list is empty, if not take out the first grid cell from the neighbor list and execute step c-10), if yes return to execute step c-7).

[0081] c-10) Check whether the first grid cell taken out from the neighbor list is not in the grid cell set G and whether the first grid cell taken out has been visited and whether the first level density of the first grid cell taken out is zero. If one of the judgment conditions is yes, discard the first grid cell taken out and return to execute step c-9). If all the judgment conditions are no, add the first grid cell taken out to the queue Q and return to execute step c-9).

[0082] c-11) Repeat steps c-4) to c-10) until all m grid cells in the grid cell list G′ have executed steps c-4) to c-10). After the repetition is completed, the grid ball list corresponding to the l grid cells that meet the judgment condition in step c-7) constitutes a grid ball set GB, GB={GB1,GB2,...,GB l}.

[0083] In one embodiment of the present invention, step d) comprises the following steps:

[0084] d-1) Through the formula Calculate the i-th grid ball GB i The first-order density ρ i1 , i∈{1,...,l}, where g j1 is the i-th grid ball GB i The jth grid cell G j The first-level density, G j ∈GB i , c is the i-th grid ball GB i The number of grid cells in .

[0085] d-2) Through the formula Calculate the i-th grid ball GB i The secondary level density ρ i2 , where g j2 is the i-th grid ball GB i The jth grid cell G j The secondary level density of all grid balls constitutes the density set R of the grid ball, R = {g′1, g′2, ..., g′ i ,...,g′ l}, g′ i is the i-th tuple, i∈{1,...,l}, g′ i =(ρ i1 ,ρ i2 ).

[0086] d-3) Through the formula Calculate the i-th grid ball GB i The jth grid cell G j The weight ω j , where g j1 The local density T of the grid cell represents the jth grid cell G j The primary level density of

[0087] d-4) Through the formula Calculate the i-th grid ball GB i The centroid ci , the centroids of all l grid balls constitute the grid ball centroid set C, C = {c1, c2, ..., c i ,...,c l}.

[0088] In one embodiment of the present invention, step e) comprises the following steps:

[0089] e-1) through the formula d(GB i ,GB j )=d(c i ,c j ) Calculate the i-th grid ball GB i With the jth grid ball GB j The distance between i ,GB j ), where d(c i ,c j ) is the i-th grid ball GB i The centroid c i With the jth grid ball GB j The centroid c j The Euclidean distance between .

[0090] e-2) Through the formula

[0091]

[0092] Calculate the i-th grid ball GB i The relative distance δ i , ρ j1 is the jth tuple g′ in the density set R of the grid sphere j The jth grid ball GB in j The first-level density, ρ j2 is the jth tuple g′ in the density set R of the grid sphere j The jth grid ball GB in j The second-level density, i∈{1,...,l}, j∈{1,...,l}, i≠j, ρ1 is the first-level density set, ρ1={ρ 11 ,ρ 21 ,...,ρ i1 ,...,ρ l1}, ρ2 is the secondary level density set, ρ2={ρ 12 ,ρ 22 ,...,ρ i2 ,...,ρ l2}, j: [·] indicates that the condition must be met, ∨ indicates or, ∧ indicates and, the relative distances of all grid balls constitute the relative distance set δ, δ = {δ1, δ2, ..., δ i,...,δ l}. j:[ρ i1 <ρ j1 ]∨[(ρ i1 =ρ j1 )∧(ρ i2 <ρ j2 )] represents all j-th grid balls GB j The following conditions need to be met: its primary level density is greater than the i-th grid ball GB i The first-level density or its first-level density is equal to the i-th grid ball GB i The first-level density of the grid ball GB is greater than the second-level density of the grid ball GB. i The first-level density.

[0093] represents all i-th grid balls GB without the maximum first-level density i The relative distance of is equal to the distance between the grid ball closest to the grid ball that meets the conditions. i =maxd(GB i ,GB j ) represents the i-th grid ball GB with the largest primary level density and the largest secondary level density i The relative distance is equal to the largest distance among all the distances between the grid balls. The values ​​of i and j range from 1 to l and i and j cannot be equal at the same time.

[0094] In one embodiment of the present invention, step f) comprises the following steps:

[0095] f-1) through the formula γ i =ρ i1 ·δ i Calculate the i-th grid ball GB i The decision value of γ i .

[0096] f-2) Sort the decision values ​​of all l grid balls in descending order, select the grid balls corresponding to the first k decision values ​​after descending order, each grid ball is a cluster center, assign a unique label to the cluster center, and obtain the cluster center label set CL, CL = {CL1, CL2, ..., CL i ,...,CL k}, CL i is the label value of the i-th cluster center, i∈{1,...,k}.

[0097] In one embodiment of the present invention, step g) comprises the following steps:

[0098] g-1) Select the grid balls corresponding to the last lk decision values ​​sorted in descending order in step f-2), each grid ball is a non-clustering center, and use the label propagation strategy of the density peak clustering algorithm to assign a unique label value to the non-clustering center to obtain the non-clustering center label set FCL, FCL = {FCL1, FCL2, ..., FCL i ,...,FCL l-k}, FCL i is the label value of the i-th non-cluster center, i∈{1,...,lk}.

[0099] g-2) The label set of all l grid balls is GBL, GBL = {CL, FCL}, and the label value of the i-th grid ball in the label set GBL is GBL i , i∈{1,...,l}, the label value of the jth grid cell of the i-th grid ball is The label set of all grid cells of the i-th grid sphere is GL i , j∈{1,...,c}, the label values ​​of all grid cells of all grid spheres constitute the grid cell label set GL, GL={GL1,GL2,...,GL i ,...,GL l};

[0100] g-3) The label value of the p-th pixel in the j-th grid cell of the i-th grid ball is i∈{1,...,l}, the label set of all pixels in the jth grid cell of the i-th grid ball is j∈{1,...,c}, p∈{1,...,e}, the label set of all pixel label values ​​of all grid cells of the i-th grid sphere is L i , The label set of all pixel label values ​​of all grid balls is L, L = {L1, L2, ..., L i ,...,L l};

[0101] g-4) Obtain the segmented image I′ based on the label set L.

[0102] In one embodiment of the present invention, in step g-4), the set L of all pixel label values ​​of all grid spheres is reshaped into the form of image I using the reshape function to obtain the segmented image I′.

[0103] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art can still modify the technical solutions described in the aforementioned embodiments or replace some of the technical features therein by equivalents. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A density peak clustering method based on grid ball for image segmentation, characterized in that: The steps include: a) Input image I, extract pixel features from image I, and obtain pixel feature matrix D; b) creating a grid space S based on the pixel feature matrix D, and obtaining a grid unit set G according to the grid space S; c) obtaining a descending sorted grid cell list G′ according to the grid cell set G, and generating a grid ball set GB based on the grid cell list G′; d) Calculate the primary level density and the secondary level density of each grid ball in the grid ball set GB to obtain the density set R of the grid ball, use the density set R of the grid ball to calculate the weight of the grid unit of each grid ball in the grid ball set GB, and use the weighted average method to calculate the center of mass set C of the grid ball; e) using the centroid set C of the grid balls and the density set R of the grid balls to calculate the relative distance set δ of all the grid balls; f) Calculate the decision value according to the relative distance set δ and the density set R, select the cluster center based on the decision value, assign a unique label to the cluster center, and obtain the label set CL of the cluster center; g) Obtain the segmented image I′ based on the label set CL.

2. The grid ball based density peak clustering method for image segmentation according to claim 1, characterized in that: Step a) comprises the following steps: a-1) Use the imread function of the cv2 module in the OpenCV library to read image I, and obtain the characteristic values ​​of the red channel, the green channel, and the blue channel of n pixels of image I. The i-th pixel x i The eigenvalue of the red channel is x i1 , the i-th pixel x of image I i The eigenvalue of the green channel is x i2 , the i-th pixel x of image I i The eigenvalue of the blue channel is x i3 , i∈{1,...,n}; a-2) Use the cvtColor function of the cv2 module in the OpenCV library to convert image I into a grayscale image, and use the local_binary_pattern function of the feature module in the skimage library to calculate the LBP feature values ​​of n pixels of image I. The i-th pixel x i The LBP eigenvalue of i4 ; a-3) Use the concatenate function in the numpy library to combine the eigenvalues ​​of the red channel, the eigenvalues ​​of the green channel, the eigenvalues ​​of the blue channel, and the LBP eigenvalues ​​of all pixels to obtain a three-dimensional eigenvalue matrix of shape (d, h, 4), where d is the width of image I and h is the height of image I; a-4) Use the resize function of the cv2 module in the OpenCv library to rearrange the three-dimensional eigenvalue matrix of shape (d, h, 4) into a two-dimensional pixel feature matrix D of shape (d*h, 4). The pixel feature matrix D consists of d*h rows and 4 columns. The i-th row of the pixel feature matrix D represents the i-th pixel x of image I. i Sample, the i-th row and the first column is the i-th pixel x i The eigenvalue x of the red channel i1 , the i-th row and the second column is the i-th pixel x i The eigenvalue x of the green channel i2 , the ith row and third column is the ith pixel x i The eigenvalue x of the blue channel i3 , the ith row and 4th column is the ith pixel x i The LBP eigenvalue x i4 .

3. The grid ball based density peak clustering method for image segmentation according to claim 2, characterized in that: Step b) comprises the following steps: b-1) Extract the minimum value min(x) of the four feature dimensions from the pixel feature matrix D ij ), j∈{1,2,3,4}, extract the maximum value of the four feature dimensions max(x ij ), the minimum value min(x ij ) as the minimum boundary, and the maximum value max(x ij ) as the maximum boundary, the minimum boundary and the maximum boundary together form a 4-dimensional grid space S; b-2) Divide the grid space S into s grid units in each dimension by setting the grid size parameter s, and obtain s 4 grid cells; b-3) s 4 grid cells are combined into a grid cell set G, G i is the i-th grid unit, i∈{1,...,s 4 }.

4. The density peak clustering method based on grid ball for image segmentation according to claim 3, characterized in that: Step c) comprises the following steps: c-1) Through the formula Calculate the i-th grid unit G i The first-level density g i1 , where x j represents the j-th pixel of image I, j∈{1,...,n}, F(x j ) is the jth pixel x j The discriminant function of j In the i-th grid cell G i In the above equation, F(x j )=1, if the jth pixel x j Not in the i-th grid cell G i In the above equation, F(x j )=0;c-2)Through the formula Calculate the i-th grid unit G i The secondary level density g i2 , where x p is the i-th grid unit G i The p-th pixel point, p∈{1,...,e}, e is the i-th grid unit G i The number of all pixels in x q is the i-th grid unit G i The qth pixel of , q∈{1,...,e}, is the i-th grid unit G i The pth pixel x p With the qth pixel x q Euclidean distance, p≠q; c-3) Construct the local density T of the grid cells, g i is the i-th tuple, i∈{1,...,s 4 }, g i =(g i1 ,g i2 ), delete the tuples with zero first-level density in the local density T of the grid cell, and use the lexsort function in the numpy library to sort the m tuples with non-zero first-level density in the local density T of the grid cell in descending order according to the values ​​of their corresponding first-level density. If the values ​​of the first-level density of two tuples are equal, they are sorted in descending order according to the values ​​of their corresponding second-level density to obtain a descending grid cell list G′, G′={G1′,G2′,...,G i ′,...,G′ m }, G i ′ is the i-th grid unit after descending sorting, i∈{1,...,m}; c-4) Take the first grid cell from the grid cell list G′ and check whether the first grid cell has been visited. If yes, end the process. If not, execute step c-5); c-5) Create a grid ball list GB1 and an empty queue Q; c-6) Add the first grid cell to the empty queue Q; c-7) Check whether the queue Q is empty, if so, output the grid ball list GB1, if not, execute step c-8); c-8) Take the first grid cell from the queue Q and add it to the grid ball list GB1 and mark the grid cell as visited. Then use the product function in the itertools library to calculate all offset combinations with an offset length of 4 (-1, 0, 1). Add each offset in the combination to the vector coordinates of the grid cell to obtain all neighbors of the grid cell, create a neighbor list, and add all neighbors to the neighbor list. c-9) Check if the neighbor list is empty, if not, take out the first grid cell from the neighbor list and execute step c-10), if yes, return to execute step c-7); c-10) Check whether the first grid cell taken out from the neighbor list is not in the grid cell set G and whether the first grid cell taken out has been visited and whether the first level density of the first grid cell taken out is zero. If one of the judgment conditions is yes, the first grid cell taken out is discarded and the process returns to step c-9). If all the judgment conditions are no, the first grid cell taken out is added to the queue Q and the process returns to step c-9); c-11) Repeat steps c-4) to c-10) until all m grid cells in the grid cell list G′ have executed steps c-4) to c-10). After the repetition is completed, the grid ball list corresponding to the l grid cells that meet the judgment condition in step c-7) constitutes a grid ball set GB, GB={GB1,GB2,...,GB l }.

5. The density peak clustering method based on grid ball for image segmentation according to claim 4, characterized in that: Step d) comprises the following steps: d-1) Through the formula Calculate the i-th grid ball GB i The first-order density ρ i1 , i∈{1,...,l}, where g j1 is the i-th grid ball GB i The jth grid cell G j The first-level density, G j ∈GB i , c is the i-th grid ball GB i The number of grid cells in ; d-2) Through the formula Calculate the i-th grid ball GB i The secondary level density ρ i2 , where g j2 is the i-th grid ball GB i The jth grid cell G j The secondary level density of all grid balls, the primary level density and the secondary level density constitute the density set R of the grid ball, R = {g1′, g2′, ..., g i ′,...,g l ′},g i ′ is the i-th tuple, i∈{1,...,l}, g i ′=(ρ i1 ,ρ i2 ); d-3) Through the formula Calculate the i-th grid ball GB i The jth grid cell G j The weight ω j , where g j1 The local density T of the grid cell represents the jth grid cell G j The primary level density of d-4) Through the formula Calculate the i-th grid ball GB i The centroid c i , the centroids of all l grid balls constitute the grid ball centroid set C, C = {c1, c2, ..., c i ,...,c l }.

6. The density peak clustering method based on grid ball for image segmentation according to claim 5, characterized in that: Step e) comprises the following steps: e-1) through the formula d(GB i ,GB j )=d(c i ,c j ) Calculate the i-th grid ball GB i With the jth grid ball GB j The distance between i ,GB j ), where d(c i ,c j ) is the i-th grid ball GB i The centroid c i With the jth grid ball GB j The centroid c j The Euclidean distance between e-2) Through the formula Calculate the i-th grid ball GB i The relative distance δ i , ρ j1 is the jth tuple g in the density set R of the grid sphere j The jth grid ball GB in ′ j The first-level density, ρ j2 is the jth tuple g in the density set R of the grid sphere j The jth grid ball GB in ′ j The second-level density, i∈{1,...,l}, j∈{1,...,l}, i≠j, ρ1 is the first-level density set, ρ1={ρ 11 ,ρ 21 ,...,ρ i1 ,...,ρ l1 }, ρ2 is the secondary level density set, ρ2={ρ 12 ,ρ 22 ,...,ρ i2 ,...,ρ l2 }, j: [·] indicates that the condition must be met, ∨ indicates or, ∧ indicates and, the relative distances of all grid balls constitute the relative distance set δ, δ = {δ1, δ2, ..., δ i ,...,δ l }.

7. The grid ball based density peak clustering method for image segmentation according to claim 6, characterized in that: Step f) comprises the following steps: f-1) through the formula γ i =ρ i1 ·δ i Calculate the i-th grid ball GB i The decision value of γ i ; f-2) Sort the decision values ​​of all l grid balls in descending order, select the grid balls corresponding to the first k decision values ​​after descending order, each grid ball is a cluster center, assign a unique label to the cluster center, and obtain the cluster center label set CL, CL = {CL1, CL2, ..., CL i ,...,CL k }, CL i is the label value of the i-th cluster center, i∈{1,...,k}.

8. The density peak clustering method based on grid ball for image segmentation according to claim 7, characterized in that: Step g) comprises the following steps: g-1) Select the grid balls corresponding to the last lk decision values ​​sorted in descending order in step f-2), each grid ball is a non-clustering center, and use the label propagation strategy of the density peak clustering algorithm to assign a unique label value to the non-clustering center to obtain the non-clustering center label set FCL, FCL = {FCL1, FCL2, ..., FCL i ,...,FCL l-k }, FCL i is the label value of the i-th non-cluster center, i∈{1,...,lk}; g-2) The label set of all l grid balls is GBL, GBL = {CL, FCL}, and the label value of the i-th grid ball in the label set GBL is GBL i , i∈{1,...,l}, the label value of the jth grid cell of the i-th grid ball is The label set of all grid cells of the i-th grid sphere is GL i , The label values ​​of all grid cells of all grid spheres constitute the grid cell label set GL, GL = {GL1, GL2, ..., GL i ,...,GL l }; g-3) The label value of the p-th pixel in the j-th grid cell of the i-th grid ball is The label set of all pixels in the jth grid cell of the i-th grid sphere is j∈{1,...,c}, p∈{1,...,e}, the label set of all pixel label values ​​of all grid cells of the i-th grid sphere is L i , The label set of all pixel label values ​​of all grid balls is L, L = {L1, L2, ..., L i ,...,L l }; g-4) Obtain the segmented image I′ based on the label set L.

9. The grid ball based density peak clustering method for image segmentation according to claim 8, characterized in that: In step g-4), the reshape function is used to reshape the label set L of all pixel label values ​​of all grid balls into the form of image I to obtain the segmented image I′.