Image segmentation method and device, terminal equipment and computer readable storage medium
By acquiring and fusing image features to improve the accuracy and efficiency of image segmentation, it solves the problem of high computational resource consumption in the existing technology and achieves efficient segmentation of complex images.
Patent Information
- Application Number
- CN202310349178.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-31
- Publication Date
- 2024-10-18
AI Technical Summary
Existing image segmentation technology consumes a lot of computing resources when processing complex images, and it is difficult to guarantee efficiency and accuracy, especially when a large number of training samples are required.
By obtaining different image features of the image to be segmented and performing secondary fusion to obtain the target fusion image features, the image is segmented based on these rich features to improve the accuracy and efficiency of segmentation while saving computing resources.
The accuracy and efficiency of image segmentation are significantly improved, and edge areas, special shapes and color boundaries in images can be more precisely processed, effectively saving computing resources.
Smart Images

Figure CN118799339A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image segmentation method, apparatus, terminal device and computer-readable storage medium. Background Art
[0002] Image segmentation refers to the segmentation of different objects in an image. It is currently widely used in many fields, such as face recognition, satellite image positioning, medical pathology detection, etc. With the development of artificial intelligence algorithms, the most commonly used method is to use image segmentation related models or networks to complete image segmentation.
[0003] However, as the content and scenes of images become increasingly rich, it is difficult to accurately segment images. A large number of training samples are required to train the above image segmentation models or networks, which results in huge consumption of computing resources and makes it difficult to guarantee the efficiency and accuracy of image segmentation. Summary of the invention
[0004] The present application provides an image segmentation method, which can significantly improve the accuracy and efficiency of image segmentation and effectively save the computing resources required for image segmentation by obtaining different image features of an image to be segmented and target fused image features spliced together by fused image features corresponding to different image features, and segmenting the image to be segmented according to the target fused image features containing the above rich features.
[0005] In a first aspect, the present application provides an image segmentation method, the method comprising:
[0006] Obtain the image to be segmented;
[0007] Performing secondary fusion on image features of different scales in the image to be segmented to obtain target fused image features;
[0008] The image to be segmented is segmented based on the target fused image features.
[0009] In a second aspect, the present application further provides an image segmentation device, the device comprising:
[0010] An image acquisition module, used for acquiring an image to be segmented;
[0011] An image fusion module performs secondary fusion on image features of different scales in the image to be segmented to obtain target fused image features;
[0012] The image segmentation module is used to segment the image to be segmented based on the target fusion image features.
[0013] In a third aspect, the present application also provides a terminal device, comprising a processor, a memory, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the steps in any one of the image segmentation methods described.
[0014] In a fourth aspect, the present application further provides a computer-readable storage medium, on which a computer program is stored, and the computer program is executed by a processor to implement the steps in any one of the image segmentation methods.
[0015] The image segmentation method, apparatus, terminal device and computer-readable storage medium provided by the present application obtain different image features of the image to be segmented, as well as target fused image features spliced together by fused image features corresponding to the different image features, and segments the image to be segmented according to the target fused image features containing the above rich features. During segmentation, the detailed features such as the edge area, special shape and color boundary of the target object in the image to be segmented can be processed more finely, thereby significantly improving the accuracy and efficiency of image segmentation and effectively saving the computing resources required for image segmentation. BRIEF DESCRIPTION OF THE DRAWINGS
[0016] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0017] Figure 1 is a schematic diagram of a scene of an image processing system provided in an embodiment of the present application;
[0018] Figure 2 It is a flowchart of the image segmentation method in an embodiment of the present application;
[0019] Figure 3 is a schematic diagram of the image segmentation process provided in an embodiment of the present application;
[0020] Figure 4 is a schematic diagram of obtaining splicing features provided in an embodiment of the present application;
[0021] Figure 5 is a schematic diagram of obtaining a local segmented image provided in an embodiment of the present application;
[0022] Figure 6 It is a schematic diagram of the module structure of the image segmentation device in an embodiment of the present application;
[0023] Figure 7It is a schematic diagram of the structure of the terminal device in the embodiment of the present application. DETAILED DESCRIPTION
[0024] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of this application.
[0025] In the description of the present application, it should be understood that the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the feature. In the description of the present application, "plurality" means two or more, unless otherwise clearly and specifically defined.
[0026] In this application, the word "exemplary" is used to mean "used as an example, illustration or description". Any embodiment described as "exemplary" in this application is not necessarily to be construed as being more preferred or advantageous than other embodiments. At the same time, it is to be understood that in the specific implementation of this application, when user information, user data and other related data are involved, when the above embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data shall comply with relevant laws, regulations and standards of relevant countries and regions.
[0027] In order to enable any person skilled in the art to implement and use the present application, the following description is provided. In the following description, details are listed for the purpose of explanation. It should be understood that those of ordinary skill in the art will recognize that the present application can be implemented without using these specific details. In other examples, known structures and processes will not be elaborated in detail to avoid unnecessary details that make the description of the present application obscure. Therefore, the present application is not intended to be limited to the embodiments shown, but is consistent with the widest range of principles and features disclosed in the present application.
[0028] The present application provides an image segmentation method, apparatus, device and storage medium, which are described in detail below.
[0029] See also Figure 1 , Figure 1 Schematic diagram of a scene of an image processing system provided in an embodiment of the present application. The image processing system may include a terminal device 100 and a storage device 200. The storage device 200 may transmit data to the terminal device 100. Figure 1The terminal device 100 in the embodiment can obtain the image stored in the storage device 200 to execute the image segmentation method in the present application.
[0030] In the embodiment of the present application, the terminal device 100 includes but is not limited to a desktop computer, a portable computer, a network server, a PDA (Personal Digital Assistant), a tablet computer, a wireless terminal device, an embedded device, etc.
[0031] In the embodiments of the present application, communication between the terminal device 100 and the storage device 200 can be achieved through any communication method, including but not limited to mobile communications based on the 3rd Generation Partner ship Project (3GPP), Long Term Evolution (LTE), Worldwide Interoperability for Microwave Access (WiMAX), or computer network communications based on the TCP / IP Protocol Suite (TCP / IP), User Datagram Protocol (UDP), etc.
[0032] It should be noted that Figure 1 The scene diagram of the image processing system shown is only an example. The image processing system and scene described in the embodiment of the present application are intended to more clearly illustrate the technical solution of the embodiment of the present application, and do not constitute a limitation on the technical solution provided in the embodiment of the present application. Ordinary technicians in this field can know that with the evolution of the image processing system and the emergence of new business scenarios, the technical solution provided in the embodiment of the present application is also applicable to similar technical problems.
[0033] like Figure 2 As shown, Figure 2 This is a flow chart of an embodiment of the image segmentation method in the embodiment of the present application. The image segmentation method may include the following steps 201 to 203:
[0034] Step 201: Obtain an image to be segmented.
[0035] The image to be segmented refers to the image to be segmented. Generally speaking, the purpose of image segmentation is to segment the foreground area and the background area of the image to be segmented. For example, in the segmented image, the background area can be represented by black, and the pixel value of each pixel in the background area is 0; correspondingly, the foreground area can be represented by white, and the pixel value of each pixel in the foreground area is 255, so as to distinguish the foreground area from the background area through the black and white colors with large visual differences.
[0036] In some embodiments, before segmenting the image to be segmented, feature extraction can be performed on the image to be segmented of different scales to obtain image features of different scales. The scale mentioned in this application is the size, and the scale of the image is usually expressed by resolution, for example, the scale of the image to be segmented is 336*336, 256*256, etc.
[0037] In order to further enrich the content included in the scale, in some embodiments, the scale of the image can also be jointly represented by the resolution, number and number of channels of the image. For example, the scale of an image can be represented as [1, 336, 336, 3], which means that the number of the image is 1, the resolution is 336*336, and the number of channels is 3, that is, the image is an image with a resolution of 336*336 and 3 channels.
[0038] In order to better implement the embodiment of the present application, in one embodiment of the present application, before step 201, the method of the present application may include:
[0039] Downsampling the image to be segmented at different downsampling multiples to obtain downsampled images of different scales;
[0040] The downsampled images of different scales are subjected to convolution processing with the number of channels changed to obtain image features of different scales.
[0041] In order to obtain images to be segmented of different scales, in some embodiments, different downsampling multiples can be set first, and the image to be segmented can be downsampled based on the set downsampling multiples to obtain downsampled images of different scales. For example, the downsampling multiple can be 2, 4, 8, 16, 32, etc.
[0042] Specifically, when downsampling the image to be segmented, the resolution and number of channels of the image to be segmented can be changed according to the downsampling multiple. For example, if the scale of the image to be segmented is [1, 336, 336, 16] and the downsampling multiple is 2, the scale of the image to be segmented after downsampling becomes [1, 168, 168, 32].
[0043] It can be seen that when the image is downsampled, the resolution of the image is reduced in proportion to the downsampling multiple, while the number of channels of the image is increased in proportion to the downsampling multiple, so that the downsampled images of different scales will have more and richer features compared to the original image to be segmented due to the changes in resolution and number of channels.
[0044] It should also be noted that the above process of downsampling the image to be segmented to obtain the downsampled image can be performed by the encoding end of the relevant image segmentation model or network, for example, the encoding end can be a mobile enetV2 network or other networks. In addition, the downsampling multiples and the number of downsampled images mentioned above are also determined according to demand, and this embodiment does not limit this.
[0045] In some embodiments, the downsampled images of different scales obtained above may be subjected to convolution processing with a changed number of channels. For example, each downsampled image may be subjected to convolution processing by n convolution kernels, and since the number of channels of the image after convolution is equal to the number of convolution kernels, image features with n channels may be obtained.
[0046] Among them, the number of convolution kernels n corresponding to the convolution processing with the changed number of channels can be set according to the actual needs of image processing. It can be understood that as the downsampling multiple increases, a downsampled image with a larger number of channels will be obtained, and the number and complexity of the features of the image itself are higher, which makes the subsequent computational resources required for feature extraction and segmentation of the image larger. Therefore, a suitable number of convolution kernels can be set according to the needs. For example, the number of convolution kernels can be set to 16, so that the number of channels of the image features after the convolution processing with the changed number of channels is 16, so as to avoid the appearance of image features with a higher number of channels and complexity. Accordingly, the size of the convolution kernel can also be set according to the actual feature extraction needs, such as 1*1, 3*3 convolution kernels, etc.
[0047] Step 202: Image feature fusion The image features of different scales in the image to be segmented are secondary fused to obtain target fused image features.
[0048] In some embodiments, image features of each scale can be spliced and convolved to achieve fusion, thereby obtaining fused image features of each scale. It should be noted that the splicing mentioned in this application is concatenate splicing, that is, the number of channels of the two spliced objects is superimposed, but the pixel value of the image in each channel remains unchanged. It should also be noted that the necessary condition for performing concatenate splicing on different spliced objects is that the resolution between each spliced object is equal. Therefore, in order to achieve successful splicing and fusion of image features of different scales, each image feature should be unified to the same resolution before splicing.
[0049] Just as an example, Figure 3 As shown, assuming Figure 3 The image features in the figure are image feature A, image feature B, image feature C and image feature D from top to bottom. Taking the fusion of image feature A and image feature B as an example, as can be seen from the downsampling mark in the figure, the resolution of image feature A is smaller than that of image feature B. Therefore, before the fusion of the above two image features, image feature A can be upsampled first, the resolution of image feature A can be increased to be equal to the resolution of image feature B, and then spliced and convolved.
[0050] To give a further example, if the scale of image feature A is [1, 10, 10, 512] and the scale of image feature B is [1, 20, 20, 256], then image feature A can be upsampled to change its scale to [1, 20, 20, 512], and then concatenated with image feature B to obtain a feature with a scale of [1, 20, 20, 768], and then the concatenated feature is convolved to obtain a fused image feature.
[0051] It can be understood that, since image feature A is a feature obtained through downsampling and convolution processing, image feature A has a larger number of features than the image to be segmented, and the pixel value of each pixel in the image is changed through convolution processing, and more detailed features in the image are effectively extracted. Therefore, even if image feature A is scaled by upsampling before being fused with image feature B, the above method of obtaining fused image features can achieve gradual fusion between image features of different scales and obtain the effect of richer image feature information.
[0052] In order to better implement the embodiment of the present application, in one embodiment of the present application, step 202 may include:
[0053] For each of the scales, the image features of the scale and the fused image features of a previous scale adjacent to the image features are fused to obtain the fused image features of the scale.
[0054] like Figure 3 As shown, assuming Figure 3 The fused image features in the image are fused image feature E, fused image feature F, fused image feature G and fused image feature Q from top to bottom. Figure 3 It can be seen from the direction of the arrow in that the fused image feature F is obtained by fusing the image feature C and the fused image feature E, that is, the image feature corresponding to the fused image feature F is the image feature C, the previous image feature adjacent to the image feature C is the image feature B, and the fused image feature corresponding to the image feature B is the fused image feature E.
[0055] It can be understood that when image features of different scales are fused in the above manner, the fused object can include not only image features of different scales, but also different fused image features. Therefore, the fused image features have richer features than the image features, so that the image to be segmented can be subsequently segmented based on the size fusion features containing rich features. During segmentation, the edge areas, special shapes, color boundaries and other detail features of the target object in the segmented image can be processed more finely to improve the accuracy of image segmentation.
[0056] In order to better implement the embodiment of the present application, in one embodiment of the present application, step 202 may include:
[0057] The image features of different scales are fused to obtain fused image features of different scales;
[0058] The fused image features of different scales are concatenated with the image features of different scales to obtain the target fused image features.
[0059] like Figure 3 As shown, assuming Figure 3 The stitching features in are stitching feature H, stitching feature I and stitching feature G. It can be seen that the stitching features are obtained by stitching different fused image features, or by stitching image features with other stitching features. Therefore, the stitching features of the present application are similar to the fused image features, and also have the characteristics of many features, rich features, and fusion of multi-scale image information.
[0060] In order to better implement the embodiment of the present application, in one embodiment of the present application, the step of “fusing image features of different scales to obtain fused image features of different scales” may include:
[0061] splicing the fused image features belonging to the first target scale among the fused image features of each scale to obtain a first splicing feature;
[0062] The first splicing features, image features belonging to the second target scale among the image features of each scale, image features belonging to the third target scale, and fused image features belonging to the third target scale among the fused image features of each scale are spliced to obtain a target fused image feature.
[0063] Among them, the first target scale is smaller than the second target scale, and the second target scale is smaller than the third target scale. It can be understood that, for the different scales corresponding to the image features, fused image features and splicing features involved in each image segmentation, the third target scale is a scale in a larger interval among the different scales, the second target scale is a scale in a middle interval among the different scales, and the first target scale is a scale in a smaller interval among the different scales.
[0064] In order to facilitate the understanding of the above content, Figure 3 As shown, the first splicing feature is the splicing feature H, and the fused image features belonging to the first target scale among the fused image features of each scale are the fused image feature E and the fused image feature F. Therefore, the first splicing feature is obtained by splicing the fused image feature E and the fused image feature F.
[0065] Similar to the method of obtaining fused image features, in some embodiments, different fused image features may be subjected to splicing and convolution processing to obtain splicing features.
[0066] like Figure 4 As shown, Figure 4 Schematic diagram of obtaining splicing features provided in an embodiment of the present application. Taking the splicing to obtain the first splicing feature as an example, the first input may be the fused image feature F, the second input may be the fused image feature E, and after obtaining an intermediate splicing feature through the concatenate operation, according to Figure 4 As can be seen from the arrows in , the intermediate splicing features can flow to three different branches. For example, in the first branch, the intermediate splicing features can be first convolved with a 3*3 convolution kernel, and the processed features can be convolved with a 1*1 convolution kernel to obtain the first intermediate convolution feature. Correspondingly, in the second branch, the intermediate splicing features can first be convolved with a 1*1 convolution kernel, and the processed features can be convolved with a 3*3 convolution kernel to obtain the second intermediate convolution feature. Finally, the first intermediate convolution feature, the second intermediate convolution feature and the intermediate splicing feature in the third branch are spliced to obtain the corresponding splicing feature.
[0067] In some embodiments, after obtaining the first stitching feature, the first stitching feature can be stitched with the image feature belonging to the second target scale, the image feature belonging to the third target scale, and the fused image feature belonging to the third target scale in the fused image features of each scale to obtain the target fused image feature. Figure 3 For example, the first stitching feature is the stitching feature H, the image feature belonging to the second target scale is the image feature D, the image feature belonging to the third target scale is any image feature whose scale is greater than the image feature D, and the scale fusion belonging to the third target scale is the fused image feature Q. Therefore, the target fused image feature can fuse all the features and detail information extracted from all previous image features, fused image features and the first stitching feature. For example, the target fused image feature can include high-level features in the image to be segmented, such as high-level semantic information such as the edge, shape and color of the target object contained in the image to be segmented.
[0068] In some embodiments, the image features of different scales may be first spliced, and then spliced with the fused image features of the third target scale and the first spliced features to obtain the target fused image features. In some embodiments, the image features of different scales may also be first spliced with the first spliced features, and then spliced with the fused image features of the third target scale to obtain the target fused image features. Therefore, this embodiment does not limit the splicing order used to obtain the target fused image features by splicing different image features, fused image features, and the first spliced features.
[0069] In order to better implement the embodiment of the present application, in one embodiment of the present application, the first splicing feature, the image features belonging to the second target scale among the image features of each scale, the image features belonging to the third target scale, and the fused image features belonging to the third target scale among the fused image features of each scale are spliced to obtain the target fused image feature, including:
[0070] Splicing the image feature of the second target scale, the image feature of the third target scale, and the first splicing feature to obtain a second splicing feature;
[0071] The second splicing feature is spliced with the fused image feature of the third target scale to obtain the target fused image feature.
[0072] In order to better understand the above content, Figure 3 As shown, the image feature of the second target scale is still the image feature D, and the image feature belonging to the third target scale is still any image feature whose scale is larger than the image feature D, then the second stitching feature may be the stitching feature J. In some embodiments, the image feature D may be stitched with the stitching feature H of the first stitching feature to obtain the stitching feature I, and then the image feature belonging to the third target scale may be stitched with the stitching feature I to obtain the stitching feature J of the second stitching feature. Therefore, similar to the method of obtaining the target fused image feature, the present embodiment does not limit the stitching order used to obtain the second stitching feature by stitching different image features with the first stitching feature.
[0073] It should be noted that no matter which of the above splicing orders is used to obtain the target fused image features, after the last concatenation operation to obtain the target fused image features is completed, the features after the concatenation operation can be convolved through two convolution kernels so that the number of channels of the final target fused image features is 2, so as to facilitate the subsequent predictive segmentation of the image to be segmented to obtain a two-channel segmented image.
[0074] In order to better implement the embodiment of the present application, in one embodiment of the present application, the fused image features belonging to the first target scale in the fused image features of each scale are spliced to obtain the first spliced features, including:
[0075] Performing feature processing on at least one fused image feature of the first target scale to obtain a processed fused image feature;
[0076] The processed fused image features and the fused image features of the first target scale that have not been feature processed are spliced to obtain a first spliced feature.
[0077] like Figure 3 As shown, the fused image feature F of the first target scale may be processed to obtain a processed fused image feature F1. In some embodiments, the feature processing performed on the fused image feature F may be at least one convolution process to extract detail features in the fused image feature F. For example, the fused image feature F may be first convolved with a 3*3 convolution kernel and then convolved with a 1*1 convolution kernel to perform feature processing on the fused image feature F to obtain a processed fused image feature F1.
[0078] It can be understood that in the process of image segmentation using the method of the present application, since the image features A and image features B corresponding to the smaller first target scale do not directly participate in the operation of the target fused image features, for example, image feature A is fused with image feature B after upsampling to form fused image feature E, so that both image feature A and image feature B participate in the subsequent splicing operation to obtain the target fused image features after fused image feature E. In the process of splicing the fused image feature E with other image features or splicing features to obtain the target fused image features, it is easy to lose the smaller features belonging to the first target scale. Therefore, feature extraction processing can be added to the fused image features belonging to the second target scale to extract the detail information retained in the smaller-scale image features from the moderate-scale fused image features.
[0079] It should be noted that the above process of obtaining the target fused image features based on image features, fused image features and splicing features can be implemented by a decoding end corresponding to the encoding end. For example, the decoding end can be an FPN network, a Light-FPN network, etc., and this embodiment does not limit this.
[0080] Step 203: Segment the image to be segmented based on the target fusion image features.
[0081] Specifically, the image segmentation model can predict and output a grayscale segmentation image with two black and white channels based on the rich features of the image to be segmented at different scales contained in the target fusion image features.
[0082] In order to better implement the embodiments of the present application, in one embodiment of the present application, the method of the present application may further include:
[0083] Determine a first probability that each pixel in the segmented image belongs to the foreground area after the image to be segmented is segmented based on the target fused image feature;
[0084] Determining a first training loss based on the first probability and a second probability that each pixel actually belongs to the foreground area;
[0085] Obtaining a true segmentation image, a local segmentation image, and a reverse segmentation image corresponding to the segmentation image obtained after segmentation by the image segmentation model, wherein the true segmentation image is a label image of the segmentation image, the local segmentation image is an image retaining a target foreground area in the true segmentation image, and the reverse segmentation image is an image whose foreground area and background area are opposite to those of the segmentation image;
[0086] Obtaining a first pixel matrix corresponding to the segmented image, a second pixel matrix corresponding to the true segmented image, a third pixel matrix corresponding to the local segmented image, and a fourth pixel matrix corresponding to the reverse segmented image, wherein each element of the pixel matrix represents a pixel value and a corresponding position of each pixel in the image;
[0087] Based on operations on the first pixel matrix, the second pixel matrix, the third pixel matrix, and the fourth pixel matrix, a loss pixel matrix corresponding to the segmented image is calculated;
[0088] Based on the loss pixel matrix, adding and averaging the pixel values corresponding to each pixel in the loss image to determine a second training loss;
[0089] The image segmentation model is iteratively trained according to the first training loss and the second training loss.
[0090] In some embodiments, calculating the training loss can be expressed as the following three formulas:
[0091] y=labels (1)
[0092]
[0093] loss=-∑ i ∑ j yij*lbp ij (3)
[0094] Wherein, formula (1) indicates that the corresponding label of the segmented image is y, and the label is the real segmented image of the image to be segmented, wherein each element in the real segmented image can be represented by a value between 0 and 255, where 0 is the pixel value of the black background area and 255 is the pixel value of the white foreground area. Alternatively, each element in the real segmented image can also be represented by a value between 0 and 1, where 0 indicates that the probability of the pixel being a pixel in the foreground area is 0, and 1 indicates that the probability of the pixel being a pixel in the foreground area is 100%.
[0095] In formula (2), i and j are the horizontal and vertical coordinates of the pixel in the image, respectively, and z ij is the pixel value of a pixel in the predicted segmented image, p ij For z ij The probability that the pixel belongs to the foreground area after being processed by the Softmax activation function. C represents the number of categories, which is consistent with the number of channels of the predicted output feature map. Considering the foreground and background, the value of C is 2. It means that at the same (i, j) position, the values on the feature maps of different channels corresponding to each other are added up and summed.
[0096] Among them, -yij*lnp in formula (3) ij The predicted loss deviation value calculated for this pixel based on the pixel at the corresponding position in the real segmented image can be understood as the predicted loss deviation value loss corresponding to the pixel in the segmented image. ij , loss is the predicted loss deviation value loss for all pixels ij Sum up and get the cross entropy loss of the final predicted value cross-entropy , and iterate the training until the loss is cross-entropy Minimum.
[0097] like Figure 5 As shown, Figure 5 is a schematic diagram of obtaining a local segmented image provided in an embodiment of the present application. In some embodiments, training can be performed for the accuracy of segmenting the target area, for example Figure 5 The target area can be the area corresponding to the hand of the human body in the image. Further, a local segmentation image including the hand area can be segmented from the real segmentation image, and based on the local segmentation image, the real segmentation image, the segmentation image and the reverse segmentation image, the image segmentation model can be subsequently trained to improve the accuracy of target area segmentation.
[0098] It should be noted that the target area can be set according to the specific requirements of the model training and is not limited to the hand area of the target object in the image. This embodiment does not impose any restrictions on this.
[0099] The pixel matrix can be understood as a matrix composed of the pixel values of each pixel in the image. For example, for an image with a resolution of 2*2, the pixel values from top to bottom and from left to right are 0, 255, 0, 255 respectively, then the pixel matrix corresponding to the image can be expressed as
[0100] In some embodiments, the specific Tensorflow code for calculating the training loss can be expressed as:
[0101] hand_loss(hand_mask,y_pred,y_true){
[0102] alpha = 0.25
[0103] y_pred=tf.nn.softmax(y_pred)
[0104] s1=y_true*log(y_pred)
[0105] s2=(1.-y_true)*log(1.-y_pred)
[0106] yn=1-y_pred
[0107] s3=alpha*yn*yn*s1+(1-alpha)*y_pred*y_pred*s2
[0108] s=hand_mask*s3
[0109] e_loss = -tf.reduce_mean(s)
[0110] return e_loss
[0111] }
[0112] Among them, alpha is a pre-set hyperparameter, y_pred is the first pixel matrix corresponding to the segmented image, y_true is the second pixel matrix corresponding to the true segmented image, hand_mask is the third pixel matrix corresponding to the local segmented image, yn is the fourth pixel matrix corresponding to the reverse segmented image, s is the loss function matrix, and e_loss is the loss function generated by the image segmentation model to segment the local segmented image containing the target area.
[0113] In some embodiments, the pixel values corresponding to each pixel in the loss matrix may be summed and averaged to obtain the corresponding loss function. For example, assuming the loss pixel matrix is but
[0114]
[0115] It should be noted that in order to calculate the value of the loss function more quickly without affecting the accuracy of the calculation results, the element values of the above pixel matrices can take values between 0 and 1. Correspondingly, 0 indicates that the probability that the pixel is a foreground area pixel is 0, and 1 indicates that the probability that the pixel is a foreground area pixel is 100%.
[0116] It can be understood that through the above method, a separate loss function calculation can be performed on the local segmentation image containing the target area segmented by the image segmentation model, so that the image segmentation model can have a more precise segmentation accuracy for the target area in a large number of image features and complex scenes.
[0117] From the above, it can be seen that the present application obtains different image features of the image to be segmented, and the target fused image features spliced together by the fused image features corresponding to the different image features, and segments the image to be segmented according to the target fused image features containing the above rich features. During segmentation, the edge areas, special shapes, color boundaries and other detail features of the target object in the image to be segmented can be processed more finely, thereby significantly improving the accuracy and efficiency of image segmentation, and effectively saving the computing resources required for image segmentation.
[0118] In order to better implement the image segmentation method in the embodiment of the present application, in addition to the image segmentation method, an image segmentation device is also provided in the embodiment of the present application, such as Figure 6 As shown, the device 300 includes:
[0119] An image acquisition module 301 is used to acquire an image to be segmented;
[0120] An image fusion module 302 performs secondary fusion on image features of different scales in the image to be segmented to obtain target fused image features;
[0121] The image segmentation module 303 is used to segment the image to be segmented based on the target fusion image features.
[0122] The image segmentation device provided by the present application acquires the image to be segmented through the image acquisition module 301; then, the image fusion module 302 performs secondary fusion on the image features of different scales in the image to be segmented to obtain the target fused image features; finally, the image segmentation module 303 segments the image to be segmented based on the target fused image features. Target fused image features.
[0123] In some embodiments of the present application, the image fusion module 302 is specifically used for:
[0124] For each of the scales, the image features of the scale and the fused image features of a previous scale adjacent to the image features are fused to obtain the fused image features of the scale.
[0125] In some embodiments of the present application, the image segmentation module 303 includes:
[0126] A first splicing feature acquisition submodule is used to splice the fused image features belonging to the first target scale among the fused image features of each scale to obtain a first splicing feature;
[0127] The target fused image feature acquisition submodule is used to splice the first splicing features, the image features belonging to the second target scale among the image features of each scale, the image features belonging to the third target scale, and the fused image features belonging to the third target scale among the fused image features of each scale to obtain the target fused image features, wherein the first target scale is smaller than the second target scale, and the second target scale is smaller than the third target scale.
[0128] In some embodiments of the present application, the first splicing feature acquisition submodule is specifically used to:
[0129] Splicing the image feature of the second target scale, the image feature of the third target scale, and the first splicing feature to obtain a second splicing feature;
[0130] The second splicing feature is spliced with the fused image feature of the third target scale to obtain the target fused image feature.
[0131] In some embodiments of the present application, the first splicing feature acquisition submodule is specifically used to:
[0132] Performing feature processing on at least one fused image feature of the first target scale to obtain a processed fused image feature;
[0133] The processed fused image features and the fused image features of the first target scale that have not been feature processed are spliced to obtain a first spliced feature.
[0134] In some embodiments of the present application, the image segmentation device of the present application further includes:
[0135] A down-sampling image acquisition module down-samples the image to be segmented at different down-sampling multiples to obtain down-sampled images of different scales;
[0136] The image feature acquisition module performs convolution processing with a change in the number of channels on downsampled images of different scales to obtain image features of different scales.
[0137] From the above, it can be seen that the image segmentation device of the present application can obtain different image features of the image to be segmented, and the target fused image features spliced together by the fused image features corresponding to the different image features, and segment the image to be segmented according to the target fused image features containing the above rich features. During segmentation, the edge areas, special shapes, color boundaries and other detail features of the target object in the image to be segmented can be processed more finely, thereby significantly improving the accuracy and efficiency of image segmentation, and effectively saving the computing resources required for image segmentation.
[0138] The present application also provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the steps of any image segmentation method in the present application. The terminal device integrates any image segmentation method provided in the present application. Figure 7 As shown, it shows a schematic diagram of the structure of the terminal device involved in the embodiment of the present application, specifically:
[0139] The terminal device may include one or more processing core processors 401, one or more computer-readable storage media memories 402, a power supply 403, an input unit 404 and other components. Those skilled in the art will appreciate that Figure 7 The terminal device structure shown in the figure does not constitute a limitation on the terminal device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently. Among them:
[0140] The processor 401 is the control center of the terminal device, and uses various interfaces and lines to connect various parts of the entire terminal device. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, the processor 401 executes various functions of the terminal device and processes data, thereby monitoring the terminal device as a whole. Optionally, the processor 401 may include one or more processing cores; the processor 401 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc. Preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, the user interface and the application program, etc., and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0141] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the terminal device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0142] The terminal device also includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, power consumption management and other functions through the power management system. The power supply 403 can also include any components such as one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, and power status indicators.
[0143] The terminal device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0144] Although not shown, the terminal device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the terminal device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, such as:
[0145] Obtain the image to be segmented;
[0146] Performing secondary fusion on image features of different scales in the image to be segmented to obtain target fused image features;
[0147] Based on the target fused image features, the image to be segmented is segmented. A person skilled in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructions, or by controlling related hardware through instructions. The instructions can be stored in a computer-readable storage medium and loaded and executed by a processor.
[0148] To this end, the embodiment of the present application provides a computer-readable storage medium, which may include: a read-only memory (ROM), a random access memory (RAM), a disk or an optical disk, etc. A computer program is stored thereon, and the computer program is loaded by a processor to execute the steps in any image segmentation method provided in the embodiment of the present application. For example, the computer program is loaded by the processor to execute the following steps:
[0149] Get the image to be processed;
[0150] Determine a first area and a second area of the image to be processed, wherein the first area and the second area are non-overlapping image areas;
[0151] The first region and the second region are enhanced in sequence to obtain a target image, wherein the degree of change of pixel values in the first region of the target image is smaller than the degree of change of pixel values in the second region of the target image.
[0152] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the detailed description of other embodiments above, and will not be repeated here.
[0153] In specific implementation, the above units or structures can be implemented as independent entities, or can be arbitrarily combined to be implemented as the same or several entities. The specific implementation of the above units or structures can refer to the previous method embodiments, which will not be repeated here.
[0154] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0155] The above is a detailed introduction to an image segmentation method and device provided in an embodiment of the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. An image segmentation method, characterized in that: The method comprises: Obtain the image to be segmented; Performing secondary fusion on image features of different scales in the image to be segmented to obtain target fused image features; The image to be segmented is segmented based on the target fused image features.
2. The method according to claim 1, characterized in that The second step of fusing the image features of different scales in the image to be segmented to obtain target fused image features includes: Fusing the image features of different scales to obtain fused image features of different scales; The fused image features of different scales are concatenated with the image features of different scales to obtain target fused image features.
3. The method according to claim 1, characterized in that: The second step of fusing the image features of different scales in the image to be segmented to obtain target fused image features includes: For any of the scales, the image features of the scale and the fused image features of the previous scale adjacent to the image features are fused to obtain the fused image features of the scale.
4. The method according to claim 1, characterized in that The second step of fusing the image features of different scales in the image to be segmented to obtain target fused image features includes: splicing the fused image features belonging to the first target scale among the fused image features of each scale to obtain a first splicing feature; The first splicing features, image features belonging to the second target scale among image features of each scale, image features belonging to the third target scale, and fused image features belonging to the third target scale among fused image features of each scale are spliced to obtain target fused image features, wherein the first target scale is smaller than the second target scale, and the second target scale is smaller than the third target scale.
5. The method according to claim 4, characterized in that The step of splicing the first splicing feature, the image features belonging to the second target scale among the image features of each scale, the image features belonging to the third target scale, and the fused image features belonging to the third target scale among the fused image features of each scale to obtain the target fused image feature includes: Splicing the image feature of the second target scale, the image feature of the third target scale, and the first splicing feature to obtain a second splicing feature; The second splicing feature is spliced with the fused image feature of the third target scale to obtain the target fused image feature.
6. The method according to claim 4, characterized in that The step of splicing the fused image features belonging to the first target scale among the fused image features of each scale to obtain the first spliced features includes: Performing feature processing on at least one fused image feature of the first target scale to obtain a processed fused image feature; The processed fused image features and the unprocessed fused image features of the first target scale are spliced to obtain a first spliced feature.
7. The method according to claim 1, characterized in that: Before obtaining the image to be segmented, the method further includes: Downsampling the image to be segmented at different downsampling multiples to obtain downsampled images of different scales; The downsampled images of different scales are subjected to convolution processing with the number of channels changed to obtain image features of different scales.
8. An image segmentation device, characterized in that: The device comprises: An image acquisition module, used for acquiring an image to be segmented; An image fusion module performs secondary fusion on image features of different scales in the image to be segmented to obtain target fused image features; The image segmentation module is used to segment the image to be segmented based on the target fusion image features.
9. A terminal device, characterized in that: The terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor, and the processor executes the computer program to implement the steps in the image segmentation method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and the computer program is executed by a processor to implement the steps in the image segmentation method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Image segmentation method, device, computer readable storage medium and computer equipment
CN110363780A
Image processing method and device and computer storage medium
CN111079761A
Image segmentation method, device, equipment, medium and program product
CN114565763A
Three-dimensional medical image segmentation method, system and device fused with 2D pooling and medium
CN115471441A
Image segmentation model training method and apparatus, image segmentation method and apparatus, and device and medium
WO2020199593A1
