Dot painting generation method based on adaptive clustering and linear programming optimization point selection

By employing an algorithm based on superpixel adaptive clustering and linear programming to optimize point selection, the problems of color gradient level control and image edge details in color dot pattern generation are solved, resulting in high-quality color dot pattern images suitable for low-cost color/black and white printing and neon advertising images.

CN116452686BActive Publication Date: 2026-04-17HUBEI UNIV OF TECH
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
HUBEI UNIV OF TECH
Filing Date
2023-03-03
Publication Date
2026-04-17

AI Technical Summary

Technical Problem

Existing color dot plot generation methods have shortcomings in controlling color gradient levels and image edge details. Furthermore, the dot plot images generated by traditional methods are of low quality, especially in color images where the sense of color gradation is ignored and the color differences within superpixels are significant.

Method used

An algorithm based on superpixel adaptive clustering and linear programming for point selection is adopted. The image is initially divided by the SLIC superpixel algorithm, and further divided into sub-clusters by combining color density peak adaptive clustering and the triangle elbow method. The target optimization model of SSIM value is used to select points in the sub-clusters to form high-quality color dot painting.

Benefits of technology

It improves the visualization effect of color dotted images, achieves uniform distribution of dots and preservation of color gradient levels, and significantly improves the quality of generated dotted images, enabling applications in low-cost color/black and white printing and neon advertising images.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116452686B_ABST
    Figure CN116452686B_ABST
Patent Text Reader

Abstract

This invention discloses a dotted image generation method based on adaptive clustering and linear programming for optimal point selection. The algorithm first preprocesses the image using superpixels, dividing the original image into superpixel blocks with similar colors to reduce the processing scale. However, these pixel blocks still contain subsets with color jumps. Therefore, an adaptive clustering method based on color density peaks is used to further divide the superpixel blocks into smaller sub-clusters, and the triangle elbow method is used for verification to ensure that there are no significant color jumps within the sub-clusters. Then, the generation sampling radius is determined based on the color mean within the sub-clusters. Finally, the optimal point selection model for linear programming is determined based on the image similarity index SSIM. Experiments demonstrate that the proposed color dotted image generation algorithm outperforms most existing methods in terms of visual effect and SSIM / PSNR scores, and has wide applications in low-cost color / black-and-white printing and pixel art.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of digital image processing technology, and relates to an algorithm for generating color dotted images, particularly a dotted image generation method based on adaptive clustering and linear programming for optimizing point selection. Background Technology

[0002] Pointillism is one of the most widely used non-photorealistic rendering techniques in computer graphics. As an art form that represents images with points, one of the key issues is the placement of these points. Generally, they should be evenly distributed within the same set while also possessing a degree of randomness. Blue noise sampling methods provide these characteristics and are widely used in computer graphics. However, color pointillism is more challenging because each channel must simultaneously maintain a uniform distribution. Existing methods treat color pointillism as a multi-class blue noise sampling problem, sacrificing processing time for high-quality results.

[0003] Currently, dot-mapping algorithms also have broad application prospects in low-cost color and black-and-white printing, neon advertising images, and the construction of dot-mapping images by aerial drones.

[0004] Traditional computer-aided pointillism generation methods involve drawing sparse points with large radii and grayscale values ​​in brighter areas, while using numerous dense points with smaller radii in darker areas. This algorithm can reproduce the artist's creative process and improve the drawing effect, but it still has some shortcomings in controlling color gradation and edge details in color images. For example, the sense of color gradation is often ignored in black and white pointillism, while this important factor must be considered in color pointillism. Chinese invention patent CN115619884A, a pointillism generation method and device based on superpixels and a color knapsack algorithm, proposes using superpixels for initial image segmentation. Superpixels are small regions composed of a series of adjacent pixels with similar color, brightness, and texture characteristics. These small regions can retain effective image information and generally do not destroy the boundary information of objects in the image. However, within superpixels, there are still some points with significant color differences. Verification showed that, calculated with 256 grayscale values, the maximum color difference within superpixels of some images reached 70. The method used in black and white dotted images is to further divide the superpixel set into two sub-clusters. However, experiments show that two sub-clusters are not the best division result. It has been verified that the optimal division for most sub-clusters fluctuates between 2, 3, and 4 (not exceeding 4). Therefore, the dotted image generation method produces low-quality dotted images. Summary of the Invention

[0005] To further improve the quality of color-generated dot matrix images, this invention discloses a point selection algorithm based on superpixel adaptive clustering and linear programming optimization. Based on the initial superpixel segmentation of the image, this algorithm further uses an adaptive clustering method based on density peaks to obtain the optimal number of clusters and perform the segmentation. The algorithm then uses the color mean of each sub-cluster as the optimal interval distance for point selection within that sub-cluster. Simultaneously, based on the SSIM index, a target optimization model is established, and the gurobi mathematical optimizer is used to implement the model's point selection. This ensures that the points are evenly distributed while maintaining color gradation, thereby improving the visualization effect of the generated dot matrix image.

[0006] To achieve the technical effects of this invention, the technical solution is as follows: a point drawing generation method based on adaptive clustering and linear programming for optimal point selection, comprising the following steps:

[0007] Step 1: The SLIC superpixel algorithm is used to perform preliminary segmentation of the image, dividing the input image into a series of superpixel blocks with clear boundaries and compact space. In subsequent processing, superpixel blocks are used instead of pixels as the basic unit for operation.

[0008] Step 2: The superpixel blocks are further adaptively divided into appropriate sub-clusters using a color density peak-based adaptive clustering algorithm and the triangle elbow method.

[0009] Step 3: Select the most suitable point in the sub-cluster using a target optimization model based on SSIM values;

[0010] Step 4: Assign the original color to all selected points, and change the background color to the remaining points to form a new colored dotted image.

[0011] Furthermore, the specific implementation of the color density peak-based adaptive clustering algorithm in step 2 is as follows;

[0012] Step 2.1: First, preprocessing is performed to obtain the density decision map;

[0013] Step 2.2: Then, perform pre-clustering. Sort the points in the decision graph in ascending order of their density, calculate the maximum density difference and the average density difference, and remove the data points to the left of the point with the maximum density change in the decision graph as noise points. Select points with a density greater than the average value and a diffusion distance greater than the average value as the initial cluster centers. The average value is obtained by averaging the density values ​​of all data points after removing noise points. The list of cluster center points is denoted as... That is, there are k initial clusters;

[0014] Step 2.3: Finally, merge clusters based on the point-to-point distance of the initial cluster centers.

[0015] Furthermore, the specific implementation method for obtaining the density decision map in step 2.1 is as follows;

[0016] 2.2.1 Let I be the set of each superpixel, and let p be the set of points. i =(x i ,y i ,c i ), where i represents different point numbers, c i The different colors representing that point, x i ,y i These represent the x-coordinate and y-coordinate of the point, respectively.

[0017] Define the calculation of the color distance d between any two points i and j. ij It is composed of the exponent of the Euclidean distance and the color difference;

[0018]

[0019] 2.1.2, Local point density ρ is defined according to the Gaussian kernel function. i :

[0020]

[0021] Set the cutoff distance as d c d c The calculation formula is:

[0022]

[0023] 2.1.3 Calculate the diffusion distance at any point

[0024] For the data point p with the highest density i diffusion distance δ i The diffusion distance δi is the maximum value of all distances between pixel pairs. For any other pixel, the diffusion distance δi is the minimum value of all distances from it to all pixels with a density greater than its own. Therefore, the diffusion distance of pixel pi can be calculated in the following two cases:

[0025]

[0026] 2.1.4. Draw a decision diagram with density ρ as the abscissa and diffusion distance δ as the ordinate.

[0027] Furthermore, the specific implementation method of step 2.3 is as follows;

[0028] 2.3.1 Suppose that there are k initial clusters obtained from the pre-clustering, with categories {class1, class2, ..., class...} k}, where len is the number of categories, initially set to k, and the initial point-to-point distance from the center is... Then sort them in ascending order; let the existence duration sequence corresponding to the initial classification method be {alive1, alive2, ..., alive}. k The initial values ​​are all 0, and the maximum duration is set to max_last_time = -1;

[0029] 2.3.2, When k > 1, perform the following operations in a loop:

[0030] Search sequentially for the two nearest cluster centers in the initial cluster center queue. Set as p1_center min_1 p2_center min_2 The class corresponding to the two points id They belong to category p1 respectively class1 and p1 clsss2 Skip cluster pairs whose cluster center distance is -1, and the initial distance between clusters is not -1;

[0031] If p1 class1 ≠p1 class2 Then p1 class1 =len+1 and p1 class2 =len+1, and set the category attribute of all points in these two classes to the new category with a category number of len+1, and add the new category number to the category number table {class1, class2, ..., class...} k From} we get {class1, class2, ..., class k The expression `len+1` indicates that these two categories are merged into a new cluster, the category number `len` is increased by 1, and the current total number of clusters `k = k-1`, indicating that the total number of categories has decreased by 1, and the distance between the two nearest cluster centers is set to -1.

[0032] If they are in the same class, p1 class1 =p1 class2 If k remains unchanged;

[0033] Increment the duration of the classification method corresponding to this number of categories by 1, alive k =alive k +1;

[0034] If currently alive k >max_last_time, then max_last_time=alive k using points record Record the sequence of cluster centers containing the new category labels. Record the new classification of the cluster center point when the maximum existence duration is reached;

[0035] The loop ends when k=1;

[0036] 2.3.3, based on the points in 2.3.2 record The final stored cluster center table contains the class results. id The display shows the number of clusters calculated, and the final result is taken as the optimal number of clusters. Multiple centroids belonging to the same cluster after merging can be selected as any one of them as the centroid.

[0037] Furthermore, in step 2, the triangular elbow method is an optimal K-value selection algorithm based on the sum of squared clustering errors (SSE) and K-means clustering, used to obtain the optimal number of clusters for a set of data points.

[0038] Furthermore, the specific implementation of the triangular elbow method in step 2 is as follows;

[0039] Step 2a: Set the maximum number of cluster attempts, n, as a preset parameter for K-means clustering to divide the initial clusters. The result of each division is KC. n ={C1, ..., C n};

[0040] Step 2b: Calculate the sum of squared clustering errors (SSE).

[0041]

[0042] In formula (5), C i It is the i-th cluster, and p is C i The pixels in m i It is C i The cluster centers are determined by SSE, which is the clustering error of all samples. The values ​​of SSE are calculated to form a list of values ​​{SSE1, SSE2, ..., SSE...}. n};

[0043] Step 2c, convert the value list {SSE1, SSE2, ..., SSE...} n Normalized, the SSE value corresponds to the vertical axis, and the subscripts {1, 2, ... n} correspond to the horizontal axis. Connecting them forms a line graph.

[0044] Step 2d: Starting from the first point, connect every three adjacent points to form a triangle, a i b i c i These represent the lengths of the three sides of the triangle, and the cosine values ​​between each elbow point are calculated using formula (6).

[0045]

[0046] Where, β i It is the included angle between the points that are the middle of three adjacent points;

[0047] Step 2e: Calculate the angles corresponding to the inverse cosines based on the cosine value sequence: {α2, α3, ..., α...} n-1};

[0048] Step 2f, calculate id = index(min{α2, α3, ..., α... n-1 The index of the minimum angle between elbows obtained by calculation is the potential optimal cluster number.

[0049] Furthermore, the SSIM value is calculated in step 3 as follows;

[0050] Given two images x and y, SSIM compares the similarity of images x and y in three aspects: brightness l(x, y), contrast c(x, y), and structure s(x, y). Brightness is estimated using the mean, contrast using the standard deviation, and structure using the covariance. The final similarity between x and y is the product of these three factors; where μ... x and μ y σ x and σ y The mean and standard deviation of x and y are respectively, σ xy Let x be the covariance of y;

[0051] C1, C2, and C3 are positive constants used to prevent division by zero in the formula.

[0052] C1=(K1*L)*(K1*L)

[0053] C2=(K2*L)*(K2*L)

[0054] C3 = C2 / 2

[0055] The default values ​​are K1 = 0.01, K2 = 0.03, and L = 255.

[0056]

[0057]

[0058]

[0059] The product of these three functions is the SSIM function SSIM(x, y), as shown in the following equation:

[0060]

[0061] Furthermore, the specific implementation method of step 3 is as follows;

[0062] Let P be the set of points in the sub-cluster, and p be the set of points in the sub-cluster. i Let P be any point in P, where P = {p1, p2, ..., P}. N}; N represents the number of points in the set, and each point p i There are 3 attributes (coordinate_x) i coordinate_y i c i ), representing point p respectively. i x-axis, y-axis, color number, where c i The range of variation is 0-255, coordinate_x i The range of variation is w min ~w max w min ~w max The coordinate_y represents the minimum and maximum values ​​of the x-coordinate. i The range of variation is w min ~w max h min ~h max The ordinate represents the minimum and maximum values.

[0063] Calculate the distance matrix Dis_Matrix between points within each sub-cluster;

[0064]

[0065] Point p i and point p j The distance between them;

[0066] Let the decision variable be x. i x i Let x be a variable between 0 and 1, representing the i-th point being selected and retaining its original color. i =1, otherwise x is not selected. i =0; Set the indicator variable to: y ij u ij w ij The ultimate objective function is to minimize the color difference between the selected and unselected points and the original image, i.e.:

[0067]

[0068] Among them, the selected points have the same color as the original image and the pixel difference with the original image is 0, while the unselected points have a white background and the gray value of the white pixels is 255.

[0069] The objective function described above satisfies the following constraints:

[0070] Constraint 1: The total number of selected points must be less than γ times the total number of points;

[0071]

[0072] Constraint 2, set indicator variable y ij Constraints, y ij The distance between all pairs of points in the sub-clusters, if point p i p j One of them was not selected, namely x i and x j If at least one of them is 0, then y ij The value is 0, meaning both points are selected, i.e., x. i and x j If both are 1, then y ij The Euclidean distance between two points;

[0073]

[0074] Constraint 3, set indicator variable w ij Constraints, w ij A value of 1 indicates all variables y ij The point greater than ε, i.e., p i p j All selected points, w ij A value of 0 indicates all variables y ij The point greater than ε, i.e., p i p j At least one item was not selected;

[0075] w ij =1 if y ij ≥ε

[0076] Constraint 4, set indicator variable w ij constraint;

[0077] w ij =0 if y ij <ε

[0078] Where e is a constant that is set;

[0079] Constraint 5, set indicator variable u ij Constraint, u ij p represents the new distance between all pairs of points, which differs from the original Euclidean distance. i p j When there are unselected points, u ij If it is very large, and both points are selected, u ijThis uses the normal Euclidean distance, thus masking all unselected point pairs:

[0080] u ij =y ij +(1-w ij )*M

[0081] M is an integer that is set;

[0082] Constraint 6 sets the indicator variable z constraint, where z is the distance u between the selected point and the specified point. ij The minimum value of the sequence;

[0083] z = min(u ij )

[0084] Constraint 7, set indicator variable u ij Upper limit constraint: the maximum distance between all selected point pairs must be less than twice the color radius;

[0085]

[0086] Constraint 8, set indicator variable u ij The lower bound constraint requires that the minimum distance between all selected point pairs must be greater than the color radius.

[0087]

[0088] Furthermore, color radius The calculation formula is as follows;

[0089]

[0090] Where r(color) is the color radius. The parameter color represents the color mean of the sub-cluster.

[0091] This invention proposes a method for generating color dot paintings based on superpixel adaptive clustering and a linear programming optimization point selection algorithm. This technique, using a computer as a tool, generates artistic dot painting images with unique attributes such as artistic style at near real-time speeds, based on original images. Experiments show that, under the same conditions, this method achieves better results in generating artistic dot paintings, not only using fewer pixels and reducing costs, but also producing high-quality dot painting effects. Therefore, it has wide applications in low-cost color / black-and-white printing and pixel art. Attached Figure Description

[0092] Figure 1 This is a flowchart illustrating an embodiment of the present invention;

[0093] Figure 2 This is a comparison diagram of the present invention and the structure-aware algorithm;

[0094] Figure 3 This is a comparison chart of the present invention and the IVS-based radius adjustment algorithm;

[0095] Figure 4 This is a comparison chart of the color tone algorithm of this invention and the digital color panel.

[0096] Figure 5 Comparison of colored dot painting effects on the lenna.png image;

[0097] Figure 6 Comparison chart of the optimization results of point selection in linear programming;

[0098] Figure 7 A graph showing the change in the angle between the lines representing the SSE relationship;

[0099] Figure 8 To construct a three-dimensional surface graph for the functions l(x,y) and c(x,y). Detailed Implementation

[0100] To facilitate understanding and implementation of the present invention by those skilled in the art, the present invention will be further described in detail below with reference to the accompanying drawings and examples. It should be understood that the embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.

[0101] Please see Figure 1 This invention provides a method for generating color dots based on superpixel adaptive clustering and linear programming optimization point selection algorithm, comprising the following steps:

[0102] Step 1: The SLIC superpixel algorithm is used to initially divide the image into a series of hundreds of superpixels with clear boundaries and compact space. In subsequent image processing, superpixel blocks are used instead of pixels as the basic unit for operation.

[0103] Step 2: The superpixels are further adaptively divided into suitable sub-clusters using a color density peak-based adaptive clustering algorithm and the triangle elbow method.

[0104] Step 3: Use the target optimization model based on SSIM value to select the most suitable point in the sub-cluster.

[0105] Step 4: Assign the original color to all selected points, and change the background color to the remaining points to form a new colored dotted image.

[0106] In step one, we have already obtained the superpixel image. We then use a custom color density peak clustering adaptive algorithm to further divide the superpixel clusters into sub-clusters. The specific implementation is as follows:

[0107] Preprocessing: Each superpixel set is denoted as I, and the points within each set are composed of triples. p i =(x i y i c i ), where i represents different point numbers, c i The different colors representing that point, x i y i These represent the x-coordinate and y-coordinate of the point, respectively.

[0108] 1. Define and calculate the color distance d between any two points i and j. ij It is composed of the Euclidean distance and the exponent of the color difference, where the color difference between two points is the main factor affecting the distance.

[0109]

[0110] 2. Define the local point density ρ according to the Gaussian kernel function. i .

[0111] Even when there are large differences in density between clusters, this density estimation method can still distinguish their densities well. The Gaussian kernel function is defined as follows:

[0112]

[0113] Set the cutoff distance as d c ;

[0114] The sensitive parameter d of this algorithm c The truncation distance is actually the neighborhood radius of the cluster center. Its selection is based on the center point position of the superpixel image region. The magnitude of this value affects the computational complexity of the algorithm and can be adjusted according to requirements. d c The calculation formula is:

[0115]

[0116] 3. Calculate the diffusion distance at any point.

[0117] For the data point p with the highest density i diffusion distance δ i It is the maximum value of all distances between pixel pairs; for any other pixel, the diffusion distance δ is... i It is the minimum value of all distances from pixel p to all pixels with a density greater than its own. Therefore, pixel p i The diffusion distance can be calculated in the following two cases:

[0118]

[0119] 4. Draw a ρ-δ decision diagram with density ρ on the x-axis and diffusion distance δ on the y-axis.

[0120] 5. Pre-clustering class:

[0121] Step 1: Sort all points in ascending order of density.

[0122] Sort the points in the decision graph in ascending order of their density, and calculate the maximum density difference and the average density difference.

[0123] Step 2: Treat the data points to the left of the point with the largest density change in the decision graph as noise points and remove them;

[0124] Step 3: Select points with density and diffusion distance greater than the average as initial cluster centers, aiming to achieve the highest possible density and cohesion among these points. The average density is obtained by averaging the density values ​​of all data points after removing noise points. Let the list of cluster centers be denoted as... There are k initial clusters. Typically, the number of initial clusters is much larger than the actual number of clusters. Let each point in the initial cluster center list be...

[0125] 6. Merge clusters:

[0126] Step 1: Suppose that there are k initial clusters obtained in step 5, with categories {class1, class2, ..., class...} k}, where len is the number of categories, initially set to k, and the initial point-to-point distance from the center is... Then sort them in ascending order; let the existence duration sequence corresponding to the initial classification method be {alive1, alive2, ..., alive}. k}, with all initial values ​​set to 0. For example, alive5 represents the duration of a category 5, and the maximum duration is set to max_last_time = -1.

[0127] Step 2: When k > 1, execute the process repeatedly.

[0128] Search sequentially for the two nearest cluster centers in the initial cluster center queue. Set as p1_center min_1 p2_center min_2 The class corresponding to the two points id They belong to category p1 respectively clsss1 and p1 clsss2 Skip cluster pairs whose cluster center distance is -1, and the initial distance between clusters is not -1.

[0129] If p1 class1 ≠p1 class2(If they are not in the same class), then p1 class1 =len+1 and p1 class2 =len+1, and set the category attribute of all points in these two classes to the new type, with a type number of len+1, and add the new class number to the category number table {class1, class2, ..., class...} k In the context of}, it becomes {class1, class2, ..., class...} k The expression `len+1` indicates that these two categories are merged into a new cluster, the category number `len` is increased by 1, and the current total number of clusters `k` = `k-1`, indicating that the total number of categories is reduced by 1, and the distance between the two nearest cluster center points is set to -1.

[0130] If they are in the same class, p1 class1 =p1 class2 If k remains unchanged, then k remains the same.

[0131] Increment the duration of the classification method corresponding to this number of categories by 1, alive k =alive k +1.

[0132] If currently alive k >max_last_time, then max_last_time=alive k using points record Record the cluster centroid sequence containing the new category label. Record the new classification of the cluster center point when the maximum existence duration is reached;

[0133] The loop ends when k=1.

[0134] Step 3: Based on the points in Step 2 record The final stored cluster center table contains the class results. ia The display shows the calculated number of clusters; the final result is taken as the optimal number of clusters. Multiple centroids belonging to the same cluster after merging can be selected as any one of them.

[0135] 7. Verification based on the elbow method using triangles

[0136] The elbow method is an algorithm for selecting the optimal K value based on the sum of squared errors (SSE) and K-means clustering. It's used to determine the optimal number of clusters for a set of data points, typically suitable for relatively small K values. The core idea of ​​the elbow method is that as the number of clusters K increases, the sample segmentation becomes more refined, the clustering degree increases, and the SSE decreases. When the number of clusters K is much smaller than the actual number of clusters, continuously increasing K leads to a higher degree of clustering, thus significantly decreasing the SSE. However, when K reaches the actual number of clusters, the clustering degree stabilizes, and further increases in K don't cause significant changes, so the decrease in SSE slows down considerably and eventually stabilizes as K continues to increase. In essence, the line graph of the relationship between SSE and K resembles the shape of an elbow. By comparing the SSE of each cluster, the K value corresponding to the most extreme difference in the elbow angle is identified as the optimal K value. Furthermore, to prevent indistinct elbow points (such as...) from appearing in the graph when the relationship is relatively smooth, the elbow method is used. Figure 3 As shown, in special cases where the value of the elbow point is unclear, the determination of the K value may be biased, thus affecting the final clustering result. The angles of each elbow point in the relationship line graph are mainly determined manually by observation, which is inconvenient in practice. Therefore, when validating the optimal clustering, we designed an elbow method based on the automatic determination of the triangle angle sequence.

[0137] The algorithm steps are as follows:

[0138] Step 1: Set the maximum number of cluster attempts, n, sequentially. The value of n ranges from 1 to 7. This is used as a preset parameter for K-means clustering to divide the initial clusters. The result of each division is KC. n ={C1, ..., C n}

[0139] Step 2: Calculate the sum of squared errors (SSE)

[0140]

[0141] In formula (5), C i It is the i-th cluster, p is the pixel in C, m i It is C i The cluster centers are determined by the clustering error (SSE) of all samples, which is typically used to quantify the clustering error and represents the quality of the clustering. We take the values ​​of n sequentially as 1, 2, 3, 4, 5, 6, 7, and calculate the SSE values, forming a list of values ​​{SSE1, SSE2, ..., SSE...}. n}, n = 7.

[0142] Step 3: Create a list of values ​​{SSE1, SSE2, ..., SSE...} nNormalized, the SSE value corresponds to the ordinate, and the subscripts {1, 2, ... n} correspond to the abscissa. Connecting these subscripts forms a line graph, as shown below. Figure 7 As shown.

[0143] Step 4: Starting from the first point, connect every 3 points to form a triangle, and calculate the sum of the sums ... i For example, the angle formed by the connecting lines is ∠(SSE1, SSE2, SSE3), which means that SSE2 is the vertex, and the three sides are a2, b2, and c2 respectively. The SSE values ​​at each vertex are calculated sequentially. i The Euclidean distance between adjacent points, and the distance along the longest side. i b i c i These represent the lengths of the three sides of the triangle. The cosine values ​​between each elbow point are calculated using Formula 6.

[0144]

[0145] Where, β i It is the included angle between the points that are the middle of three adjacent points;

[0146] Step 4: Calculate the angles corresponding to the inverse cosines based on the cosine value sequence: {α2, α3, α4, α5, α6}

[0147] Step 5: The index of the minimum angle between elbows calculated by id = index(min{α2, α3, α4, α5, α6}) is the potential optimal cluster number.

[0148] Since the angle between SSE curves is usually obtuse, the angle with the smallest angle in the obtuse angle list reflects the maximum rate of change of the broken line.

[0149] 8. To ensure that the points selected in each sub-cluster are as close as possible to the original image, we use the optimization metric from SSIM as the optimal objective for point selection. This metric should reflect a sense of hierarchy, allowing even a small number of abrupt color changes to be displayed with a certain probability, while also ensuring that the point density reflects the color intensity. The improved algorithm defines the interval radius of point selection using the color mean (color) of the sub-clusters. The radius formula is set as follows:

[0150]

[0151] Given two images x and y, SSIM compares the similarity of images x and y in three aspects: brightness l(x, y), contrast c(x, y), and structure s(x, y). Brightness is estimated using the mean, contrast using the standard deviation, and structure using the covariance. The final similarity between x and y is the product of these three factors. Where μ x and μ y σ x and σy The mean and standard deviation of x and y are respectively, σ xy Let x be the covariance of y.

[0152] C1, C2, and C3 are positive constants used to prevent division by zero errors in the formula.

[0153] C1=(K1*L)*(K1*L)

[0154] C2=(K2*L)*(K2*L

[0155] C3 = C2 / 2 (8)

[0156] The default values ​​are K1 = 0.01, K2 = 0.03, and L = 255.

[0157]

[0158]

[0159]

[0160] The product of the three functions, C3 = C2 / 2, and after simplification, we get the SSIM function, SSIM(x, y), as shown in equation (12).

[0161]

[0162] Analyzing the SSIM calculation process, let the original list of sub-pixels of the input image be P1 = {x1, x2, ... x...} n}, the sampling point set P2 = {y1, y2...y} m}, where P1 is the source pixel in the grayscale image, and each pixel x i The value of y is between [0, 255], and the P2 sequence represents the selected and retained source pixel art points. Assuming the pixel art is constructed against a white background, the value of y for each point is... i The initial values ​​are all 255. The three-dimensional surface plot constructed according to formula (12) shows that... Figure 8 As shown, when μ x =μ y When the pixel counts of two images are nearly equal, l(x, y) will take the highest value of 1, meaning the higher the value, the closer the pixel counts of the two images are to being equal. σ in c(x, y) x , σ y It also has the same properties.

[0163] The process of establishing the SSIM optimization index model is as follows:

[0164] Let P be the set of points in the sub-cluster, and p be the set of points in the sub-cluster. i Let P be any point in P, where P = {p1, p2, ..., p...}N}; N represents the number of points in the set, and each point p i There are 3 attributes (coordinate_x) i coordinate_y i c i ), representing point p respectively. i x-axis, y-axis, color number, where c i The range of variation is (0-255), coordinate_x i The range of variation is w min ~w max w min ~w max The coordinate_y represents the minimum and maximum values ​​of the x-coordinate. i The range of variation is w min ~w max h min ~h max Let be the minimum and maximum values ​​of the ordinate. The distance matrix Dis_Matrix between points within each sub-cluster is constructed using formula (*). Point p i and point p j The distance between them is calculated as follows:

[0165]

[0166] Set a large integer M = 999 for use in formula (18) to find the minimum distance between point pairs.

[0167] Decision variables:

[0168] x i : A 0-1 variable, indicating that the i-th point is selected and retains its original color, then x i =1, otherwise x is not selected. i =0.

[0169] Indicator variable: y ij u ij w ij , z

[0170] Objective: Minimize the color difference between the selected and unselected points and the original image. Since the selected points match the original image color, their pixel difference is 0. The unselected points have a white background, and the grayscale value of white pixels is 255.

[0171]

[0172] Constraint 1: The total number of selected points must be less than 0.7 of the total number of points (this limit can be modified according to requirements).

[0173]

[0174] Constraint 2: Set indicator variable y ij constraint. Yi j This represents the distance between all pairs of points in the sub-clusters. If point p... i p j One of them was not selected (i.e., x) i and x j If at least one of them is 0, then y ij A value of 0 indicates that both points are selected (i.e., x). i and x j If both are 1), then y ij The distance between the two points is the Euclidean distance.

[0175]

[0176] Constraint 3: Set indicator variable w ij Constraints. Together with constraint 4, w ij A value of 1 indicates all variables y ij Points greater than 0.02 (i.e., p) i p j (Points that are all selected). ij A value of 0 indicates all variables y ij Points greater than 0.02 (i.e., p) i p j At least one point was not selected.

[0177] w ij =1 if y ij ≥0.02 (16)

[0178] Constraint 4: Set indicator variable w ij Constraints. Used in conjunction with constraint 3.

[0179] w ij =0 if y ij <0.02 (17)

[0180] Constraint 5: Set indicator variable u ij Constraints. ij p represents the new distance between all pairs of points, which differs from the original Euclidean distance. i p j When there are unselected points, u ij The distance is very large, and when both points are selected, the distance is the normal Euclidean distance. This masks all unselected point pairs.

[0181] u ij =y ij +(1-w ij )*M (18)

[0182] Constraint 6: Set the indicator variable z constraint, where z is the distance u between the selected point and the specified point. ij The minimum value of the sequence.

[0183] z = min(u ij (19)

[0184] Constraint 7: Set indicator variable u ij The upper limit constraint is that the maximum distance between all selected point pairs must be less than twice the color radius.

[0185]

[0186] Constraint 8: Set indicator variable u ij Lower bound constraint: The minimum distance between all selected point pairs must be greater than the color radius.

[0187]

[0188] The effectiveness of this invention can be illustrated by the following comparative experiments:

[0189] 1. Experimental conditions: The experiment was implemented using Python 3.8 and tested on an i7 2.40GHz CPU, 8.0GB of memory, and Windows 10 platform.

[0190] 2. The experimental content and results are as follows:

[0191] This invention compares the pixel quality with three existing algorithms: the mainstream structure-aware algorithm, the IVS-based radius adjustment algorithm, and the digital color halftone algorithm. It uses structural similarity (SSIM) and peak signal-to-noise ratio (PSNR) to score the pixel quality. All test comparison images used are from the corresponding literature.

[0192] Experimental results are as follows Figure 2-4 As shown, Figure 2 Table 1 shows the comparison results between the algorithm in this paper and the structure-aware algorithm based on test images a and b. Figure 3 Table 2 shows the comparison results between the algorithm in this paper and the IVS-based radius adjustment algorithm on test images c, d, and e. Figure 4Table 3 shows the comparison results between the proposed algorithm and the digital color halftone algorithm on test images f, g, and h. All images were drawn from points with the same radius. From the numerical errors SSIM and PSNR, it can be seen that the proposed algorithm generates higher quality dots, and the algorithm is faster on average, achieving real-time drawing. The final dot quality is also superior to other methods in both visual effect and numerical score.

[0193] Table 1 Comparison results between the algorithm presented in this paper and the structure-aware algorithm.

[0194]

[0195] Table 2 Comparison results between the algorithm presented in this paper and the IVS-based radius adjustment algorithm

[0196]

[0197] Table 3 Comparison results between the algorithm presented in this paper and the digital color halftone algorithm.

[0198]

[0199] In summary, experiments demonstrate that, under the same conditions, the method of this invention achieves better results in generating artistic dot paintings. It not only uses fewer pixels, reducing costs, but also produces high-quality dot painting effects.

[0200] Optimize the selection of experimental sites: Figure 5 Taking lenna.png as an example, taking superpixel number 101, the optimized point selection result is: the original lenna.png image has 256*256=65636 points, while this method has 33295 points, which is a reduction of 49% of the pixels.

[0201] Linear programming optimization point selection experiment: First, a uniform sample image with 1007 points was randomly generated using the Bridson sampling method. The image width was 1.0, the height was 1.0, and the interval between points was 0.025. A new point interval radius of 0.05 was selected. After applying the linear programming optimization point selection method, 223 sampling points were obtained. Figure 6 As can be seen, while increasing the distance between points, the uniformity of each point is maintained.

[0202] Compared to existing technologies, the steps of this invention are greatly simplified, and the dot generation algorithm proposed in this invention is superior to existing methods in terms of visual effects and SSIM and PSNR scores.

[0203] It should be understood that any parts not described in detail in this specification belong to the prior art.

[0204] It should be understood that the above description of the preferred embodiments is quite detailed, but it should not be considered as a limitation on the scope of protection of this invention. Those skilled in the art, under the guidance of this invention, can make substitutions or modifications without departing from the scope of protection of the claims of this invention, and all such substitutions or modifications fall within the scope of protection of this invention. The scope of protection of this invention should be determined by the appended claims.

Claims

1. A pointillism generation method based on adaptive clustering and linear programming optimization point selection, characterized in that, Includes the following steps: Step 1: The SLIC superpixel algorithm is used to perform preliminary segmentation of the image, dividing the input image into a series of superpixel blocks with clear boundaries and compact space. In subsequent processing, superpixel blocks are used instead of pixels as the basic unit for operation. Step 2: The superpixel blocks are further adaptively divided into appropriate sub-clusters using a color density peak-based adaptive clustering algorithm and the triangle elbow method. The specific implementation of the color density peak-based adaptive clustering algorithm in step 2 is as follows; Step 2.1: First, preprocessing is performed to obtain the density decision map; Step 2.2: Then, perform pre-clustering. Sort the points in the decision graph in ascending order of their density, calculate the maximum density difference and the average density difference, and remove the data points to the left of the point with the maximum density change in the decision graph as noise points. Select points with a density greater than the average value and a diffusion distance greater than the average value as the initial cluster centers. The average value is obtained by averaging the density values ​​of all data points after removing noise points. The list of cluster center points is denoted as... That is, the initial clustering has indivual; Step 2.3: Finally, merge clusters based on the point-to-point distances of the initial cluster centers; The specific implementation method for obtaining the density decision map in step 2.1 is as follows; 2.2.1, Let each set of superpixels be denoted as . The points inside the set are composed of triples. , They represent different point numbers. Different colors represent that point. These represent the x-coordinate and y-coordinate of the point, respectively. Define the calculation of the color distance between any two points i and j. It is composed of the exponent of the Euclidean distance and the color difference; (1) 2.1.2, Local point density is defined based on the Gaussian kernel function. : Set the cutoff distance as , The calculation formula is: (3) 2.1.3 Calculate the diffusion distance at any point For the data points with the highest density diffusion distance It is the maximum value of all distances between pixel pairs; for any other pixel, the diffusion distance is... It is the minimum value of all distances from it to all pixels with a density greater than its own, therefore the pixel... The diffusion distance can be calculated in the following two cases: (4) 2.1.4, with density The x-axis represents the diffusion distance. Draw a decision diagram with the vertical axis as the ordinate; Step 3: Select the most suitable point in the sub-cluster using a target optimization model based on SSIM values; Step 4: Assign the original color to all selected points, and change the background color to the remaining points to form a new colored dotted image.

2. The point drawing generation method based on adaptive clustering and linear programming for optimal point selection as described in claim 1, characterized in that: the specific implementation of step 2.3 is as follows; 2.3.1, Suppose that the initial clusters obtained from the pre-clustering are: There are 1, and the categories are as follows: The number of categories, initially set to... Point-to-point distance from the initial distance center Then sort them in ascending order; let the existence duration sequence corresponding to the initial classification method be... The initial values ​​are all 0, and the maximum duration is set. ; 2.3.2, when At that time, perform the following operations in a loop: Search sequentially for the two nearest cluster centers in the initial cluster center queue. , set as , The categories corresponding to the two points They belong to different categories and Skip cluster pairs whose cluster center distance is -1, and the initial distance between clusters is not -1; like ,but and And set the category attribute of all points in these two classes to the new category, with the category number as [category number]. And add the new category number to the category number table. From This indicates that the two categories have been merged into a new cluster, and the category number is... Increase by 1, while the current total number of clusters The total number of categories is reduced by 1, and the distance between the two nearest cluster centers is set to -1. If they are in the same category, If k remains unchanged; Increment the duration of the classification method corresponding to this number of categories by 1. ; If the current ,but ,use Record the sequence of cluster centers containing the new category labels. Record the new classification of the cluster center point when the maximum existence duration is reached; until The time loop ends; 2.3.3, based on 2.3.2 The final stored cluster center table contains the category results. The display shows the number of clusters calculated, and the final result is taken as the optimal number of clusters. Multiple centroids belonging to the same cluster after merging can be selected as any one of them as the centroid.

3. The point generation method based on adaptive clustering and linear programming for optimal point selection as described in claim 1, characterized in that: In step 2, the triangle elbow method is an optimal K value selection algorithm based on the sum of squared clustering errors (SSE) and K-means clustering, used to obtain the optimal number of clusters for a set of data points.

4. The point drawing generation method based on adaptive clustering and linear programming for optimal point selection as described in claim 1, characterized in that: The specific implementation of the triangular elbow method in step 2 is as follows; Step 2a, set the maximum number of cluster attempts sequentially. The initial clusters are divided using preset parameters for K-means clustering, and the result of each division is... ; Step 2b, calculate the sum of squared clustering errors. ; (5) In formula (5), It is the first One cluster, yes The pixels in yes The cluster centers are determined, and SSE is the clustering error of all samples. The values ​​of SSE are calculated and a list of values ​​is generated. ; Step 2c, list the values Normalized, SSE values ​​correspond to the ordinate, subscript Corresponding to the horizontal axis, the lines are connected to form a line graph; Step 2d: Starting from the first point, connect every three adjacent points to form a triangle. These represent the lengths of the three sides of the triangle, and the cosine values ​​between each elbow point are calculated using formula (6). (6) in, It is the included angle between the points that are the middle of three adjacent points; Step 2e: Calculate the angles corresponding to the inverse cosine values ​​based on the cosine value sequence. ; Step 2f, calculate id= The index of the minimum included angle between the elbows is the potential optimal cluster number.

5. The point generation method based on adaptive clustering and linear programming for optimal point selection as described in claim 1, characterized in that: The SSIM value is calculated in step 3 as follows; Given two images x and y, SSIM compares the similarity of images x and y in three aspects: brightness, light intensity, and color intensity. Contrast and structure Brightness is estimated using the mean, contrast using the standard deviation, and structural similarity using the covariance. The final similarity between x and y is the product of these three factors. and , and Let x and y be the mean and standard deviation, respectively. Let x be the covariance of y; C1, C2, and C3 are positive constants used to prevent division by zero in the formula. The default values ​​are K1 = 0.01, K2 = 0.03, and L = 255. The product of these three functions is the SSIM function. .

6. The point generation method based on adaptive clustering and linear programming for optimal point selection as described in claim 1, characterized in that: The specific implementation method of step 3 is as follows; Let P be the set of points in the sub-cluster. Let P be any point, ; This represents the number of points in the set, and each point... There are 3 attributes , respectively representing points The x-axis, y-axis, and color number, where The range of variation is 0-255. The range of variation is , The x-axis represents the minimum and maximum values. The range of variation is , The ordinate represents the minimum and maximum values; Calculate the distance matrix Dis_Matrix between points within each sub-cluster; Point and points The distance between them; Set the decision variable as , A variable that is 0 or 1 represents the first... If a point is selected and its original color is retained, then... Otherwise, it was not selected. ; Set the indicator variable as follows: , , , The final objective function is to minimize the color difference between the selected and unselected points and the original image, that is: Among them, the selected points have the same color as the original image and the pixel difference with the original image is 0, while the unselected points have a white background and the gray value of the white pixels is 255. The objective function described above satisfies the following constraints: Constraint 1: The total number of selected points must be less than γ times the total number of points; Constraint 2, setting indicator variables constraint, The distance between all pairs of points in the sub-clusters, if the point One of them was not selected, that is If at least one is 0, then A value of 0 indicates that both points are selected. If both are 1, then The Euclidean distance between two points; Constraint 3, setting indicator variables constraint, A value of 1 indicates all variables. Points greater than or equal to ε, i.e. All selected points A value of 0 indicates all variables. Points less than ε, i.e. At least one item was not selected; Constraint 4, setting indicator variables constraint; Where ε is a set constant; Constraint 5, setting indicator variables constraint, The new distance between all pairs of points differs from the original Euclidean distance. When there are unselected points, Very large, and when both points are selected. This is the normal Euclidean distance, which masks all unselected point pairs; M is an integer that is set; Constraint 6, setting indicator variables constraint, Distance to the selected point The minimum value of the sequence; Constraint 7, setting indicator variables Upper limit constraint: the maximum distance between all selected point pairs must be less than or equal to twice the color radius; Constraint 8, setting indicator variables The lower bound constraint requires that the minimum distance between all selected point pairs must be greater than or equal to the color radius. 。 7. The point generation method based on adaptive clustering and linear programming for optimal point selection as described in claim 6, characterized in that: Color radius The calculation formula is as follows; in, That is, the color radius The parameter color represents the color mean of the sub-clusters.

Citation Information

Patent Citations

  • Dot picture generation method and device based on superpixel and color knapsack algorithm

    CN115619884A