Image segmentation method and device, electronic equipment, storage medium and product
By using the preset clustering algorithm based on Julia language in image segmentation, the existing K-mean clustering algorithm in high-dimensional data processing, noise sensitivity and computing efficiency are solved, and more efficient and accurate image segmentation is achieved.
Patent Information
- Application Number
- CN202411651246.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-19
- Publication Date
- 2025-02-28
AI Technical Summary
The existing K-mean clustering algorithm has problems in high-dimensional data processing, noise sensitivity and computing efficiency, which affects the accuracy and efficiency of image segmentation.
The preset clustering algorithm based on Julia language is used to cluster pixel points in the image, which shortens the image segmentation time and improves the image segmentation efficiency and accuracy.
The preset clustering algorithm of Julia language significantly improves the efficiency and accuracy of pixel point classification, solves the problems of the existing K-mean clustering algorithm in high-dimensional data processing, noise sensitivity and computing efficiency, and ensures the reliability and accuracy of the target image.
Smart Images

Figure CN119540258A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing technology, and in particular to an image segmentation method, device, electronic equipment, storage medium and product. Background Art
[0002] To achieve image segmentation, the K-means clustering algorithm is usually used. K-means clustering is an unsupervised learning algorithm used for image segmentation. The K-means clustering algorithm can divide the pixels in the image into K clusters to extract and simplify image features.
[0003] At present, the K-means clustering algorithms in the prior art include the classic K-means algorithm, the improved K-means++ algorithm, and the algorithm combining K-means with edge detection. However, the classic K-means algorithm is sensitive to the selection of the initial clustering center, which may lead to unstable clustering results. And the computational efficiency is low when processing high-dimensional data. The improved K-means++ algorithm has the problem of high computational complexity when processing a large amount of image data. The algorithm combining K-means with edge detection may introduce noise when performing clustering processing, and because of the use of the edge detection algorithm, the implementation complexity of the combined algorithm is high, which is not conducive to subsequent algorithm optimization. Based on the above, the existing K-means clustering algorithm has problems in high-dimensional data processing, noise sensitivity and computational efficiency, which will affect the accuracy and efficiency of image segmentation. Summary of the invention
[0004] The present invention provides an image segmentation method, device, electronic device, storage medium and product, which shorten the image segmentation time and improve the image segmentation efficiency and accuracy by using a preset clustering algorithm of the Julia language.
[0005] According to one aspect of the present invention, there is provided an image segmentation method, the method comprising:
[0006] Obtaining an image to be segmented, wherein the image to be segmented is a color image or a grayscale image;
[0007] Clustering each pixel in the segmented image according to a preset clustering algorithm to obtain at least two categories of pixels to be processed, wherein the preset clustering algorithm is a clustering algorithm based on the Julia language;
[0008] A target image is obtained according to at least two categories of to-be-processed pixel points and preset pixel values corresponding to each category.
[0009] According to another aspect of the present invention, there is provided an image segmentation device, the device comprising:
[0010] An image acquisition module is used to acquire an image to be segmented, wherein the image to be segmented is a color image or a grayscale image;
[0011] A pixel clustering module, used for clustering each pixel in the segmented image according to a preset clustering algorithm to obtain at least two categories of pixels to be processed, wherein the preset clustering algorithm is a clustering algorithm based on the Julia language;
[0012] The target image determination module is used to obtain the target image according to at least two categories of pixel points to be processed and the preset pixel values corresponding to each category.
[0013] According to another aspect of the present invention, there is provided an electronic device, the electronic device comprising:
[0014] at least one processor; and
[0015] a memory communicatively connected to at least one processor; wherein,
[0016] The memory stores a computer program that can be executed by at least one processor. The computer program is executed by at least one processor so that the at least one processor can execute the image segmentation method of any embodiment of the present invention.
[0017] According to another aspect of the present invention, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the image segmentation method of any embodiment of the present invention when executed.
[0018] According to another aspect of the present invention, a computer program product is provided, comprising a computer program, wherein the computer program implements the image segmentation method according to any embodiment of the present invention when executed by a processor.
[0019] The technical solution of the embodiment of the present invention obtains an image to be segmented, and clusters each pixel in the image to be segmented according to a preset clustering algorithm based on the Julia language to obtain at least two categories of pixels to be processed. The preset clustering algorithm of the Julia language shortens the time for pixel classification, and improves the efficiency and accuracy of pixel classification. According to at least two categories of pixels to be processed and the preset pixel values corresponding to each category, a target image is obtained so that the target image can be applied to various image analyses. The present invention is applicable to a variety of scenarios, solves the problems of the existing K-means clustering algorithm in high-dimensional data processing, noise sensitivity and computational efficiency, and improves the efficiency and accuracy of image segmentation, while ensuring the reliability and accuracy of the target image.
[0020] It should be understood that the contents described in this section are not intended to identify the key or important features of the embodiments of the present invention, nor are they intended to limit the scope of the present invention. Other features of the present invention will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0021] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0022] Figure 1 is a flow chart of an image segmentation method provided by an embodiment of the present invention;
[0023] Figure 2 is an example diagram of an original image provided by an embodiment of the present invention;
[0024] Figure 3 is an example diagram of a target image provided by an embodiment of the present invention;
[0025] Figure 4 is a flow chart of an image segmentation method provided by an embodiment of the present invention;
[0026] Figure 5 is a structural schematic diagram of an image segmentation device provided by an embodiment of the present invention;
[0027] Figure 6 It is a schematic diagram of the structure of an electronic device for implementing the image segmentation method according to an embodiment of the present invention. DETAILED DESCRIPTION
[0028] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present invention.
[0029] It should be noted that the terms "first", "second", etc. in the specification and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0030] Embodiment 1
[0031] Figure 1 This is a flowchart of an image segmentation method provided in the first embodiment of the present invention. This embodiment is applicable to the case where the pixel points in the image are classified using the preset clustering algorithm of the Julia language and the target image is obtained. The method can be executed by an image segmentation device, which can be implemented in the form of hardware and / or software. The image segmentation device can be configured in an electronic device such as a mobile phone, a computer or a server. Figure 1 As shown, the method includes:
[0032] S110, obtaining an image to be segmented, wherein the image to be segmented is a color image or a grayscale image.
[0033] The image to be segmented can be understood as an image that needs to be segmented at present. The image to be segmented can be a color image or a grayscale image.
[0034] Specifically, an image to be segmented that needs to be segmented is obtained to perform classification processing on each pixel point in the image to be segmented.
[0035] In an embodiment of the present invention, the method for obtaining the image to be segmented can be: obtaining the original image, and determining the pixel mean and pixel variance corresponding to each pixel point in the original image; based on the pixel mean and pixel variance, standardizing the pixel value of each pixel point in the original image to obtain the standard pixel value corresponding to each pixel point, and obtaining the image to be segmented based on each pixel point with the standard pixel value.
[0036] Among them, the original image can be an image that needs to be processed by pixel classification. In order to improve the clustering processing speed of each pixel in the subsequent image, the pixel mean and pixel variance of the original image can be standardized. The pixel mean can be understood as the pixel average value determined according to the pixel value of each pixel in the original image. The pixel variance can be understood as the mean of the square of the difference between the pixel value of each pixel in the original image and the pixel mean. The standardized processing can be, through the pixel mean and pixel variance, processing the pixel value of each pixel in the original image, so that the pixel mean corresponding to the processed pixel is zero and the pixel variance is unit variance. The standard pixel value can be the pixel value after the standardized processing.
[0037] Specifically, the original image is obtained. According to the pixel value of each pixel in the original image, the pixel mean and pixel variance corresponding to each pixel in the original image are determined. According to the pixel mean and pixel variance, the pixel value of each pixel in the original image is standardized. That is, the pixel value of each pixel is subtracted from the pixel mean to obtain a subtraction result. The subtraction result is divided by the pixel standard deviation corresponding to the pixel variance to obtain a standard pixel value corresponding to each pixel. It should be noted that the pixel mean of each pixel after the above processing is zero mean, and the pixel variance is unit variance. Through the above standardization process, the convergence speed and stability of the subsequent preset clustering algorithm can be improved, thereby improving the efficiency of pixel classification.
[0038] For example, see Figure 2 , Figure 2 is an example diagram of the original image. The original image is taken as a two-dimensional true color image as an example. The data type of the original image can be UInt8. According to the input normalization parameters, such as the NormalizeInput parameter, the original image is selectively normalized. That is, the pixel mean and pixel variance of each pixel in the original image are calculated. And the pixel standard deviation corresponding to each pixel is determined by the pixel variance. The pixel values of each pixel of the original image are normalized by the pixel mean and the pixel standard deviation to obtain the standard pixel value corresponding to each pixel, so that the pixel mean corresponding to each pixel is zero and the pixel variance is unit variance.
[0039] S120, clustering each pixel in the image to be segmented according to a preset clustering algorithm to obtain at least two categories of pixels to be processed, wherein the preset clustering algorithm is a clustering algorithm based on Julia language.
[0040] The preset clustering algorithm may be a K-means clustering algorithm based on the Julia language. At least two categories of pixels to be processed may be obtained after clustering each pixel. The category of the pixels to be processed is consistent with the preset classification threshold. For example, if the preset classification threshold is set to 5, each pixel of the image to be segmented is divided into five categories, that is, there are 5 categories of pixels to be processed.
[0041] Optionally, before clustering the pixels of the image to be segmented using a preset clustering algorithm, clustering parameters associated with the clustering process may be set. The clustering parameters include at least: a preset classification threshold, a preset repetition threshold for repeating the clustering process using a new clustering center, a preset number threshold for each clustering process, and a preset change threshold (convergence threshold) of the clustering algorithm. It should be noted that data preprocessing may also be performed on the clustering parameters to ensure the rationality and correctness of the clustering parameters.
[0042] Specifically, each pixel in the image to be segmented is clustered according to a preset clustering algorithm, and when the number of iterations of each clustering process reaches a preset number threshold or the moving distance of the cluster center is less than a preset change threshold, the pixel to be processed whose number of categories is consistent with the preset classification threshold is obtained. The above clustering process is repeated, and when the number of clustering processes reaches a preset repetition number threshold, the pixel to be processed of at least two categories corresponding to the image to be segmented is obtained.
[0043] S130: Obtain a target image according to at least two categories of to-be-processed pixel points and preset pixel values corresponding to each category.
[0044] The preset pixel value may be a pre-set pixel value corresponding to each category of pixel points. For different categories of pixel points, the corresponding pixel values are different. For example, if there are 5 categories of pixel points to be processed, there are also five categories of preset pixel values. The target image may be an image obtained by processing the image to be segmented with the preset pixel values corresponding to different categories. For example, if there are 5 categories of preset pixel values, the target image may be an image that is consistent with the image size of the image to be segmented and contains five categories of pixel values.
[0045] Specifically, according to the preset pixel values corresponding to each category, the pixel values of the corresponding category are updated to obtain updated pixels to be processed in at least two categories. According to the updated pixels to be processed in at least two categories, the target image is obtained.
[0046] In an embodiment of the present invention, a target image may be determined by: determining the category label corresponding to each pixel to be processed according to the category corresponding to each pixel to be processed, and determining a label matrix to be used corresponding to the image to be segmented according to the category label corresponding to each pixel to be processed; based on the label matrix to be used and the preset pixel value corresponding to each category, updating the pixel value of the pixel at the corresponding position of the preset image to obtain the target image.
[0047] Among them, the category label can be an identifier used to uniquely identify the category of the pixel to be processed. Optionally, the category label can be a number, a letter or other identifier. For example, if there are five categories of pixels to be processed, the category labels 1 to 5 can be used to identify the pixels to be processed in these five categories. The label matrix to be used can be a matrix determined by the category label corresponding to each pixel to be processed in the image to be segmented. The preset image can be a pre-set image that is consistent with the image size of the image to be segmented. Optionally, the preset image can be a pure black image.
[0048] Specifically, according to the category corresponding to each pixel to be processed, the category label corresponding to each pixel to be processed is determined. According to the category label corresponding to each pixel to be processed, a label matrix to be used corresponding to the image to be segmented is obtained. According to the label matrix to be used and the preset pixel value corresponding to each category, the pixel value of the pixel at the corresponding position of the preset image is updated, and the updated preset image is used as the target image.
[0049] Optionally, if the image to be segmented is the original image after standardization processing, at least two categories of pixel points to be processed are updated according to each pixel point of the original image to obtain at least two categories of pixel points to be matched, so as to obtain a target image corresponding to the original image based on at least two categories of pixel points to be matched and the preset pixel values corresponding to each category.
[0050] The pixels to be matched may be the pixels in the original image corresponding to each category.
[0051] Specifically, if the image to be segmented is an image obtained after the original image is standardized, then in order to ensure the accuracy of the subsequent target area, at least two categories of pixels to be matched corresponding to the original image can be determined. That is, at least two categories of pixels to be processed are updated according to each pixel of the original image to obtain at least two categories of pixels to be matched. Based on this, a target image consistent with the image size of the original image can be obtained according to at least two categories of pixels to be matched and the preset pixel values corresponding to each category. For example, the target image can be as follows Figure 3 As shown, Figure 3 The target image uses five preset pixel points to represent the pixel points of five categories.
[0052] Optionally, if the image to be segmented is an image obtained after the pixel values of each pixel in the original image are standardized, the cluster centers corresponding to the pixels to be processed of at least two categories can be denormalized to the cluster centers corresponding to the pixels of the original data. According to the denormalized cluster centers, the pixels to be matched of at least two categories corresponding to the original image are determined. And according to the category label corresponding to each pixel to be matched, a label matrix to be used that is consistent with the image size of the original image is obtained, so as to superimpose the label matrix to be used on a preset image that is consistent with the image size of the original image to obtain a target image. Optionally, the preset image can be a black image. Optionally, the data type of the category label can also be determined according to the number of categories of the pixels to be matched. For example, if the number of categories of the pixels to be matched belongs to [0, 255], the data type of the category label is UInt8. If the number of categories of the pixels to be matched belongs to [256, 65535), the data type of the category label is UInt16. If the number of categories of the pixels to be matched belongs to [65535, 2 32-1), the data type of the category label is Float64.
[0053] The technical solution of this embodiment obtains an image to be segmented, and clusters each pixel in the image to be segmented according to a preset clustering algorithm based on the Julia language to obtain at least two categories of pixels to be processed. The preset clustering algorithm of the Julia language shortens the time for pixel classification, and improves the efficiency and accuracy of pixel classification. According to at least two categories of pixels to be processed and the preset pixel values corresponding to each category, a target image is obtained so that the target image can be applied to various image analyses. The present invention is applicable to a variety of scenarios, solves the problems of the existing K-means clustering algorithm in high-dimensional data processing, noise sensitivity and computational efficiency, and improves the efficiency and accuracy of image segmentation, while ensuring the reliability and accuracy of the target image.
[0054] Embodiment 2
[0055] Figure 4 This is a flow chart of an image segmentation method provided by the second embodiment of the present invention. This embodiment is based on the above embodiment and refines the step of "clustering each pixel in the image to be segmented according to a preset clustering algorithm to obtain at least two categories of pixels to be processed". The specific implementation method can refer to the technical solution of this embodiment. Among them, the technical terms that are the same or corresponding to the above embodiment are not repeated here. Figure 4 As shown, the method includes:
[0056] S210: Acquire an image to be segmented, wherein the image to be segmented is a color image or a grayscale image.
[0057] S220 . Determine at least two to-be-processed cluster centers corresponding to the to-be-segmented image according to a preset clustering algorithm.
[0058] The cluster center to be processed may be the cluster center of the image to be segmented determined according to a preset clustering algorithm.
[0059] Specifically, a preset clustering algorithm based on the Julia language is called, and according to the preset clustering algorithm based on the Julia language, a pixel point in the image to be segmented is randomly determined as the first cluster center to be processed. For other pixel points in the image to be segmented, the minimum pixel distance between each pixel point and the first cluster center to be processed is calculated. According to the minimum pixel distance corresponding to each pixel point, the pixel point with the largest pixel distance from the first cluster center to be processed is determined as the next cluster center to be processed. The above process is repeated until at least two cluster centers to be processed corresponding to the image to be segmented are obtained.
[0060] In an embodiment of the present invention, the method for determining the cluster center to be processed can be: randomly determining the first cluster center to be processed corresponding to the image to be segmented; determining the next cluster center to be processed based on the distance information between each pixel point in the image to be segmented and the first cluster center to be processed; when the number of repeated determinations of the cluster center to be processed reaches a preset classification threshold, at least two cluster centers to be processed are obtained.
[0061] The distance information can be understood as the minimum pixel distance between each pixel and the first cluster center to be processed. The preset classification threshold can be a pre-set value for dividing the image to be segmented into several clusters. For example, the preset classification threshold can be 5, and the image to be segmented can be divided into 5 clusters corresponding to 5 cluster centers to be processed.
[0062] Specifically, according to each pixel of the image to be segmented, a pixel is randomly determined as the first cluster center to be processed of the image to be segmented. According to the distance information between other pixel points in the image to be segmented and the first cluster center to be processed, a pixel point with a larger distance information is selected as the next cluster center to be processed. When the number of times the above determination of the cluster center to be processed is repeated reaches a preset classification threshold, at least two cluster centers to be processed are obtained.
[0063] Exemplarily, the distance information is the square value of the minimum pixel distance between the pixel point and the first cluster center to be processed, and the preset classification threshold is 5 as an example for explanation. According to each pixel point in the image to be segmented, a pixel point is randomly determined as the first cluster center to be processed of the image to be segmented. For other unselected pixels, the minimum pixel distance between each pixel point and the first cluster center to be processed is calculated. According to the positive proportional relationship between the square value of the minimum pixel distance between each pixel point and the first cluster center to be processed and the probability value of the pixel point being determined as the next cluster center to be processed, the pixel point that is farther away from the first cluster center to be processed is used as the next cluster center to be processed. Repeat the above process until 5 cluster centers to be processed are obtained.
[0064] S230. For at least two cluster centers to be processed, determine the pixel distance between each pixel point in the image to be segmented and each cluster center to be processed, and determine at least one pixel point to be used corresponding to each cluster center to be processed based on the pixel distance.
[0065] The pixel distance can be understood as the distance between each pixel point in the image to be segmented and each cluster center to be processed. The pixel points to be used can be the pixel points belonging to the same cluster center to be processed.
[0066] Specifically, for at least two cluster centers to be processed, the pixel distance between each pixel point in the image to be segmented and each cluster center to be processed is determined. The pixel points in the image to be segmented are assigned to the cluster center to be processed with the closest pixel distance thereto, thereby obtaining at least one pixel point to be used corresponding to each cluster center to be processed.
[0067] S240, performing mean processing on pixel coordinate data of at least one pixel point to be used to obtain target pixel coordinate data, and updating the cluster center to be processed to the target pixel point corresponding to the target pixel coordinate data.
[0068] The target pixel coordinate data can be understood as the center point coordinate data corresponding to each pixel to be used. The target pixel point can be understood as the center point of each pixel to be used in the current cluster center to be processed.
[0069] Specifically, for the current cluster center to be processed, the pixel coordinate data of each pixel point to be used in the current cluster center to be processed is averaged to obtain the coordinate data corresponding to the center point. The center point is the target pixel point, and the coordinate data of the center point is the target pixel coordinate data. Based on the target pixel point, the cluster center to be processed is updated. That is, the cluster center to be processed at this time is the target pixel point.
[0070] S250, when the number of repeated updates of the to-be-processed cluster center reaches a preset number threshold or the position change parameter of the to-be-processed cluster center is less than a preset change threshold, obtaining at least two target cluster centers corresponding to the to-be-segmented image.
[0071] The preset number threshold may be a pre-set standard value for updating the number of times the cluster center to be processed is updated. The preset number threshold may be understood as the maximum number of iterations for each clustering process. Optionally, the preset number threshold may be represented by MaxIterations, and the preset number threshold may be 100 times.
[0072] The position change parameter can be used to characterize the position change information of the cluster center to be processed obtained by updating the cluster center to be processed twice in succession. The preset change threshold can be a pre-set standard value of the position change parameter. The preset change threshold, which can also be understood as a convergence threshold or an accuracy threshold, is a condition that determines the stop of the preset clustering algorithm. When the moving position of each cluster center to be processed in continuous iterations is less than the preset change threshold, the preset clustering algorithm is stopped. Optionally, the preset change threshold can be represented by Threshold, and the preset change threshold can be 0.0001.
[0073] Specifically, when the number of repeated updates of the to-be-processed cluster center reaches a preset number threshold or the position change parameter of the to-be-processed cluster center is less than a preset change threshold, at least two target cluster centers corresponding to the to-be-segmented image are obtained.
[0074] Exemplarily, when the number of repeated updates of the cluster center to be processed reaches 100 times or the position change parameter of the cluster center to be processed is less than 0.0001, the preset clustering algorithm stops processing and obtains at least two target cluster centers corresponding to the image to be segmented.
[0075] Optionally, in order to improve the classification accuracy of each pixel point of the image to be segmented and avoid local optimal solutions, the above-mentioned processes S220 to S40 can be repeated, and when the number of repetitions reaches a preset repetition threshold, at least two target clustering centers are obtained, so as to obtain at least two categories of processed pixel points corresponding to the image to be segmented based on the at least two target clustering centers.
[0076] The preset repetition number threshold may be the number of times the process from S220 to S40 is repeated using a new cluster center to be processed, that is, the number of attempts to perform cluster processing. Optionally, the preset repetition number threshold may be represented by NumAttempts. It can be understood that each time the cluster center to be processed is used at a different position to determine the final cluster center, so as to determine the target cluster center from the final cluster center obtained each time.
[0077] S260: Determine at least two categories of pixels to be processed corresponding to the image to be segmented based on at least two target cluster centers.
[0078] The pixels to be processed can be understood as pixels belonging to the same target cluster center.
[0079] Specifically, each pixel in the image to be segmented is divided into at least two categories of pixels to be processed according to the pixel distance between each pixel in the image to be segmented and each target cluster center.
[0080] Exemplarily, the K-means clustering process from S220 to S250 can be explained by the following pseudo code:
[0081] Input: The pixel set X of the image to be segmented, and the preset classification threshold K
[0082] 1) Initialize K cluster centers to be processed
[0083] 2) repeat
[0084] a) For each pixel x_i∈X:
[0085] i. Calculate the pixel distance from x_i to all the cluster centers to be processed
[0086] ii. Assign x_i to the nearest cluster center to be processed
[0087] b) For each category k:
[0088] i. Update the cluster center c_k to be processed as the coordinate mean of all pixels to be used in each category k
[0089] 3) Until the cluster center to be processed does not change, the target cluster center is obtained
[0090] Output: The target cluster center C and the cluster assignment of each pixel in the image to be segmented
[0091] S270: Obtain a target image according to at least two categories of to-be-processed pixel points and preset pixel values corresponding to each category.
[0092] The technical solution of this embodiment is to obtain an image to be segmented, and determine at least two to-be-processed cluster centers corresponding to the image to be segmented according to a preset clustering algorithm. For at least two to-be-processed cluster centers, the pixel distance between each pixel in the image to be segmented and each to-be-processed cluster center is determined, and at least one to-be-used pixel corresponding to each to-be-processed cluster center is determined according to the pixel distance. The pixel coordinate data of at least one to-be-used pixel is processed to obtain target pixel coordinate data, and the to-be-processed cluster center is updated to the target pixel corresponding to the target pixel coordinate data. Based on this, the update of the to-be-processed cluster center is realized, so as to obtain a more accurate cluster center. When the number of repeated updates of the to-be-processed cluster center reaches a preset number threshold or the position change parameter of the to-be-processed cluster center is less than a preset change threshold, at least two target cluster centers corresponding to the image to be segmented are obtained, and the accuracy of the target cluster centers is ensured. According to the at least two target cluster centers, at least two categories of to-be-processed pixel points corresponding to the image to be segmented are determined. According to the to-be-processed pixel points of at least two categories and the preset pixel values corresponding to each category, a target image is obtained, so that the target image can be applied to various image analyses. The present invention is applicable to a variety of scenarios and solves the problems of the existing K-means clustering algorithm in high-dimensional data processing, noise sensitivity and computational efficiency, thereby improving the efficiency and accuracy of image segmentation and ensuring the reliability and accuracy of the target image.
[0093] Embodiment 3
[0094] Figure 5 FIG. 1 is a schematic diagram of the structure of an image segmentation device provided by Embodiment 3 of the present invention. Figure 5 As shown, the device includes: an image acquisition module 310 , a pixel clustering module 320 and a target image determination module 330 .
[0095] The image acquisition module 310 is used to acquire the image to be segmented, wherein the image to be segmented is a color image or a grayscale image; the pixel clustering module 320 is used to cluster each pixel in the image to be segmented according to a preset clustering algorithm to obtain at least two categories of pixels to be processed, wherein the preset clustering algorithm is a clustering algorithm based on the Julia language; the target image determination module 330 is used to obtain the target image based on at least two categories of pixels to be processed and the preset pixel values corresponding to each category.
[0096] The technical solution of this embodiment obtains an image to be segmented, and clusters each pixel in the image to be segmented according to a preset clustering algorithm based on the Julia language to obtain at least two categories of pixels to be processed. The preset clustering algorithm of the Julia language shortens the time for pixel classification, and improves the efficiency and accuracy of pixel classification. According to at least two categories of pixels to be processed and the preset pixel values corresponding to each category, a target image is obtained so that the target image can be applied to various image analyses. The present invention is applicable to a variety of scenarios, solves the problems of the existing K-means clustering algorithm in high-dimensional data processing, noise sensitivity and computational efficiency, and improves the efficiency and accuracy of image segmentation, while ensuring the reliability and accuracy of the target image.
[0097] On the basis of the above embodiment, optionally, an image acquisition module is used to acquire the original image and determine the pixel mean and pixel variance corresponding to each pixel point in the original image; based on the pixel mean and pixel variance, the pixel value of each pixel point in the original image is standardized to obtain a standard pixel value corresponding to each pixel point, and based on each pixel point with the standard pixel value, an image to be segmented is obtained.
[0098] Optionally, the pixel clustering module includes: a unit for determining cluster centers to be processed, which is used to determine at least two cluster centers to be processed corresponding to the image to be segmented based on a preset clustering algorithm; a unit for determining pixels to be used, which is used to determine the pixel distance between each pixel in the image to be segmented and each cluster center to be processed for at least two cluster centers to be processed, and determine at least one pixel to be used corresponding to each cluster center to be processed based on the pixel distance; a unit for updating cluster centers to be processed, which is used to perform mean processing on pixel coordinate data of at least one pixel to be used to obtain target pixel coordinate data, and update the cluster center to be processed to a target pixel corresponding to the target pixel coordinate data; a unit for determining target cluster centers, which is used to obtain at least two target cluster centers corresponding to the image to be segmented when the number of repeated updates of the cluster centers to be processed reaches a preset number threshold or the position change parameter of the cluster centers to be processed is less than a preset change threshold; and a unit for determining pixels to be processed, which is used to determine at least two categories of pixels to be processed corresponding to the image to be segmented based on the at least two target cluster centers.
[0099] Optionally, a unit for determining the cluster center to be processed is used to randomly determine the first cluster center to be processed corresponding to the image to be segmented; determine the next cluster center to be processed based on the distance information between each pixel point in the image to be segmented and the first cluster center to be processed; and obtain at least two cluster centers to be processed when the number of repeated determinations of the cluster center to be processed reaches a preset classification threshold.
[0100] Optionally, a target image determination module is used to determine the category label corresponding to each pixel to be processed according to the category corresponding to each pixel to be processed, and to determine the label matrix to be used corresponding to the image to be segmented according to the category label corresponding to each pixel to be processed; based on the label matrix to be used and the preset pixel value corresponding to each category, the pixel value of the pixel at the corresponding position of the preset image is updated to obtain the target image.
[0101] Optionally, the device also includes: a pixel update module, which is used to update at least two categories of pixel points to be processed based on each pixel point of the original image if the image to be segmented is the original image after standardization processing, so as to obtain at least two categories of pixel points to be matched, so as to obtain a target image corresponding to the original image based on at least two categories of pixel points to be matched and preset pixel values corresponding to each category.
[0102] The image segmentation device provided in the embodiment of the present invention can execute the image segmentation method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.
[0103] Embodiment 4
[0104] Figure 6 1 is a schematic diagram of the structure of an electronic device provided in Embodiment 4 of the present invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device may also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices (such as helmets, glasses, watches, etc.) and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present invention described and / or required herein.
[0105] like Figure 6As shown, the electronic device 10 includes at least one processor 11, and a memory connected to the at least one processor 11, such as a read-only memory (ROM) 12, a random access memory (RAM) 13, etc., wherein the memory stores a computer program that can be executed by at least one processor, and the processor 11 can perform various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 12 or the computer program loaded from the storage unit 18 to the random access memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 can also be stored. The processor 11, the ROM 12, and the RAM 13 are connected to each other through a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0106] A number of components in the electronic device 10 are connected to the I / O interface 15, including: an input unit 16, such as a keyboard, a mouse, etc.; an output unit 17, such as various types of displays, speakers, etc.; a storage unit 18, such as a disk, an optical disk, etc.; and a communication unit 19, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0107] The processor 11 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as an image segmentation method.
[0108] In some embodiments, the image segmentation method may be implemented as a computer program, which is tangibly contained in a computer-readable storage medium, such as a storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on the electronic device 10 via the ROM 12 and / or the communication unit 19. When the computer program is loaded into the RAM 13 and executed by the processor 11, one or more steps of the image segmentation method described above may be performed. Alternatively, in other embodiments, the processor 11 may be configured to perform the image segmentation method in any other appropriate manner (e.g., by means of firmware).
[0109] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0110] The computer program for implementing the image segmentation method of the present invention can be written in any combination of one or more programming languages. These computer programs can be provided to a processor of a general-purpose computer, a special-purpose computer or other programmable data processing device, so that when the computer program is executed by the processor, the functions / operations specified in the flow chart and / or block diagram are implemented. The computer program can be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0111] Embodiment 5
[0112] Embodiment 5 of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to execute an image segmentation method, the method comprising:
[0113] An image to be segmented is obtained, wherein the image to be segmented is a color image or a grayscale image; each pixel in the image to be segmented is clustered according to a preset clustering algorithm to obtain at least two categories of pixel points to be processed, wherein the preset clustering algorithm is a clustering algorithm based on the Julia language; a target image is obtained according to the at least two categories of pixel points to be processed and the preset pixel values corresponding to each category.
[0114] In the context of the present invention, a computer-readable storage medium may be a tangible medium that may contain or store a computer program for use by or in combination with an instruction execution system, device or equipment. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices or equipment, or any suitable combination of the foregoing. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0115] To provide interaction with a user, the systems and techniques described herein may be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or trackball) through which the user can provide input to the electronic device. Other types of devices may also be used to provide interaction with the user; for example, the feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form (including acoustic input, voice input, or tactile input).
[0116] The systems and techniques described herein may be implemented in a computing system that includes backend components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0117] A computing system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The client and server relationship is generated by computer programs running on the corresponding computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or cloud host, which is a host product in the cloud computing service system to solve the defects of difficult management and weak business scalability in traditional physical hosts and VPS services.
[0118] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps described in the present invention can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solution of the present invention can be achieved, and this document does not limit this.
[0119] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.
Claims
1. An image segmentation method, characterized in that: include: Acquire an image to be segmented, wherein the image to be segmented is a color image or a grayscale image; Clustering each pixel in the image to be segmented according to a preset clustering algorithm to obtain at least two categories of pixel points to be processed, wherein the preset clustering algorithm is a clustering algorithm based on the Julia language; A target image is obtained according to the at least two categories of pixel points to be processed and the preset pixel values corresponding to each of the categories.
2. The method according to claim 1, characterized in that The step of obtaining the image to be segmented comprises: Acquire an original image, and determine a pixel mean and a pixel variance corresponding to each pixel point in the original image; The pixel value of each pixel in the original image is standardized according to the pixel mean and the pixel variance to obtain a standard pixel value corresponding to each pixel, and the image to be segmented is obtained based on each pixel of the standard pixel value.
3. The method according to claim 1, characterized in that The clustering process is performed on each pixel in the image to be segmented according to a preset clustering algorithm to obtain at least two categories of pixel points to be processed, including: Determine at least two to-be-processed cluster centers corresponding to the to-be-segmented image according to a preset clustering algorithm; For the at least two cluster centers to be processed, determine the pixel distance between each pixel point in the image to be segmented and each of the cluster centers to be processed, and determine at least one pixel point to be used corresponding to each of the cluster centers to be processed according to the pixel distance; Performing mean processing on the pixel coordinate data of the at least one pixel point to be used to obtain target pixel coordinate data, and updating the to-be-processed cluster center to be the target pixel point corresponding to the target pixel coordinate data; When the number of repeated updates of the to-be-processed cluster center reaches a preset number threshold or the position change parameter of the to-be-processed cluster center is less than a preset change threshold, at least two target cluster centers corresponding to the to-be-segmented image are obtained; At least two categories of pixels to be processed corresponding to the image to be segmented are determined according to the at least two target cluster centers.
4. The method according to claim 3, characterized in that The step of determining at least two to-be-processed cluster centers corresponding to the to-be-segmented image includes: Randomly determine a first to-be-processed cluster center corresponding to the to-be-segmented image; Determining the next cluster center to be processed according to the distance information between each pixel point in the image to be segmented and the first cluster center to be processed; When the number of times of repeatedly determining the cluster centers to be processed reaches a preset classification threshold, at least two cluster centers to be processed are obtained.
5. The method according to claim 1, characterized in that The step of obtaining a target image according to the at least two categories of pixels to be processed and the preset pixel values corresponding to each category includes: Determine the category label corresponding to each pixel to be processed according to the category corresponding to each pixel to be processed, and determine the label matrix to be used corresponding to the image to be segmented according to the category label corresponding to each pixel to be processed; Based on the label matrix to be used and the preset pixel value corresponding to each of the categories, the pixel value of the pixel point at the corresponding position of the preset image is updated to obtain the target image.
6. The method according to claim 1, characterized in that The method further comprises: If the image to be segmented is an original image after standardization processing, the at least two categories of pixel points to be processed are updated according to each pixel point of the original image to obtain at least two categories of pixel points to be matched, so as to obtain a target image corresponding to the original image based on the at least two categories of pixel points to be matched and the preset pixel values corresponding to each of the categories.
7. An image segmentation device, characterized in that: include: An image acquisition module, used for acquiring an image to be segmented, wherein the image to be segmented is a color image or a grayscale image; A pixel clustering module, used for clustering each pixel in the image to be segmented according to a preset clustering algorithm to obtain at least two categories of pixels to be processed, wherein the preset clustering algorithm is a clustering algorithm based on the Julia language; The target image determination module is used to obtain the target image according to the at least two categories of pixel points to be processed and the preset pixel values corresponding to each category.
8. An electronic device, characterized in that: The electronic device comprises: at least one processor; and a memory communicatively connected to the at least one processor; wherein, The memory stores a computer program executable by the at least one processor, and the computer program is executed by the at least one processor so that the at least one processor can perform the image segmentation method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer instructions, and the computer instructions are used to enable a processor to implement the image segmentation method according to any one of claims 1 to 6 when executed.
10. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the computer program implements the image segmentation method according to any one of claims 1 to 6.