Image processing method, system, device and medium
Through the binary processing and semantic segmentation model recognition in the image processing method, a background mask is generated to remove stains, solving the problem of low stain recognition and removal efficiency in the prior art, and achieving efficient and accurate stain removal effect.
Patent Information
- Application Number
- CN202411346844.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-26
- Publication Date
- 2025-01-07
- Estimated Expiration
- 2044-09-26
AI Technical Summary
The existing image processing technology is inefficient and inaccurate in spot recognition and removal, and cannot meet the speed and quality requirements of modern image processing.
The image processing method is adopted, including obtaining the original scanned image for binary processing, generating the original mask through image closing operation, using the pre-generated semantic segmentation model for stain recognition, determining the text area and generating the background mask, and finally clearing the image stain.
It improves the efficiency and accuracy of stain removal, reduces information loss, and meets the speed and quality requirements of modern image processing.
Smart Images

Figure CN118864302B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of image processing, and in particular to an image processing method, system, device and medium. Background Art
[0002] In the field of image processing, especially in the identification and removal of stains in scanned images, current technology mainly relies on manual processing and simple image processing algorithms.
[0003] Manual processing is one of the most common methods in many image editing jobs. Users usually use professional image editing software, such as Adobe Photoshop, GIMP, etc., to manually identify and remove stains in images. The advantage of this method is that users can flexibly process each image based on their own judgment and experience to ensure that the final effect meets expectations. However, manual processing of stain removal has low efficiency and quality, and requires high professional skills.
[0004] Simple image processing algorithms usually include basic denoising techniques such as median filtering and mean filtering. Median filtering is a commonly used nonlinear filtering technique that can effectively remove salt and pepper noise in images. Mean filtering smoothes images by calculating the average value of the neighborhood around each pixel in the image. These methods can reduce noise and stains in images to a certain extent, but they often cannot effectively distinguish between stains and text, and are prone to information loss.
[0005] Therefore, the current stain recognition and removal technology is insufficient in efficiency, accuracy and automation, and cannot meet the speed and quality requirements of modern image processing. Summary of the invention
[0006] In order to improve the efficiency of stain removal, the present application provides an image processing method, system, device and medium.
[0007] In a first aspect, the present application provides an image processing method, which adopts the following technical solution:
[0008] An image processing method, comprising:
[0009] Acquire an original scanned image, and perform binarization processing on the original scanned image to obtain a corresponding binary image;
[0010] Performing an image closing operation on the binary image to obtain a corresponding original mask;
[0011] Performing stain recognition on the original scanned image according to a pre-generated semantic segmentation model to obtain a corresponding stain mask;
[0012] Determine a text area in the original mask according to the original mask, and generate a corresponding text mask;
[0013] Determine the clearing area according to the stain mask and the text mask, and generate a corresponding background mask;
[0014] The stains in the binary image or the original scanned image are removed according to the background mask to obtain a corresponding stain-removed image.
[0015] By adopting the above technical solution, the original scanned image is first obtained, and the original scanned image is binarized to obtain the corresponding binary image, and then the binary image is closed to obtain the corresponding original mask, and then the original scanned image is subjected to stain recognition according to the pre-generated semantic segmentation model to obtain the corresponding stain mask, and then the text area in the original mask is determined according to the original mask to generate the corresponding text mask, and then the clearing area is determined according to the stain mask and the text mask to generate the corresponding background mask, and finally the stains in the binary image or the original scanned image are cleared according to the background mask to obtain the corresponding destaining image. Compared with the manual method of clearing stains in the original scanned file, the efficiency of clearing stains is improved, and at the same time, the accuracy of clearing stains is improved, and information loss is less likely to occur, which meets the requirements of modern image processing for speed and quality.
[0016] Optionally, the step of performing an image closing operation on the binary image to obtain a corresponding original mask includes:
[0017] Performing a dilation operation on the binary image to obtain a corresponding dilated image;
[0018] Performing an erosion operation on the dilated image to obtain a corresponding eroded image;
[0019] A corresponding original mask is determined according to the eroded image.
[0020] By adopting the above technical solution, in order to obtain the corresponding original mask, the binary image is first dilated to obtain the corresponding dilated image, and then the dilated image is eroded to obtain the corresponding eroded image, and finally the corresponding original mask is determined according to the eroded image.
[0021] Optionally, the step of determining the text area in the original mask according to the original mask and generating a corresponding text mask includes:
[0022] According to the original mask, an original mask matrix corresponding to the original mask is obtained, and first coordinate data is obtained; the first coordinate data is coordinate data corresponding to a matrix region whose element value in the original mask matrix is 1;
[0023] Determine whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data, and if so, obtain the dimension of the original mask matrix, and create a corresponding first two-dimensional matrix according to the dimension of the original mask matrix; the coordinate data of the first two-dimensional matrix is composed of the first coordinate data and the second coordinate data;
[0024] The element value corresponding to the first coordinate data in the first two-dimensional matrix is set to 1, and the element value corresponding to the second coordinate data in the first two-dimensional matrix is set to 0, to generate a corresponding text mask.
[0025] By adopting the above technical solution, in order to generate a corresponding text mask, first, the original mask matrix corresponding to the original mask is obtained according to the original mask, and the first coordinate data is obtained, the first coordinate data is the coordinate data corresponding to the matrix area whose element value is 1 in the original mask matrix, and then it is judged according to the first coordinate data whether the image area corresponding to the first coordinate data in the original mask is a text area. If the image area corresponding to the first coordinate data in the original mask is a text area, the dimension of the original mask matrix is obtained, and the corresponding first two-dimensional matrix is created according to the dimension of the original mask matrix, and then the element value corresponding to the first coordinate data in the first two-dimensional matrix is set to 1, and the element value corresponding to the second coordinate data in the first two-dimensional matrix is set to 0, so as to generate the corresponding text mask.
[0026] Optionally, the step of judging, according to the first coordinate data, whether the image area corresponding to the first coordinate data in the original mask is a text area includes:
[0027] determining, according to the first coordinate data, whether a longitudinal length of an image area corresponding to the first coordinate data in the original mask is within a preset range;
[0028] If yes, determining that the image area is a text area;
[0029] If not, it is determined that the image area is not a text area.
[0030] By adopting the above technical solution, in order to determine whether the image area is a text area, it is judged according to the first coordinate data whether the vertical length of the image area corresponding to the first coordinate data in the original mask is within a preset range. If the vertical length of the image area corresponding to the first coordinate data is within the preset range, the image area is determined to be a text area. If the vertical length of the image area corresponding to the first coordinate data is not within the preset range, the image area is determined not to be a text area.
[0031] Optionally, the step of determining the clearing area according to the stain mask and the text mask and generating a corresponding background mask includes:
[0032] Acquire a stain mask matrix corresponding to the stain mask according to the stain mask, and acquire a text mask matrix corresponding to the text mask according to the text mask;
[0033] Acquire third coordinate data; the third coordinate data is coordinate data corresponding to a matrix area whose element value in the stain mask matrix is 1 and whose element value in the text mask matrix is 0; the clearing area is a stain area corresponding to the third coordinate data in the binary image or the original scanned image;
[0034] Creating a corresponding second two-dimensional matrix according to the dimension of the original mask matrix; the coordinate data of the second two-dimensional matrix includes third coordinate data and fourth coordinate data;
[0035] The element value corresponding to the third coordinate data in the second two-dimensional matrix is set to 1, and the element value corresponding to the fourth coordinate data in the second two-dimensional matrix is set to 0, to generate a corresponding background mask.
[0036] By adopting the above technical solution, in order to generate a corresponding background mask, a stain mask matrix corresponding to the stain mask is obtained according to the stain mask, and a text mask matrix corresponding to the text mask is obtained according to the text mask, and then the third coordinate data is obtained, the third coordinate data is the coordinate data corresponding to the matrix area whose element value is 1 in the stain mask matrix and whose element value is 0 in the text mask matrix, and then a corresponding second two-dimensional matrix is created according to the dimension of the original mask matrix, the coordinate data of the second two-dimensional matrix includes the third coordinate data and the fourth coordinate data, and then the element value corresponding to the third coordinate data in the second two-dimensional matrix is set to 1, and the element value corresponding to the fourth coordinate data in the second two-dimensional matrix is set to 0, so as to generate the corresponding background mask.
[0037] Optionally, the step of removing stains in the binary image or the original scanned image according to the background mask to obtain a corresponding stain-removed image includes:
[0038] Acquire a background mask matrix corresponding to the background mask according to the background mask, and acquire fifth coordinate data; the fifth coordinate data is coordinate data corresponding to a matrix region whose element value in the background mask matrix is 1;
[0039] The background pixels of the binary image or the original scanned image are obtained, and the element values of the corresponding matrix area in the binary image or the original scanned image are replaced with the background pixels according to the fifth coordinate data to obtain the corresponding decontamination image.
[0040] By adopting the above technical solution, in order to obtain the corresponding decontamination image, the background mask matrix corresponding to the background mask is obtained according to the background mask, and the fifth coordinate data is obtained. The fifth coordinate data is the coordinate data corresponding to the matrix area whose element value is 1 in the background mask matrix, and then the background pixels of the binary image or the original scanned image are obtained, and the element values of the corresponding matrix area in the binary image or the original scanned image are replaced with the background pixels according to the fifth coordinate data to obtain the corresponding decontamination image.
[0041] Optionally, the step of generating the pre-generated semantic segmentation model includes:
[0042] Perform data annotation on stains in the sample image according to the preset semantic segmentation category to obtain the corresponding data annotation image;
[0043] Performing data enhancement operation on the data annotated image to obtain a corresponding model training image;
[0044] Training a pre-selected semantic segmentation model according to the model training data to obtain a pre-trained semantic segmentation model;
[0045] Determine whether the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy. If so, use the pre-trained semantic segmentation model as the pre-generated semantic segmentation model.
[0046] By adopting the above technical scheme, in order to generate a pre-generated semantic segmentation model, data annotation is performed on the stains in the sample image according to the preset semantic segmentation category to obtain the corresponding data annotation image, and then data enhancement operation is performed on the data annotation image to obtain the corresponding model training image, and then the pre-selected semantic segmentation model is trained according to the model training data to obtain the pre-trained semantic segmentation model, and finally it is determined whether the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy. If the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy, the pre-trained semantic segmentation model is used as the pre-generated semantic segmentation model.
[0047] In a second aspect, the present application also provides an image processing system, which adopts the following technical solution:
[0048] An image processing system, comprising:
[0049] A binary image generation module is used to obtain an original scanned image and perform a binarization process on the original scanned image to obtain a corresponding binary image;
[0050] An original mask generation module, used for performing an image closing operation on the binary image to obtain a corresponding original mask;
[0051] A stain mask generation module, used for performing stain recognition on the original scanned image according to a pre-generated semantic segmentation model to obtain a corresponding stain mask;
[0052] A text mask generating module, used for determining the text area in the original mask according to the original mask, and generating a corresponding text mask;
[0053] A background mask generation module, used to determine the clearing area according to the stain mask and the text mask, and generate a corresponding background mask;
[0054] The stain removal module is used to remove stains in the binary image or the original scanned image according to the background mask to obtain a corresponding stain-removed image.
[0055] In a third aspect, the present application also provides a computer device, which adopts the following technical solution:
[0056] A computer device comprises a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method described in the first aspect when executing the computer program.
[0057] In a fourth aspect, the present application further provides a computer-readable storage medium, which adopts the following technical solution:
[0058] A computer-readable storage medium stores a computer program that can be loaded by a processor and execute the method described in the first aspect.
[0059] In summary, the present application includes at least the following beneficial technical effects: firstly, the original scanned image is obtained, and the original scanned image is binarized to obtain the corresponding binary image, and then the binary image is closed to obtain the corresponding original mask, and then the original scanned image is subjected to stain recognition according to the pre-generated semantic segmentation model to obtain the corresponding stain mask, and then the text area in the original mask is determined according to the original mask to generate the corresponding text mask, and then the clearing area is determined according to the stain mask and the text mask to generate the corresponding background mask, and finally the stains in the binary image or the original scanned image are cleared according to the background mask to obtain the corresponding de-stained image. Compared with the manual method of clearing stains in the original scanned file, the efficiency of clearing stains is improved, and at the same time, the accuracy of clearing stains is improved, and information loss is less likely to occur, which meets the requirements of modern image processing for speed and quality. BRIEF DESCRIPTION OF THE DRAWINGS
[0060] Figure 1 It is a schematic diagram of the overall process of an embodiment of the present application.
[0061] Figure 2 It is a schematic diagram of the structure of the system of this application.
[0062] Figure 3 It is a structural block diagram of the computer device of the present application. DETAILED DESCRIPTION
[0063] In order to make the purpose, technical solutions and advantages of this application more clear, the following Figure 1-3 It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0064] The embodiment of the present application discloses an image processing method.
[0065] Reference Figure 1 , an image processing method, comprising:
[0066] Step S11, obtaining an original scanned image, and performing binarization processing on the original scanned image to obtain a corresponding binary image.
[0067] It should be noted that the original scanned file in this embodiment includes scanned images in Tibetan or Tibetan-Chinese mixed format.
[0068] It should be further explained that a binary image is a type of image. A binary image refers to an image with only two colors (usually black and white). Each pixel of a binary image has only two possible values, usually represented as 0 and 1. A binary image is usually represented by a two-dimensional matrix. Each element in the matrix corresponds to a pixel in the image. The value of the element is 0 or 1, 0 represents black, and 1 represents white. The dimension of the matrix corresponds to the resolution of the image, and the number of rows and columns of the matrix corresponds to the height and width of the image, respectively.
[0069] Step S12, performing an image closing operation on the binary image to obtain a corresponding original mask.
[0070] It should be noted that the image closing operation is a morphological image processing operation. The image closing operation first dilates the image and then erodes it. The dilation operation converts the adjacent positions of each pixel in the image into the same pixel, while the erosion operation can make the foreground objects in the image smaller, thereby eliminating small parts and filtering out impurities that are too small. For binary images, the image closing operation targets the image area with a pixel value of 1 in the binary image.
[0071] It should be further explained that the structure of Tibetan is rather special. Specifically, each Tibetan font does not have a fixed size range, so the expansion parameter should be set as large as possible.
[0072] Step S13, performing stain recognition on the original scanned image according to the pre-generated semantic segmentation model to obtain a corresponding stain mask.
[0073] Step S14, determining the text area in the original mask according to the original mask, and generating a corresponding text mask.
[0074] Step S15, determining the clearing area according to the stain mask and the text mask, and generating a corresponding background mask.
[0075] Step S16, removing stains in the binary image or the original scanned image according to the background mask to obtain a corresponding stain-removed image.
[0076] In the above implementation, the original scanned image is first obtained, and the original scanned image is binarized to obtain a corresponding binary image, and then the binary image is closed to obtain a corresponding original mask, and then the original scanned image is subjected to stain recognition according to a pre-generated semantic segmentation model to obtain a corresponding stain mask, and then the text area in the original mask is determined according to the original mask to generate a corresponding text mask, and then the removal area is determined according to the stain mask and the text mask to generate a corresponding background mask, and finally the stains in the binary image or the original scanned image are removed according to the background mask to obtain a corresponding destain image. Compared with the manual removal of stains in the original scanned file, the efficiency of stain removal is improved, and at the same time, the accuracy of stain removal is improved, and information loss is less likely to occur, which meets the requirements of modern image processing for speed and quality.
[0077] As a further implementation of the image processing method, the step of performing an image closing operation on the binary image to obtain a corresponding original mask includes:
[0078] Step S21, performing a dilation operation on the binary image to obtain a corresponding dilated image.
[0079] Step S22, performing an erosion operation on the dilated image to obtain a corresponding eroded image.
[0080] Step S23, determining the corresponding original mask according to the eroded image.
[0081] In the above implementation, in order to obtain the corresponding original mask, the binary image is first dilated to obtain the corresponding dilated image, then the dilated image is eroded to obtain the corresponding eroded image, and finally the corresponding original mask is determined according to the eroded image.
[0082] As a further implementation of the image processing method, the step of determining the text area in the original mask according to the original mask and generating the corresponding text mask includes:
[0083] Step S31, obtaining an original mask matrix corresponding to the original mask according to the original mask, and obtaining first coordinate data.
[0084] The first coordinate data is the coordinate data corresponding to the matrix region whose element value is 1 in the original mask matrix.
[0085] Step S32, judging whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data, if so, obtaining the dimension of the original mask matrix, and creating a corresponding first two-dimensional matrix according to the dimension of the original mask matrix.
[0086] The coordinate data of the first two-dimensional matrix consists of first coordinate data and second coordinate data.
[0087] Specifically, it is determined whether the image area corresponding to the first coordinate data in the original mask is a text area based on the first coordinate data. If the image area corresponding to the first coordinate data in the original mask is a text area, the dimension of the original mask matrix is obtained, and a corresponding first two-dimensional matrix is created based on the dimension of the original mask matrix.
[0088] Step S33, setting the element value corresponding to the first coordinate data in the first two-dimensional matrix to 1, and setting the element value corresponding to the second coordinate data in the first two-dimensional matrix to 0, to generate a corresponding text mask.
[0089] In the above embodiment, in order to generate a corresponding text mask, the original mask matrix corresponding to the original mask is first obtained according to the original mask, and the first coordinate data is obtained, the first coordinate data being the coordinate data corresponding to the matrix area whose element value is 1 in the original mask matrix, and then it is determined whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data. If the image area corresponding to the first coordinate data in the original mask is a text area, the dimension of the original mask matrix is obtained, and a corresponding first two-dimensional matrix is created according to the dimension of the original mask matrix, and then the element value corresponding to the first coordinate data in the first two-dimensional matrix is set to 1, and the element value corresponding to the second coordinate data in the first two-dimensional matrix is set to 0 to generate the corresponding text mask.
[0090] As a further implementation of the image processing method, the step of determining whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data includes:
[0091] Step S41 : judging whether the longitudinal length of the image area corresponding to the first coordinate data in the original mask is within a preset range according to the first coordinate data.
[0092] It is understandable that the overall shape of the image area in step S41 should be close to a rectangle, that is, the longitudinal length is within a preset range, and the lateral length has no definite length range, so there is no restriction on the lateral length of the image area in step S41.
[0093] Step S42: If yes, determine that the image area is a text area.
[0094] Specifically, if the vertical length of the image area corresponding to the first coordinate data is within a preset range, the image area is determined to be a text area.
[0095] Step S43: if not, determine that the image area is not a text area.
[0096] Specifically, if the vertical length of the image area corresponding to the first coordinate data is not within a preset range, it is determined that the image area is not a text area.
[0097] In the above embodiment, in order to determine that the image area is a text area, it is determined whether the vertical length of the image area corresponding to the first coordinate data in the original mask is within a preset range based on the first coordinate data. If the vertical length of the image area corresponding to the first coordinate data is within the preset range, the image area is determined to be a text area. If the vertical length of the image area corresponding to the first coordinate data is not within the preset range, the image area is determined not to be a text area.
[0098] As a further implementation of the image processing method, the step of determining the clearing area according to the stain mask and the text mask and generating the corresponding background mask includes:
[0099] Step S51, obtaining a stain mask matrix corresponding to the stain mask according to the stain mask, and obtaining a text mask matrix corresponding to the text mask according to the text mask.
[0100] Step S52, obtaining third coordinate data.
[0101] The third coordinate data is the coordinate data corresponding to the matrix area whose element value in the stain mask matrix is 1 and whose element value in the text mask matrix is 0. The cleared area is the stain area corresponding to the third coordinate data in the binary image or the original scanned image.
[0102] Step S53: Create a corresponding second two-dimensional matrix according to the dimension of the original mask matrix.
[0103] The coordinate data of the second two-dimensional matrix includes third coordinate data and fourth coordinate data.
[0104] Step S54, setting the element value corresponding to the third coordinate data in the second two-dimensional matrix to 1, and setting the element value corresponding to the fourth coordinate data in the second two-dimensional matrix to 0, to generate a corresponding background mask.
[0105] It should be noted that, in step S51 to step S54, for each coordinate in the stain mask matrix, when the element value of the coordinate in the stain mask matrix is 1, and the element value of the coordinate in the text mask matrix is 0, it means that the coordinate is a stain position or stain area that needs to be removed, and the element value corresponding to the coordinate in the second two-dimensional matrix is defined as 1; when the element value of the coordinate in the stain mask matrix is 1, and the element value of the coordinate in the text mask matrix is 1, it means that the text of the coordinate coincides with the stain, and the text should be retained, and the element value of the coordinate in the second two-dimensional matrix is defined as 0; when the element value of the coordinate in the stain mask matrix is 0, and the element value of the coordinate in the text mask matrix is either 1 or 0, there is no stain at the coordinate, and the element value of the coordinate in the second two-dimensional matrix is defined as 0;
[0106] In the above embodiment, in order to generate a corresponding background mask, a stain mask matrix corresponding to the stain mask is obtained according to the stain mask, and a text mask matrix corresponding to the text mask is obtained according to the text mask, and then the third coordinate data is obtained, the third coordinate data is the coordinate data corresponding to the matrix area whose element value is 1 in the stain mask matrix and whose element value is 0 in the text mask matrix, and then a corresponding second two-dimensional matrix is created according to the dimension of the original mask matrix, the coordinate data of the second two-dimensional matrix includes the third coordinate data and the fourth coordinate data, and then the element value corresponding to the third coordinate data in the second two-dimensional matrix is set to 1, and the element value corresponding to the fourth coordinate data in the second two-dimensional matrix is set to 0, so as to generate the corresponding background mask.
[0107] As a further implementation of the image processing method, the step of removing stains in the binary image or the original scanned image according to the background mask to obtain the corresponding stain-removed image includes:
[0108] Step S61, obtaining a background mask matrix corresponding to the background mask according to the background mask, and obtaining fifth coordinate data. The fifth coordinate data is the coordinate data corresponding to the matrix area whose element value is 1 in the background mask matrix.
[0109] Step S62, obtaining background pixels of the binary image or the original scanned image, and replacing element values of the corresponding matrix area in the binary image or the original scanned image with the background pixels according to the fifth coordinate data, to obtain a corresponding decontamination image.
[0110] It should be noted that the background pixels of the background pixels in the binary image or the original scanned image represent the pixel values corresponding to the background pixels; for the coordinates whose element values corresponding to the background mask matrix are 1 (specifically the fifth coordinate data), the element values corresponding to the coordinates in the binary image or the original scanned image are replaced with the background pixels; the background pixels of the original scanned image are usually 255.
[0111] In the above embodiment, in order to obtain the corresponding stain-removed image, the background mask matrix corresponding to the background mask is obtained according to the background mask, and the fifth coordinate data is obtained, the fifth coordinate data is the coordinate data corresponding to the matrix area whose element value is 1 in the background mask matrix, and then the background pixels of the binary image or the original scanned image are obtained, and the element values of the corresponding matrix area in the binary image or the original scanned image are replaced with the background pixels according to the fifth coordinate data to obtain the corresponding stain-removed image.
[0112] As a further implementation of the image processing method, the step of generating the pre-generated semantic segmentation model includes:
[0113] Step S71 , data annotation is performed on the stains in the sample image according to the preset semantic segmentation category to obtain a corresponding data annotation image.
[0114] It should be noted that the pre-set semantic segmentation categories include stains and backgrounds, and the background can be set as the default category.
[0115] It should be further explained that, when labeling, only the stains can be labeled, and the background does not need additional labeling. The specific labeling method is to label according to the stain outline, create a two-dimensional matrix of the same dimension as the original scanned image, and define the value of the pixel within the stain outline in the original scanned image corresponding to the position in the two-dimensional matrix as 1, and the rest as 0, to form a labeling mask. The labeling mask is stored in the form of a file as a label for the image.
[0116] Step S72, performing data enhancement operation on the data annotated image to obtain a corresponding model training image.
[0117] It is understandable that data augmentation expands the number of images through image processing, and the expansion methods include but are not limited to image rotation, flipping, blurring, etc.; the expansion method usually cannot use methods such as adding noise, because the form of noise is similar to stains and will affect the model performance.
[0118] Step S73, training the pre-selected semantic segmentation model according to the model training data to obtain a pre-trained semantic segmentation model.
[0119] It should be noted that the pre-selected semantic segmentation model can be a Unet model, but it is not limited to this model. Other semantic segmentation models such as DeepLab, SegNet, etc. can also be used. The Unet model is a model with an encoder-decoder structure, which includes an encoder, a decoder, and an output layer. The encoder part uses a combination of convolutional layers and pooling layers to downsample the feature map and extract high-level image features. The decoder part uses a combination of upsampling layers and convolutional layers to restore the image resolution, and splices the feature map with the corresponding encoder layer at each upsampling step to fuse the image features. The output layer is a convolutional layer that generates the final segmentation result.
[0120] It should be further explained that transfer learning and freeze / thaw training are used in the training process. Due to the limited available data sets, transfer learning can greatly improve the accuracy of the final model. Specifically, it refers to training based on the existing model. We use the Pascal VOC2012 natural image binary data set as the basis for transfer learning. The total number of training rounds is determined according to the size of the model training data. The first two-thirds of the rounds are frozen training, which specifically refers to fixing the weights of the encoder part of the model during training. This part of the weight does not participate in the training update to prevent the data set from having too much influence on the weights of the model feature extraction part, resulting in the loss of the original feature extraction capability. Unfreeze training is performed in the remaining one-third of the rounds to adjust the overall weights. A smaller learning rate is set for the encoder part, and a larger learning rate is set for the other parts. The learning rate will affect the magnitude of the weight change.
[0121] Step S74, determining whether the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy, and if so, using the pre-trained semantic segmentation model as the pre-generated semantic segmentation model.
[0122] Specifically, determine whether the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy. If the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy, the pre-trained semantic segmentation model is used as the pre-generated semantic segmentation model. If the model accuracy corresponding to the pre-trained semantic segmentation model does not meet the preset accuracy, restart execution from step S71.
[0123] It should be noted that the optimization algorithm used by the optimizer during the training process is stochastic gradient descent. Stochastic gradient descent is a common optimization algorithm. Since it only needs to calculate the gradient of a small batch of samples in each iteration, it has the characteristics of high computational efficiency. Specifically, in each iteration, its update formula is:
[0124]
[0125] in the formula is the parameter at the tth iteration, is the learning rate, The loss function is The gradient when , where the gradient refers to the direction and magnitude of the rate of change of the function at a certain point, that is, the direction and magnitude of parameter optimization.
[0126] In particular, the cross entropy loss function is used as the loss function during training. The specific formula is:
[0127]
[0128] Where N is the number of samples contained in each batch. is the label data, i.e. the annotation mask, For inference data.
[0129] In the above embodiment, in order to generate a pre-generated semantic segmentation model, data annotation is performed on the stains in the sample image according to the preset semantic segmentation category to obtain the corresponding data annotation image, and then data enhancement operation is performed on the data annotation image to obtain the corresponding model training image, and then the pre-selected semantic segmentation model is trained according to the model training data to obtain the pre-trained semantic segmentation model. Finally, it is determined whether the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy. If the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy, the pre-trained semantic segmentation model is used as the pre-generated semantic segmentation model.
[0130] The embodiment of the present application also discloses an image processing system.
[0131] refer to Figure 2 , an image processing system, comprising:
[0132] A binary image generation module is used to obtain an original scanned image and perform a binarization process on the original scanned image to obtain a corresponding binary image;
[0133] The original mask generation module is used to perform image closing operation on the binary image to obtain the corresponding original mask;
[0134] A stain mask generation module is used to identify stains on the original scanned image according to a pre-generated semantic segmentation model to obtain a corresponding stain mask;
[0135] A text mask generation module, used to determine the text area in the original mask according to the original mask and generate a corresponding text mask;
[0136] A background mask generation module is used to determine the clearing area according to the stain mask and the text mask and generate a corresponding background mask;
[0137] The stain removal module is used to remove stains in the binary image or the original scanned image according to the background mask to obtain the corresponding stain-removed image.
[0138] An image processing system of the present invention can implement any one of the image processing methods, and the specific working process of the image processing system of the present invention can refer to the corresponding process in the above-mentioned image processing method.
[0139] The embodiment of the present application also discloses a computer device.
[0140] refer to Figure 3 A computer device includes a memory and a processor, wherein the memory stores a computer program that can be run on the processor, and when the processor executes the computer program, any one of the above-mentioned image processing methods is implemented.
[0141] The embodiment of the present application also discloses a computer-readable storage medium.
[0142] A computer-readable storage medium stores a computer program that can be loaded by a processor and execute any one of the above-mentioned image processing methods.
[0143] Among them, computer-readable storage media can be any tangible medium that contains or stores a program, which can be used by or in conjunction with an instruction execution system, apparatus or device; the program code contained on the computer-readable medium can be transmitted using any appropriate medium, including but not limited to wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0144] The above are all preferred embodiments of the present application, and are not intended to limit the protection scope of the present application. Any feature disclosed in this specification (including the abstract and drawings), unless otherwise stated, can be replaced by other equivalent or alternative features with similar purposes. That is, unless otherwise stated, each feature is only an example of a series of equivalent or similar features.
Claims
1. An image processing method, characterized in that: include: Acquire an original scanned image, and perform binarization processing on the original scanned image to obtain a corresponding binary image; Performing an image closing operation on the binary image to obtain a corresponding original mask; Performing stain recognition on the original scanned image according to a pre-generated semantic segmentation model to obtain a corresponding stain mask; Determine a text area in the original mask according to the original mask, and generate a corresponding text mask; Determine the clearing area according to the stain mask and the text mask, and generate a corresponding background mask; Remove stains in the binary image or the original scanned image according to the background mask to obtain a corresponding stain-removed image; The step of determining the text area in the original mask according to the original mask and generating a corresponding text mask comprises: According to the original mask, an original mask matrix corresponding to the original mask is obtained, and first coordinate data is obtained; the first coordinate data is coordinate data corresponding to a matrix region whose element value in the original mask matrix is 1; Determine whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data, and if so, obtain the dimension of the original mask matrix, and create a corresponding first two-dimensional matrix according to the dimension of the original mask matrix; the coordinate data of the first two-dimensional matrix is composed of the first coordinate data and the second coordinate data; Setting the element value corresponding to the first coordinate data in the first two-dimensional matrix to 1, and setting the element value corresponding to the second coordinate data in the first two-dimensional matrix to 0, to generate a corresponding text mask; The step of judging whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data includes: determining, according to the first coordinate data, whether a longitudinal length of an image area corresponding to the first coordinate data in the original mask is within a preset range; If yes, determining that the image area is a text area; If not, it is determined that the image area is not a text area.
2. An image processing method according to claim 1, characterized in that: The step of performing an image closing operation on the binary image to obtain a corresponding original mask comprises: Performing a dilation operation on the binary image to obtain a corresponding dilated image; Performing an erosion operation on the dilated image to obtain a corresponding eroded image; A corresponding original mask is determined according to the eroded image.
3. An image processing method according to claim 1, characterized in that: The step of determining the clearing area according to the stain mask and the text mask and generating a corresponding background mask comprises: Acquire a stain mask matrix corresponding to the stain mask according to the stain mask, and acquire a text mask matrix corresponding to the text mask according to the text mask; Acquire third coordinate data; the third coordinate data is coordinate data corresponding to a matrix area whose element value in the stain mask matrix is 1 and whose element value in the text mask matrix is 0; the clearing area is a stain area corresponding to the third coordinate data in the binary image or the original scanned image; Creating a corresponding second two-dimensional matrix according to the dimension of the original mask matrix; the coordinate data of the second two-dimensional matrix includes third coordinate data and fourth coordinate data; The element value corresponding to the third coordinate data in the second two-dimensional matrix is set to 1, and the element value corresponding to the fourth coordinate data in the second two-dimensional matrix is set to 0, to generate a corresponding background mask.
4. The image processing method according to claim 1, characterized in that: The step of removing stains in the binary image or the original scanned image according to the background mask to obtain a corresponding stain-removed image comprises: Acquire a background mask matrix corresponding to the background mask according to the background mask, and acquire fifth coordinate data; the fifth coordinate data is coordinate data corresponding to a matrix region whose element value in the background mask matrix is 1; The background pixels of the binary image or the original scanned image are obtained, and the element values of the corresponding matrix area in the binary image or the original scanned image are replaced with the background pixels according to the fifth coordinate data to obtain the corresponding decontamination image.
5. The image processing method according to claim 1, characterized in that: The step of generating the pre-generated semantic segmentation model comprises: Perform data annotation on stains in the sample image according to the preset semantic segmentation category to obtain the corresponding data annotation image; Performing data enhancement operation on the data annotated image to obtain a corresponding model training image; Training a pre-selected semantic segmentation model according to the model training data to obtain a pre-trained semantic segmentation model; Determine whether the model accuracy corresponding to the pre-trained semantic segmentation model meets the preset accuracy. If so, use the pre-trained semantic segmentation model as the pre-generated semantic segmentation model.
6. An image processing system, characterized in that: include: A binary image generation module is used to obtain an original scanned image and perform a binarization process on the original scanned image to obtain a corresponding binary image; An original mask generation module, used for performing an image closing operation on the binary image to obtain a corresponding original mask; A stain mask generation module, used for performing stain recognition on the original scanned image according to a pre-generated semantic segmentation model to obtain a corresponding stain mask; A text mask generating module, used for determining the text area in the original mask according to the original mask, and generating a corresponding text mask; A background mask generation module, used to determine the clearing area according to the stain mask and the text mask, and generate a corresponding background mask; A stain removal module, used for removing stains in the binary image or the original scanned image according to the background mask to obtain a corresponding stain-removed image; The step of determining the text area in the original mask according to the original mask and generating a corresponding text mask comprises: According to the original mask, an original mask matrix corresponding to the original mask is obtained, and first coordinate data is obtained; the first coordinate data is coordinate data corresponding to a matrix region whose element value in the original mask matrix is 1; Determine whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data, and if so, obtain the dimension of the original mask matrix, and create a corresponding first two-dimensional matrix according to the dimension of the original mask matrix; the coordinate data of the first two-dimensional matrix is composed of the first coordinate data and the second coordinate data; Setting the element value corresponding to the first coordinate data in the first two-dimensional matrix to 1, and setting the element value corresponding to the second coordinate data in the first two-dimensional matrix to 0, to generate a corresponding text mask; The step of judging whether the image area corresponding to the first coordinate data in the original mask is a text area according to the first coordinate data includes: determining, according to the first coordinate data, whether a longitudinal length of an image area corresponding to the first coordinate data in the original mask is within a preset range; If yes, determining that the image area is a text area; If not, it is determined that the image area is not a text area.
7. A computer device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program executable on the processor, and the processor implements the method according to any one of claims 1 to 5 when executing the computer program.
8. A computer-readable storage medium, characterized in that: A computer program is stored which can be loaded by a processor and execute the method according to any one of claims 1 to 5.
Citation Information
Patent Citations
Image optimization method based on image processing and related device
CN111739013A
Industrial flaw detection method and device, storage medium and electronic equipment
CN116245788A