Image processing methods, apparatus, computer equipment and storage media
By segmenting and clustering the target density map of the image, the image localization process is simplified, and the localization efficiency and accuracy are improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-25
- Publication Date
- 2026-03-10
AI Technical Summary
Existing image-based localization technologies are complex and difficult to locate target objects in images conveniently.
By acquiring the target density map of the image, segmentation is performed to obtain density map patches, and the target objects within each patch are clustered to determine the location data of the target objects.
It simplifies the image processing process, improves positioning efficiency and accuracy, and reduces computational load and complexity.
Smart Images

Figure CN115205389B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to an image processing method, an image processing apparatus, a computer device, and a computer-readable storage medium. Background Technology
[0002] With the continuous development of computer technology, positioning technology is becoming increasingly common in daily life. For example, positioning technology is used to identify target objects in images; it is also used to identify target vehicles in traffic flow, and so on.
[0003] Currently, the commonly used localization method is based on the image itself, employing localization algorithms to locate target objects within the image. This method is relatively complex, requiring various image processing steps to pinpoint the target object's location, making it quite challenging. Therefore, how to conveniently locate target objects within images has become a pressing technical problem that needs to be solved. Summary of the Invention
[0004] This application provides an image processing method, apparatus, computer device, and storage medium that can perform location recognition based on the density map of the image to be processed, thereby improving the efficiency of image processing.
[0005] On one hand, embodiments of this application provide an image processing method, the method comprising:
[0006] Obtain the target density map of the target objects contained in the image to be processed;
[0007] The target density map is segmented to obtain multiple density map patches;
[0008] Clustering is performed on each target object within each density patch to obtain the clustering result for each density patch;
[0009] Based on the clustering results of each density patch, the location data of the target objects contained in the image to be processed are determined.
[0010] On one hand, embodiments of this application provide an image processing apparatus, which includes:
[0011] The acquisition unit is used to acquire the target density map of the target object contained in the image to be processed.
[0012] The processing unit is used to segment the target density map to obtain multiple density map patches;
[0013] The processing unit is also used to perform clustering processing on each target object within each density patch to obtain the clustering result of each density patch;
[0014] The processing unit is also used to determine the location data of the target objects contained in the image to be processed based on the clustering results of each density patch.
[0015] In one possible implementation, the processing unit performs clustering processing on each target object within each density patch to obtain the clustering result for each density patch, which is then used to perform the following operations:
[0016] Obtain the density value of each pixel in the target density patch, where the target density patch is any one of multiple density patches;
[0017] The number of clusters in the target density patch is determined based on the density value of each pixel in the target density patch.
[0018] Based on the number of clusters in the target density patch, clustering is performed on each target object within the target density patch to obtain the clustering result of the target density patch.
[0019] In one possible implementation, the processing unit clusters each target object within the target density patch based on the number of clusters in the target density patch, obtaining the clustering result of the target density patch, which is then used to perform the following operations:
[0020] Based on the number of clusters in the target density patch, N initial cluster points are determined from the target density patch, where N is a positive integer and equal to the number of clusters in the target density patch;
[0021] Based on N initial cluster points, clustering is performed on each target object within the target density patch to obtain the clustering result of the target density patch.
[0022] In one possible implementation, the processing unit determines N initial cluster points from the target density patch based on the number of clusters in the target density patch, and performs the following operations:
[0023] Multiple local maxima are obtained from the target density patch. A local maximum is a pixel that corresponds to the largest density value within a preset range.
[0024] Based on the number of clusters in the target density patch, N initial cluster points are determined from the multiple local maxima obtained.
[0025] In one possible implementation, the number of multiple local maxima is denoted by K; K is a positive integer; the processing unit performs the following operations based on the number of clusters in the target density patch:
[0026] If N > K, then obtain NK pixels from the target density patch and combine the obtained NK pixels and K local maxima into N initial cluster points;
[0027] If N≤K, then select N local maxima from the K local maxima and use the selected N local maxima as N initial cluster points.
[0028] In one possible implementation, the processing unit performs clustering processing on each target object within the target density patch based on N initial clustering points to obtain the clustering result of the target density patch, which is then used to perform the following operations:
[0029] Obtain the distances from each target pixel within the target density patch to the N initial cluster points, and assign each target pixel to the cluster set containing the nearest initial cluster point. A target pixel can be any pixel within the target density patch.
[0030] Based on the target cluster set corresponding to the target initial cluster point, the position of the target initial cluster point is updated to obtain the target updated cluster point. The target initial cluster point is any one of the N initial cluster points.
[0031] Based on the N updated clustering points obtained after the update, clustering is performed on each target object within the target density map block to obtain the clustering result of the target density map.
[0032] In one possible implementation, the processing unit updates the position of the target initial cluster point based on the target cluster set corresponding to the target initial cluster point, obtaining the target updated cluster point, which is then used to perform the following operations:
[0033] Obtain the density value of each pixel within the target cluster set;
[0034] Based on the position coordinates of each pixel in the target cluster set and the density value of each pixel, the position of the target initial cluster point is updated by weighted averaging, resulting in the updated target initial cluster point.
[0035] On one hand, embodiments of this application provide a computer device, which includes a memory and a processor. The memory stores one or more computer programs, and when the computer programs are executed by the processor, the processor performs the image processing method described above.
[0036] On one hand, embodiments of this application provide a computer-readable storage medium storing a computer program, which, when read and executed by a processor of a computer device, causes the computer device to perform the aforementioned image processing method.
[0037] On one hand, embodiments of this application provide a computer program product or computer program, which includes a computer program stored in a computer-readable storage medium. A processor of a computer device reads the computer program from the computer-readable storage medium and executes the computer program, causing the computer device to perform the image processing method described above.
[0038] In this embodiment, firstly, a target density map of the target objects contained in the image to be processed can be obtained; then, the target density map can be segmented to obtain multiple density map patches; next, each target object within each density map patch can be clustered to obtain the clustering result of each density map patch; finally, based on the clustering result of each density map patch, the location data of the target objects contained in the image to be processed can be determined. Therefore, this application can determine the location data of target objects by performing clustering based on density maps. This density map-based clustering method is relatively simple and can improve the efficiency of image processing. Furthermore, pre-segmenting the density map into multiple density map patches can reduce the computational load and complexity during subsequent clustering, further improving the efficiency and accuracy of image processing. Attached Figure Description
[0039] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0040] Figure 1 This is a schematic diagram of the architecture of an image processing system provided in an embodiment of this application;
[0041] Figure 2 This is a schematic flowchart of an image processing method provided in an embodiment of this application;
[0042] Figure 3 This is a schematic diagram of a process for determining a target density map provided in an embodiment of this application;
[0043] Figure 4 This is a schematic diagram of a threshold segmentation scenario provided in an embodiment of this application;
[0044] Figure 5 This is a schematic diagram of a clustering process scenario provided in an embodiment of this application;
[0045] Figure 6 This is a schematic diagram of the structure of an image processing device provided in an embodiment of this application;
[0046] Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. Detailed Implementation
[0047] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0048] This application proposes an image processing scheme that can be used to identify the location of target objects (such as pigs, dogs, cats, etc.) in an image and improve the accuracy of image processing. The general principle of this scheme is as follows: First, a target density map of the target objects contained in the image to be processed can be obtained; then, the target density map can be segmented to obtain multiple density patches; next, each target object within each density patch can be clustered to obtain the clustering result for each density patch; finally, based on the clustering result of each density patch, the location data of the target objects contained in the image to be processed can be determined.
[0049] Therefore, this application demonstrates that clustering based on density maps can determine the location data of target objects. This density map-based clustering method is relatively simple and can improve the efficiency of image processing. Furthermore, pre-segmenting the density map into multiple density map patches can reduce the computational load and complexity during subsequent clustering, further improving image processing efficiency and accuracy.
[0050] Next, the image processing scheme mentioned above will be described using the technical terminology used in this application:
[0051] I. Cloud Technology:
[0052] Cloud computing is a computing model that distributes computing tasks across a large pool of computers, enabling various application systems to access computing power, storage space, and information services as needed. The network providing these resources is called the "cloud." From the user's perspective, resources in the "cloud" appear infinitely scalable, readily available, on-demand, and expandable, with payment based on usage.
[0053] In one possible implementation, when executing the image processing scheme of this application, clustering is performed on each target object within each density patch to obtain the clustering result of each density patch. This process involves large-scale computation and requires a large amount of computing power and storage space. Therefore, computer equipment can obtain sufficient computing power and storage space through cloud computing technology to execute the specific process of determining the location data of the target objects contained in the image to be processed involved in this application.
[0054] II. Blockchain:
[0055] Blockchain is a novel application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanisms, and cryptographic algorithms. Essentially, a blockchain is a decentralized database, a chain of data blocks linked together using cryptographic methods. Each data block contains information about a batch of network transactions, used to verify the validity of the information (anti-counterfeiting) and generate the next block. A blockchain can include an underlying platform, a platform product and service layer, and an application service layer.
[0056] The image processing solution of this application can be combined with blockchain technology. For example, data such as target density maps, clustering results, and target object location data can be uploaded to the blockchain for storage, which can ensure that the data on the blockchain is not easily tampered with, thereby ensuring the security of the image processing process.
[0057] It should be noted that in the subsequent specific embodiments of this application, data related to object information (such as identifiers, names, etc.) are involved. When the above embodiments of this application are applied to specific products or technologies, permission or consent from the object is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0058] Please see Figure 1 , Figure 1 This is a schematic diagram of the architecture of an image processing system provided in an embodiment of this application. The architecture of the image processing system includes a server 140 and a cluster of terminal devices, wherein the cluster of terminal devices may include terminal devices 110, 120, 130, etc. The cluster of terminal devices and the server 140 can be directly or indirectly connected via wired or wireless communication, which is not limited herein.
[0059] Figure 1The server 140 shown can be a standalone physical server, a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0060] Figure 1 The terminal devices 110, 120, and 130 shown can be mobile phones, tablets, laptops, PDAs, mobile internet devices (MIDs), vehicles, in-vehicle devices, roadside devices, aircraft, wearable devices such as smartwatches, smart bracelets, pedometers, and other smart devices with image processing capabilities.
[0061] In one possible implementation, taking the joint execution of the aforementioned image processing scheme by terminal device 110 and server 140 as an example, the specific operations performed by terminal device 110 and server 140 are explained below. Terminal device 110 can obtain a target density map of the target objects contained in the image to be processed. Then, terminal device 110 can send the target density map to server 140. Server 140 performs segmentation processing on the target density map to obtain multiple density map patches. Then, server 140 performs clustering processing on each target object within each density map patch to obtain the clustering result of each density map patch. Finally, based on the clustering result of each density map patch, server 140 determines the location data of the target objects contained in the image to be processed. Subsequently, server 140 can send the location data of the target objects contained in the image to be processed back to terminal device 110.
[0062] It should be understood that the above description is merely an illustrative illustration of the specific operations performed by terminal device 110 and server 140. In another possible implementation, determining the location data of the target object contained in the image to be processed based on the clustering results of each density patch does not necessarily have to be performed by server 140; it can also be performed by terminal device 110. In yet another possible implementation, the image processing scheme mentioned above can be performed by server 140 in the image processing system or by any terminal device (e.g., terminal device 110) in the terminal device cluster, and this application embodiment does not specifically limit this.
[0063] In one possible implementation, the image processing system provided in this application embodiment can be deployed on a blockchain. For example, the server 140 and each terminal device (terminal device 110, terminal device 120, terminal device 130, etc.) included in the terminal device cluster can be treated as a node device of the blockchain, jointly forming a blockchain network. Therefore, the image processing process in this application can be executed on the blockchain, which can ensure the fairness and impartiality of the image processing process, and at the same time make the image processing process traceable, thereby improving the security of the image processing process.
[0064] It is understood that the system architecture diagrams described in the embodiments of this application are for the purpose of more clearly illustrating the technical solutions of the embodiments of this application, and do not constitute a limitation on the technical solutions provided in the embodiments of this application. As those skilled in the art will know, with the evolution of system architecture and the emergence of new business scenarios, the technical solutions provided in the embodiments of this application are also applicable to similar technical problems.
[0065] Based on the above analysis, the following will combine... Figure 2 The image processing method of this application is described below. Please refer to [link / reference]. Figure 2 , Figure 2 This is a schematic flowchart illustrating an image processing method provided in an embodiment of this application. This image processing method can be executed by the computer device mentioned above, which can be a terminal device or a server. See also... Figure 2 As shown, the image processing method may include steps S201 to S204:
[0066] S201: Obtain the target density map of the target objects contained in the image to be processed.
[0067] In specific implementation, the image to be processed may include at least one target object. It should be understood that the number of target objects included in the image to be processed mentioned in the embodiments of this application is relatively large, so the corresponding target density map can be obtained based on the image to be processed with a large number of target objects.
[0068] The type of the target object may include, but is not limited to, animals, people, flowers, grass, etc. This application does not specifically limit the type of the target object. For ease of explanation, subsequent embodiments of this application will use an animal type as an example for illustration. Specifically, an animal type target object may include, for example, a cat, dog, pig, rabbit, etc.
[0069] In one possible implementation, the process by which a computer device acquires the target density map of a target object contained in an image to be processed may specifically include: calling an object recognition model to perform density estimation processing on the target objects contained in the image to be processed, thereby obtaining the target density map corresponding to the image to be processed. Here, the object recognition model is obtained by training a neural network model based on sample images and their corresponding reference density maps, where the reference density map is obtained by labeling the target objects contained in the sample images.
[0070] The object recognition model can be a neural network model, which may include, but is not limited to, Convolutional Neural Networks (CNN) models, Deep Neural Networks (DNN) models, and other network models with density estimation processing. This application does not impose specific limitations on the model structure of the object recognition model.
[0071] For example, to comprehensively consider existing reference density map regression networks and their advantages, and to improve and integrate them, please refer to [link to relevant documentation]. Figure 3 , Figure 3 This is a schematic flowchart illustrating the process of determining a target density map, as provided in an embodiment of this application. Figure 3 As shown, the object recognition model in this application uses a multi-branch network structure based on selective kernel convolution (SK conv) to achieve adaptive adjustment of the convolution kernel size, such as SK_1, SK_2, SK_3, etc. Simultaneously, this application also employs upsampling and stacking of deep features to achieve multi-layer feature fusion, thereby obtaining high-level features. That is, the features output by the SK_2 module are concatenated with the features output by the upsampled SK_3 module to obtain high-level features, which can then be used as input to subsequent network modules (such as the bottleneck module mentioned later). Furthermore, the network design employs commonly used bottleneck (hourglass structure: 3×3conv9, 3×3conv10, 1×1conv11, 1×1conv12) and residual block structures, thereby improving the expressive power of network features while reducing network parameters.
[0072] In one possible implementation, a computer device can obtain an object recognition model by training a neural network model. Specifically, the computer device can train the neural network model based on a reference density map and a predicted density map to obtain the object recognition model. The predicted density map is obtained by calling the neural network model to perform density estimation on the sample image, while the reference density map is obtained by labeling the target objects contained in the sample image.
[0073] Next, the specific process of obtaining the object recognition model will be explained in detail:
[0074] Specifically, the process of training an object recognition model can include: determining the network loss of the neural network model based on the difference data between the reference density map and the predicted density map; iteratively adjusting the neural network model based on the network loss; and if the adjusted neural network model meets the model convergence condition, then the adjusted neural network model is used as the object recognition model. The model convergence condition can be: when the number of training iterations of the neural network model reaches a preset training threshold, such as 100 times, then the neural network model meets the model convergence condition; or, when the error between the predicted density map corresponding to each sample image and the reference density map corresponding to each sample image is less than an error threshold, then the neural network model meets the model convergence condition; or, when the change between the reference density maps corresponding to each sample image obtained from two consecutive training iterations of the neural network model is less than a change threshold, then the neural network model meets the model convergence condition.
[0075] Specifically, the computer device determines the network loss of the neural network model based on the difference data between the reference density map and the predicted density map. This can include: obtaining pixel scale loss based on the pixel value difference between each pixel in the reference density map and each pixel in the predicted density map; obtaining count scale loss based on the difference in the number of target objects between the reference density map and the predicted density map; and determining the network loss of the neural network model based on the pixel scale loss and the count scale loss.
[0076] For example, the expression for calculating network loss is shown in Formula 1.1-1.3 below:
[0077]
[0078]
[0079] loss = l pixel +λl count (1.3)
[0080] Among them, l pixelPixel scale loss is used to characterize the difference between two images (reference density map and predicted density map) at each pixel location; count The counting scale loss is used to characterize the difference in counts between two images (reference density map and predicted density map). D(x,y) and These represent the density values of each pixel in the predicted density map and the reference density map, respectively; mean indicates the average value. Furthermore, the weighting coefficients for pixel scale loss and count scale loss can be customized, and this embodiment does not impose specific limitations on them.
[0081] It is understood that, in calculating the network loss in this embodiment, since both pixel-scale loss (pixel-scale loss) and global-scale counting loss (counting-scale loss) are considered simultaneously, and the location and number of target objects (e.g., pigs) are constrained by the network loss, it can ensure that the neural network model obtains a smaller counting error under the premise that the predicted density map is close to the reference density map, thereby improving the accuracy of the object recognition model obtained after training. Subsequently, based on a more accurate object recognition model, the number of target objects in the image can be identified more accurately.
[0082] S202: Segment the target density map to obtain multiple density map blocks.
[0083] In one possible implementation, the computer device segments the target density map to obtain multiple density patches. Specifically, this can include thresholding the target density map to obtain multiple density patches. Thresholding is a segmentation technique based on image regions. Its principle is to divide image pixels into several classes. For example, thresholding can include, but is not limited to, Otsu's method (or maximum inter-class variance method) thresholding, adaptive thresholding, maximum entropy thresholding, iterative thresholding, etc.
[0084] In this embodiment, based on threshold segmentation technology, pixels in the target density map can be divided into multiple unconnected density patches. It is understood that the area of each density patch can be the same or different. For example, the target density map can be divided into four equal parts according to its area, resulting in four density patches of equal area; alternatively, the target density patches can be randomly divided, resulting in multiple density patches of different sizes, and so on. This application does not specifically limit the segmentation method of the density patches. For example, please refer to... Figure 4 , Figure 4 This is a schematic diagram of a threshold segmentation scenario provided in an embodiment of this application. For example... Figure 4As shown, the target density map S40 can be divided into three unconnected density patches, such as S01, S02, and S03. The density patches S01, S02, and S03 are all of different sizes.
[0085] By using a threshold segmentation method, multiple density patches are obtained. Subsequent processing is performed on each density patch as a unit, which can reduce the complexity of clustering and thus improve the efficiency of image processing.
[0086] S203: Perform clustering processing on each target object within each density patch to obtain the clustering result for each density patch.
[0087] In this embodiment, each density patch contains at least one target object. The computer device can perform clustering processing on the target objects within each density patch based on a clustering algorithm to obtain the clustering result for each density patch. For example, the clustering algorithm may include, but is not limited to: K-Means clustering algorithm, mean-shift clustering algorithm, DBSCAN clustering algorithm (Density-Based Spatial Clustering of Applications with Noise, a density-based clustering algorithm), and hierarchical clustering algorithm. For ease of explanation, this embodiment uses the K-Means clustering algorithm as an example for description.
[0088] Next, taking any one of the multiple density patches (referred to as the target density patch) as an example, the process of clustering it and obtaining the clustering result of the target density patch is as follows:
[0089] (1) First, the computer device performs clustering processing on each target object in each density patch to obtain the clustering result of each density patch. Specifically, it may include: obtaining the density value of each pixel in the target density patch, where the target density patch is any one of multiple density patches; determining the number of clusters in the target density patch based on the density value of each pixel in the target density patch; and performing clustering processing on each target object in the target density patch according to the number of clusters in the target density patch to obtain the clustering result of the target density patch.
[0090] Specifically, the process by which a computer device determines the number of clusters in a target density patch based on the density values of each pixel in the target density patch may include: summing the density values of each pixel in the target density patch to obtain a summation result, and using the summation result as the number of clusters N in the target density patch. The determination of the number of clusters N is shown in the following formula (2):
[0091]
[0092] Among them, in the above formula (2) This refers to the density value of any pixel in the target density patch. The sum of the density values of all pixels is then used as the number of clusters N, which is the initial number of cluster points N. It should be understood that the sum of the density values of pixels within each polygonal object (e.g., an ellipse) in the target density patch is 1. Therefore, the sum of the density values of all pixels in the target density patch can be roughly considered as the number of ellipses, and the number of ellipses can be considered as the number of target objects N. Since this embodiment requires subsequent clustering processing to determine the location of the target objects (i.e., locating the target objects) based on the clustering results, and each target object corresponds to one cluster center point, the number N of target objects calculated for the target density patch can be used as the number of cluster center points N.
[0093] (2) Secondly, the computer device performs clustering processing on each target object in the target density patch according to the number of clusters in the target density patch to obtain the clustering result of the target density patch. Specifically, it may include: first, determining N initial clustering points from the target density patch according to the number of clusters in the target density patch, where N is a positive integer and equal to the number of clusters in the target density patch; then, performing clustering processing on each target object in the target density patch according to the N initial clustering points to obtain the clustering result of the target density patch.
[0094] In one possible implementation, the computer device determines N initial cluster points from the target density patch based on the number of clusters in the target density patch. This may include: obtaining multiple local maxima from the target density patch, where a local maxima is a pixel corresponding to the largest density value within a preset range; and determining N initial cluster points from the multiple local maxima obtained based on the number of clusters in the target density patch.
[0095] Specifically, the number of local maxima is denoted by K, where K is a positive integer. The computer device determines N initial cluster points from the acquired local maxima based on the number of clusters in the target density patch. This can include: if N > K, acquiring NK pixels from the target density patch and combining these NK pixels with the K local maxima to form N initial cluster points; if N ≤ K, selecting N local maxima from the K local maxima and using these N selected local maxima as the N initial cluster points. The selection of N local maxima from the K local maxima can be random or based on a preset rule. For example, the preset rule may include, but is not limited to, selecting according to the pixel density values from largest to smallest.
[0096] In this way, clustering algorithms are used to segment the distribution area of target objects and provide more reliable initial cluster points to ensure the accuracy of clustering. Specifically, N initial cluster points (i.e., the number of target objects in the target density patch) are determined from pixels with higher density values. This makes the clustering process more biased towards locations with higher density values, thereby ensuring higher accuracy in clustering locations.
[0097] (3) Then, the computer device performs clustering processing on each target object within the target density map based on the N initial clustering points to obtain the clustering result of the target density map. This may include: First, obtaining the distances from each target pixel within the target density map to the N initial clustering points, and assigning each target pixel to the cluster set containing the nearest initial clustering point. Each target pixel is any pixel within the target density map. Then, based on the target cluster set corresponding to the target initial clustering point, updating the position of the target initial clustering point to obtain the target updated clustering point. Each target initial clustering point is any one of the N initial clustering points. Finally, based on the updated N clustering points, performing clustering processing on each target object within the target density map to obtain the clustering result of the target density map.
[0098] For example, suppose the target density patch contains m pixels, and these m pixels are represented as: X1, X2, X3, ..., X... m Taking the target pixel as X1 as an example, a clustering algorithm can be used to calculate N initial cluster points (Y1, Y2, Y3, ..., Y...). m The distances, for example, are represented as: L1, L2, L3, ..., L m Finally, from L1, L2, L3, ..., L m Once the minimum value (let's assume it's L1) is determined, the target pixel X1 is assigned to the cluster set where the initial cluster point Y1 is located. Following the above method, each pixel in the target density patch can be assigned to the corresponding cluster set of the initial cluster point, thus determining the cluster set of each initial cluster point.
[0099] (4) Further, the computer device updates the position of the target initial cluster point based on the target cluster set corresponding to the target initial cluster point to obtain the target updated cluster point, which may include: first, obtaining the density value of each pixel in the target cluster set; then, according to the position coordinates of each pixel in the target cluster set and the density value of each pixel, updating the position of the target initial cluster point by weighted average to obtain the updated target initial cluster point.
[0100] For example, computer devices can update the position of each cluster center. To ensure that the cluster center positions are biased towards high-density values, a weighted average method can be used to update the cluster centers. This is illustrated in formula (3) below:
[0101]
[0102] Among them, C x C y These refer to the x-coordinate and y-coordinate of the cluster center point, respectively. It refers to the density value of any pixel in the target density patch.
[0103] Understandably, the computer device can repeatedly execute steps (3) and (4) above to continuously update the position of each cluster center point until the positions of all cluster center points no longer change, at which point the updating of the cluster center points stops. In this way, the positions of the cluster center points can be continuously corrected during the clustering process, making the positions of the cluster center points closer to the positions of pixels with higher density values in the density map. The closer the pixel is to the target object, the higher its density value, thus ensuring that the position of the cluster center point is closer to the actual position of the target object.
[0104] S204: Based on the clustering results of each density patch, determine the location data of the target objects contained in the image to be processed.
[0105] It is understandable that the clustering results for each density patch can be obtained through the above method. The clustering result for any density patch may include the location data (e.g., location coordinates) of the cluster center points. Specifically, the computer device determines the location data of the target objects contained in the image to be processed based on the clustering results of each density patch, which may include using the location data of the cluster center points in each density patch as the location data of the target objects contained in the image to be processed.
[0106] For example, please see Figure 5 , Figure 5 This is a schematic diagram illustrating a clustering process scenario provided in an embodiment of this application. For example... Figure 5 As shown, based on the detailed clustering process described above, the location data of the target objects contained in the image to be processed can be obtained. If the target object is a pig, the small black dot (ground-truth target center) represents the pig's actual location, and the small cross (clustering center) represents the pig's cluster center. Figure 5As can be seen, the positioning method mentioned in this application, which uses the K-means clustering algorithm, can reduce computational load and simplify the positioning process. Furthermore, the K-means clustering algorithm ensures both accuracy and iteration speed by segmenting the distribution area of the target object and providing more reliable initial cluster points. Simultaneously, it uses a weighted approach to update the cluster centers, making the clustering process more biased towards locations with higher density values, thus achieving higher cluster location accuracy and guaranteeing the accuracy of target object positioning.
[0107] In this embodiment, firstly, a target density map of the target objects contained in the image to be processed can be obtained; then, the target density map can be segmented to obtain multiple density map patches; next, each target object within each density map patch can be clustered to obtain the clustering result of each density map patch; finally, based on the clustering result of each density map patch, the location data of the target objects contained in the image to be processed can be determined. Therefore, this application can determine the location data of target objects by performing clustering based on density maps. This density map-based clustering method is relatively simple and can improve the efficiency of image processing. Furthermore, pre-segmenting the density map into multiple density map patches can reduce the computational load and complexity during subsequent clustering, further improving the efficiency and accuracy of image processing.
[0108] Please see Figure 6 , Figure 6 This is a schematic diagram of the structure of an image processing apparatus provided in an embodiment of this application. The image processing apparatus 600 can be applied to the computer equipment (e.g., a terminal device or a server) in the foregoing embodiments. The image processing apparatus 600 can be a computer program (including program code) running on the computer equipment; for example, the image processing apparatus 600 is application software. The image processing apparatus 600 can be used to execute corresponding steps in the data processing method provided in the embodiments of this application. The image processing apparatus 600 may include:
[0109] The acquisition unit 601 is used to acquire the target density map of the target object contained in the image to be processed;
[0110] The processing unit 602 is used to segment the target density map to obtain multiple density map blocks;
[0111] The processing unit 602 is also used to perform clustering processing on each target object in each density patch to obtain the clustering result of each density patch;
[0112] The processing unit 602 is also used to determine the location data of the target objects contained in the image to be processed based on the clustering results of each density patch.
[0113] In one possible implementation, the processing unit 602 performs clustering processing on each target object within each density patch to obtain the clustering result for each density patch, which is then used to perform the following operations:
[0114] Obtain the density value of each pixel in the target density patch, where the target density patch is any one of multiple density patches;
[0115] The number of clusters in the target density patch is determined based on the density value of each pixel in the target density patch.
[0116] Based on the number of clusters in the target density patch, clustering is performed on each target object within the target density patch to obtain the clustering result of the target density patch.
[0117] In one possible implementation, the processing unit 602 performs clustering processing on each target object within the target density patch based on the number of clusters in the target density patch, obtaining the clustering result of the target density patch, which is used to perform the following operations:
[0118] Based on the number of clusters in the target density patch, N initial cluster points are determined from the target density patch, where N is a positive integer and equal to the number of clusters in the target density patch;
[0119] Based on N initial cluster points, clustering is performed on each target object within the target density patch to obtain the clustering result of the target density patch.
[0120] In one possible implementation, processing unit 602 determines N initial cluster points from the target density patch based on the number of clusters in the target density patch, for performing the following operations:
[0121] Multiple local maxima are obtained from the target density patch. A local maximum is a pixel that corresponds to the largest density value within a preset range.
[0122] Based on the number of clusters in the target density patch, N initial cluster points are determined from the multiple local maxima obtained.
[0123] In one possible implementation, the number of multiple local maxima is represented by K; K is a positive integer; the processing unit 602 performs the following operations based on the number of clusters in the target density patch:
[0124] If N > K, then obtain NK pixels from the target density patch and combine the obtained NK pixels and K local maxima into N initial cluster points;
[0125] If N≤K, then select N local maxima from the K local maxima and use the selected N local maxima as N initial cluster points.
[0126] In one possible implementation, the processing unit 602 performs clustering processing on each target object within the target density patch based on N initial clustering points to obtain the clustering result of the target density patch, which is then used to perform the following operations:
[0127] Obtain the distances from each target pixel within the target density patch to the N initial cluster points, and assign each target pixel to the cluster set containing the nearest initial cluster point. A target pixel can be any pixel within the target density patch.
[0128] Based on the target cluster set corresponding to the target initial cluster point, the position of the target initial cluster point is updated to obtain the target updated cluster point. The target initial cluster point is any one of the N initial cluster points.
[0129] Based on the N updated clustering points obtained after the update, clustering is performed on each target object within the target density map block to obtain the clustering result of the target density map.
[0130] In one possible implementation, processing unit 602 updates the position of the target initial cluster point based on the target cluster set corresponding to the target initial cluster point, obtaining the target updated cluster point, and performs the following operations:
[0131] Obtain the density value of each pixel within the target cluster set;
[0132] Based on the position coordinates of each pixel in the target cluster set and the density value of each pixel, the position of the target initial cluster point is updated by weighted averaging, resulting in the updated target initial cluster point.
[0133] In this embodiment, firstly, a target density map of the target objects contained in the image to be processed can be obtained; then, the target density map can be segmented to obtain multiple density map patches; next, each target object within each density map patch can be clustered to obtain the clustering result of each density map patch; finally, based on the clustering result of each density map patch, the location data of the target objects contained in the image to be processed can be determined. Therefore, this application can determine the location data of target objects by performing clustering based on density maps. This density map-based clustering method is relatively simple and can improve the efficiency of image processing. Furthermore, pre-segmenting the density map into multiple density map patches can reduce the computational load and complexity during subsequent clustering, further improving the efficiency and accuracy of image processing.
[0134] Please see Figure 7 , Figure 7This is a schematic diagram of the structure of a computer device provided in an embodiment of this application. The computer device 700 is used to execute the steps performed by the computer device (terminal device or server) in the aforementioned method embodiments. The computer device 700 includes: one or more processors 710; one or more input devices 720; one or more output devices 730; and a memory 740. The processors 710, input devices 720, output devices 730, and memory 740 are connected via a bus 750. The memory 740 is used to store a computer program, which includes program instructions. The processor 710 is used to call the program instructions stored in the memory 740 to perform the following operations:
[0135] Obtain the target density map of the target objects contained in the image to be processed;
[0136] The target density map is segmented to obtain multiple density map patches;
[0137] Clustering is performed on each target object within each density patch to obtain the clustering result for each density patch;
[0138] Based on the clustering results of each density patch, the location data of the target objects contained in the image to be processed are determined.
[0139] In one possible implementation, the processor 710 performs clustering processing on each target object within each density patch to obtain the clustering result for each density patch, which is then used to perform the following operations:
[0140] Obtain the density value of each pixel in the target density patch, where the target density patch is any one of multiple density patches;
[0141] The number of clusters in the target density patch is determined based on the density value of each pixel in the target density patch.
[0142] Based on the number of clusters in the target density patch, clustering is performed on each target object within the target density patch to obtain the clustering result of the target density patch.
[0143] In one possible implementation, the processor 710 performs clustering processing on each target object within the target density patch based on the number of clusters in the target density patch, obtaining the clustering result of the target density patch, which is then used to perform the following operations:
[0144] Based on the number of clusters in the target density patch, N initial cluster points are determined from the target density patch, where N is a positive integer and equal to the number of clusters in the target density patch;
[0145] Based on N initial cluster points, clustering is performed on each target object within the target density patch to obtain the clustering result of the target density patch.
[0146] In one possible implementation, the processor 710 determines N initial cluster points from the target density patch based on the number of clusters in the target density patch, for the following operations:
[0147] Multiple local maxima are obtained from the target density patch. A local maximum is a pixel that corresponds to the largest density value within a preset range.
[0148] Based on the number of clusters in the target density patch, N initial cluster points are determined from the multiple local maxima obtained.
[0149] In one possible implementation, the number of multiple local maxima is denoted by K; K is a positive integer; the processor 710 performs the following operations based on the number of clusters in the target density map:
[0150] If N > K, then obtain NK pixels from the target density patch and combine the obtained NK pixels and K local maxima into N initial cluster points;
[0151] If N≤K, then select N local maxima from the K local maxima and use the selected N local maxima as N initial cluster points.
[0152] In one possible implementation, the processor 710 performs clustering processing on each target object within the target density patch based on N initial clustering points to obtain the clustering result of the target density patch, which is then used to perform the following operations:
[0153] Obtain the distances from each target pixel within the target density patch to the N initial cluster points, and assign each target pixel to the cluster set containing the nearest initial cluster point. A target pixel can be any pixel within the target density patch.
[0154] Based on the target cluster set corresponding to the target initial cluster point, the position of the target initial cluster point is updated to obtain the target updated cluster point. The target initial cluster point is any one of the N initial cluster points.
[0155] Based on the N updated clustering points obtained after the update, clustering is performed on each target object within the target density map block to obtain the clustering result of the target density map.
[0156] In one possible implementation, the processor 710 updates the position of the target initial cluster point based on the target cluster set corresponding to the target initial cluster point, obtaining the target updated cluster point, which is used to perform the following operations:
[0157] Obtain the density value of each pixel within the target cluster set;
[0158] Based on the position coordinates of each pixel in the target cluster set and the density value of each pixel, the position of the target initial cluster point is updated by weighted averaging, resulting in the updated target initial cluster point.
[0159] In this embodiment, firstly, a target density map of the target objects contained in the image to be processed can be obtained; then, the target density map can be segmented to obtain multiple density map patches; next, each target object within each density map patch can be clustered to obtain the clustering result of each density map patch; finally, based on the clustering result of each density map patch, the location data of the target objects contained in the image to be processed can be determined. Therefore, this application can determine the location data of target objects by performing clustering based on density maps. This density map-based clustering method is relatively simple and can improve the efficiency of image processing. Furthermore, pre-segmenting the density map into multiple density map patches can reduce the computational load and complexity during subsequent clustering, further improving the efficiency and accuracy of image processing.
[0160] Furthermore, it should be noted that this application also provides a computer storage medium storing a computer program, which includes program instructions. When the processor executes these program instructions, it can perform the methods described in the preceding embodiments. Therefore, further details will not be provided here. For technical details not disclosed in the embodiments of the computer storage medium involved in this application, please refer to the description of the method embodiments of this application. As an example, the program instructions can be deployed on a computer device, executed on multiple computer devices located in one location, or executed on multiple computer devices distributed in multiple locations and interconnected through a communication network.
[0161] According to one aspect of this application, a computer program product or computer program is provided, comprising computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium and executes the computer instructions, causing the computer device to perform the methods described in the preceding embodiments; therefore, further details will not be provided here.
[0162] Those skilled in the art will understand that all or part of the processes in the above embodiments can be implemented by a computer program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, it can include the processes of the embodiments of the above methods. The storage medium can be a magnetic disk, optical disk, read-only memory (ROM), or random access memory (RAM), etc.
[0163] The above-disclosed embodiments are merely preferred embodiments of this application and should not be construed as limiting the scope of this application. Therefore, any equivalent variations made in accordance with the claims of this application shall still fall within the scope of this application.
Claims
1. An image processing method, characterized by, The method comprises the following steps: obtaining a target density map of target objects contained in a to-be-processed image; performing segmentation processing on the target density map to obtain a plurality of density map blocks; performing clustering processing on each target object in each density map block to obtain a clustering result of each density map block; determining position data of target objects contained in the to-be-processed image based on the clustering result of each density map block; wherein the clustering processing on each target object in each density map block to obtain the clustering result of each density map block comprises: obtaining density values of each pixel point in a target density map block, the target density map block being any one of the plurality of density map blocks; performing summation operation on the density values of each pixel point in the target density map block to obtain a summation result, the summation of the density values of the pixel points in each polygon object in the target density map block being 1; determining the number of polygon objects in the target density map block according to the summation result, and determining the number of polygon objects as the clustering number of the target density map block; performing clustering processing on each target object in the target density map block according to the clustering number of the target density map block to obtain the clustering result of the target density map block.
2. The method of claim 1, wherein, The clustering processing on each target object in the target density map block according to the clustering number of the target density map block to obtain the clustering result of the target density map block comprises: determining N initial clustering points from the target density map block according to the clustering number of the target density map block, N being a positive integer and equal to the clustering number of the target density map block; performing clustering processing on each target object in the target density map block according to the N initial clustering points to obtain the clustering result of the target density map block.
3. The method of claim 2, wherein, The determination of the N initial clustering points from the target density map block according to the clustering number of the target density map block comprises: obtaining a plurality of local maximum points from the target density map block, the local maximum point being a pixel point corresponding to the maximum density value in a preset range; determining N initial clustering points from the obtained plurality of local maximum points according to the clustering number of the target density map block.
4. The method of claim 3, wherein, The number of the plurality of local maximum points is represented as K; K is a positive integer; The determination of the N initial clustering points from the obtained plurality of local maximum points according to the clustering number of the target density map block comprises: if N > K, obtaining N-K pixel points from the target density map block, and combining the obtained N-K pixel points and K local maximum points into N initial clustering points; if N ≤ K, selecting N local maximum points from the K local maximum points, and taking the selected N local maximum points as the N initial clustering points.
5. The method of claim 2, wherein, The clustering processing on each target object in the target density map block according to the N initial clustering points to obtain the clustering result of the target density map block comprises: obtaining distances from the target pixel point in the target density map block to the N initial clustering points, and dividing the target pixel point into a clustering set in which the initial clustering point closest to the target pixel point is located, the target pixel point being any pixel point in the target density map block; updating a position of the target initial clustering point based on a target clustering set corresponding to the target initial clustering point, to obtain a target updated clustering point, the target initial clustering point being any initial clustering point in the N initial clustering points; performing clustering processing on each target object in the target density map block according to the N updated clustering points obtained after the updating, to obtain a clustering result of the target density map.
6. The method of claim 5, wherein, The updating of the position of the target initial clustering point based on the target clustering set corresponding to the target initial clustering point to obtain the target updated clustering point comprises: obtaining density values of each pixel point in the target clustering set; updating the position of the target initial clustering point based on position coordinates of each pixel point in the target clustering set and the density value of each pixel point, to obtain the updated target initial clustering point.
7. An image processing apparatus characterized by comprising: comprise: an obtaining unit, configured to obtain a target density map of a target object contained in a to-be-processed image; a processing unit, configured to perform segmentation processing on the target density map, to obtain a plurality of density map blocks; the processing unit is further configured to perform clustering processing on each target object in each density map block, to obtain a clustering result of each density map block; the processing unit is further configured to determine position data of the target object contained in the to-be-processed image based on the clustering result of each density map block; wherein the processing unit is specifically configured to: obtain density values of each pixel point in a target density map block, the target density map block being any one of the plurality of density map blocks; perform summation operation on the density values of each pixel point in the target density map block, to obtain a summation result, the density values of the pixel points in each polygon object in the target density map block summing to 1; determine a number of polygon objects in the target density map block based on the summation result, and determine the number of polygon objects as a clustering number of the target density map block; perform clustering processing on each target object in the target density map block based on the clustering number of the target density map block, to obtain a clustering result of the target density map block.
8. A computer device, comprising: comprise: a processor adapted to execute a computer program; a computer readable storage medium, the computer readable storage medium storing a computer program, the computer program being executed by the processor to implement the image processing method in any one of claims 1-6.
9. A computer-readable storage medium, characterized in that, The computer readable storage medium stores a computer program, the computer program comprising program instructions, the program instructions being executed by the processor to execute the image processing method in any one of claims 1-6.
Citation Information
Patent Citations
Integer programming based crowd density estimation method
CN105740819A
Density peak-core fusion-based adaptive clustering method
CN109840558A
Method for detecting and counting distribution of dense crowds in video
CN114005085A