A video restoration method and device, electronic equipment and storage medium
By combining scratch detection and repair models, and utilizing multi-frame image detection and dilation technology, the problem of unsatisfactory scratch repair effects in video images has been solved, achieving efficient scratch repair while maintaining the original texture of the image.
Patent Information
- Application Number
- CN202311508439.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-13
- Publication Date
- 2026-11-27
- Estimated Expiration
- 2043-11-13
AI Technical Summary
Existing technologies are not ideal for scratch repair in video images, especially for high-resolution videos and scenes with large movements. Furthermore, deep learning methods tend to lose the original graininess of the image.
This paper adopts a method combining scratch detection and scratch repair models. It detects and repairs scratches by using multiple consecutive images, uses a scratch mask to dilate the image to fully cover the scratch area, and combines the content of the reference image for repair to avoid modifying other areas of the image. A deep neural network is used for video repair.
It improves scratch repair performance, preserves image graininess to the greatest extent, and increases repair efficiency, making it suitable for video repair in high-resolution and high-motion scenes.
Smart Images

Figure CN117670730B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of image restoration technology, and in particular to a video restoration method, apparatus, electronic device, and storage medium. Background Technology
[0002] Due to poor storage conditions and wear and tear during projection, old film reels often have mold and scratches, causing flickering images with visible scratches during playback, severely impacting the viewing experience. Now, with mature film digitization technology, old film reels can be scanned into digital videos using methods such as film-to-digital or magnetic-to-digital conversion, providing the necessary conditions for digitally restoring scratches on older videos.
[0003] However, videos typically contain a large number of frames, making manual scratch repair time-consuming and labor-intensive. While deep learning methods for end-to-end scratch removal often result in the loss of image detail and the original graininess, leading to less than ideal scratch repair results.
[0004] Therefore, it is necessary to develop a video restoration method, apparatus, electronic device, and storage medium to improve the restoration effect of scratches in video images. Summary of the Invention
[0005] In view of the above problems, embodiments of this application provide a video restoration method, apparatus, electronic device, and storage medium to overcome or at least partially solve the above problems.
[0006] A first aspect of this application provides a video restoration method, including:
[0007] Acquire multiple consecutive frames of images from a target video, wherein the multiple consecutive frames include the target image;
[0008] The target image is scratched using a scratch detection model to obtain a scratch mask for the target image. The scratch mask is used to indicate the location of the scratches in the target image.
[0009] The scratch mask of the multi-frame continuous images and the target image is input into the scratch repair model to repair the scratch location of the target image, and the final repair result is obtained.
[0010] In one optional implementation, the step of using a scratch detection model to detect scratches on the target image and obtaining a scratch mask for the target image includes:
[0011] The pixels of the multiple consecutive images are reduced according to a first magnification ratio to obtain multiple first consecutive images; wherein the first magnification ratio is less than or equal to a preset magnification ratio;
[0012] The first consecutive images of the multiple frames are input into the scratch detection model for scratch detection to obtain the scratch mask of the target image;
[0013] The step involves inputting the scratch mask of the multiple consecutive images and the target image into the scratch repair model to repair the scratch location in the target image, thereby obtaining the final repair result, including:
[0014] The pixels of the multi-frame continuous images are reduced according to the second magnification to obtain multi-frame second continuous images;
[0015] The scratch mask of the multi-frame second consecutive image and the target image is input into the scratch repair model to repair the scratch location of the target image, thereby obtaining the final repair result.
[0016] In one optional implementation, the step of inputting the scratch mask of the multiple frames of the second consecutive images and the target image into the scratch repair model to repair the scratch location in the target image and obtain the final repair result includes:
[0017] Using the scratch mask, obtain the reference image content in the multi-frame second consecutive image, where the reference image content is the image content corresponding to the location of the scratch in the multi-frame second consecutive image;
[0018] A first scratch repair image is obtained based on the content of the reference image and the image texture information around the scratch in the target image;
[0019] The pixels of the first scratch repair image are magnified according to the second magnification to obtain the second scratch repair image;
[0020] Using the scratch mask, obtain the repair image content in the second scratch repair image, wherein the repair image content is the image content corresponding to the location of the scratch in the scratch repair image;
[0021] The repaired image content is pasted back into the target image to obtain the final repair result.
[0022] In one optional implementation, pasting the repaired image content back into the target image to obtain the final repair result includes:
[0023] The final repair result is obtained by replacing the image content at the location of the scratch in the target image with the content of the repaired image using the following formula:
[0024]
[0025] Among them, img_res n+1 For the final repair result, img n+1 For the target image, img_pred n+1 The second scratch repair image is defined as follows: `mask` is the scratch mask, a binary image constructed from 0s and 255s, where a pixel value of 255 represents a scratch at that location. This refers to the image content of the non-scratched area in the target image. This refers to the content of the image being repaired.
[0026] In an optional implementation, the method further includes:
[0027] In the event of a repair error in the final repair result, the model causing the repair error is located from the scratch detection model and the scratch repair model based on the scratch mask and the final repair result.
[0028] The model parameters of the model that caused the repair error were adjusted.
[0029] In an optional implementation, after inputting the multi-frame continuous images into the scratch detection model to obtain the scratch mask of the target image, the method further includes:
[0030] The image at the location of the scratch indicated by the scratch mask is dilated to obtain the dilated scratch mask;
[0031] The step involves inputting the scratch mask of the multiple consecutive images and the target image into the scratch repair model to repair the scratch location in the target image, thereby obtaining the final repair result, including:
[0032] The multi-frame continuous images and the dilated scratch mask are input into the scratch repair model to repair the scratch location in the target image, thus obtaining the final repair result.
[0033] In one optional implementation, the method further includes:
[0034] Each frame of the target video is used sequentially as the target image for video scratch repair.
[0035] During the process of video scratch repair of the target video, while using the scratch detection model to detect scratches in the current frame image, the scratch repair model is used to repair the scratches in the previous frame image.
[0036] In one alternative implementation, the scratch detection model is trained according to the following steps:
[0037] Select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images, the n+1th frame of the 2n+1 consecutive frames of images is the target image of the sample, and the shape and position of the scratch in the target image of the sample are determined as the label of the training sample;
[0038] The training samples and their labels are input into the initial model to obtain the output of the initial model, which represents the scratch mask of the target image of the sample predicted by the initial model.
[0039] Based on the output, a loss function is calculated to obtain a loss function value, and the parameters of the initial model are adjusted based on the loss function value; the loss function value represents the magnitude of the difference between the output and the labels of the training samples.
[0040] Repeat the above steps until the loss function converges, then end the training to obtain the scratch detection model.
[0041] In one alternative implementation, the scratch repair model is trained through the following steps:
[0042] Select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images and a sample scratch mask, the n+1th frame of the 2n+1 consecutive frames of images is the sample target image, the sample scratch mask is used to indicate the location of the scratch in the sample target image, and the original image content of the sample target image is used as the label of the training sample.
[0043] The training samples and their labels are input into the initial model to obtain the output of the initial model. The output represents the repaired image obtained by the initial model after repairing the scratch location of the target image of the sample.
[0044] Based on the output, a loss function is calculated to obtain a loss function value, and the parameters of the initial model are adjusted based on the loss function value; the loss function value represents the magnitude of the difference between the output and the labels of the training samples.
[0045] Repeat the above steps until the loss function converges, then end the training to obtain the scratch repair model.
[0046] A second aspect of this application also provides a video restoration apparatus, the apparatus comprising:
[0047] The image acquisition module is used to acquire multiple consecutive frames of images of the target video, wherein the multiple consecutive frames include the target image;
[0048] The scratch detection module is used to perform scratch detection on the target image using a scratch detection model to obtain a scratch mask of the target image, and the scratch mask is used to indicate the location of the scratch in the target image.
[0049] The scratch repair module is used to input the scratch mask of the multi-frame continuous images and the target image into the scratch repair model, repair the scratch location of the target image, and obtain the final repair result.
[0050] In one optional implementation, the scratch detection module includes:
[0051] The first reduction submodule is used to reduce the pixels of the multi-frame continuous images according to a first magnification ratio to obtain a multi-frame first continuous image; wherein the first magnification ratio is less than or equal to a preset magnification ratio;
[0052] The first input submodule is used to input the multiple frames of the first consecutive images into the scratch detection model for scratch detection, and obtain the scratch mask of the target image;
[0053] The scratch repair module includes:
[0054] The second reduction submodule is used to reduce the pixels of the multi-frame continuous image according to the second magnification rate to obtain the multi-frame second continuous image;
[0055] The second input submodule is used to input the scratch mask of the multi-frame second consecutive image and the target image into the scratch repair model, repair the scratch location of the target image, and obtain the final repair result.
[0056] In one optional implementation, the second input submodule includes:
[0057] The reference image content determination unit is used to obtain the reference image content in the multi-frame second consecutive image using the scratch mask, wherein the reference image content is the image content corresponding to the location of the scratch in the multi-frame second consecutive image;
[0058] The first scratch repair image generation unit is used to obtain a first scratch repair image based on the content of the reference image and the image texture information around the scratch in the target image;
[0059] The second scratch repair image generation unit is used to enlarge the pixels of the first scratch repair image according to the second magnification to obtain the second scratch repair image;
[0060] The image content acquisition unit is used to acquire the repaired image content in the second scratch repair image using the scratch mask, wherein the repaired image content is the image content corresponding to the location of the scratch in the scratch repair image;
[0061] The final repair result acquisition unit is used to paste the repaired image content back into the target image to obtain the final repair result.
[0062] In one optional implementation, the final repair result acquisition unit includes:
[0063] The replacement subunit is used to replace the image content at the location of the scratch in the target image with the content of the repaired image according to the following formula, to obtain the final repair result:
[0064]
[0065] Among them, img_res n+1 For the final repair result, img n+1 For the target image, img_pred n+1 The second scratch repair image is defined as follows: `mask` is the scratch mask, a binary image constructed from 0s and 255s, where a pixel value of 255 represents a scratch at that location. This refers to the image content of the non-scratched area in the target image. This refers to the content of the image being repaired.
[0066] In one alternative embodiment, the device further includes:
[0067] The positioning module is used to locate the model that caused the repair error from the scratch detection model and the scratch repair model, based on the scratch mask and the final repair result, when a repair error occurs in the final repair result.
[0068] The adjustment module is used to adjust the model parameters of the model that caused the repair error.
[0069] In one alternative embodiment, the device further includes:
[0070] The image dilation module is used to dilate the image at the location of the scratch indicated by the scratch mask after inputting the multi-frame continuous images into the scratch detection model to obtain the scratch mask of the target image, so as to obtain the dilated scratch mask.
[0071] The scratch repair module is further used to input the multi-frame continuous images and the inflated scratch mask into the scratch repair model to repair the scratch location of the target image and obtain the final repair result.
[0072] In one alternative embodiment, the device further includes:
[0073] The video scratch repair module is used to sequentially use each frame of the target video as the target image to repair video scratches.
[0074] During the process of video scratch repair of the target video, while using the scratch detection model to detect scratches in the current frame image, the scratch repair model is used to repair the scratches in the previous frame image.
[0075] In one optional embodiment, the apparatus further includes: a scratch detection model training module for training the scratch detection model; the scratch detection model training module includes:
[0076] The first sample selection submodule is used to select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images, the n+1th frame of the 2n+1 consecutive frames of images is the target image of the sample, and the shape and position of the scratch in the target image of the sample are determined as the label of the training sample;
[0077] The first calculation submodule is used to input the training samples and the labels of the training samples into the initial model to obtain the output result of the initial model, wherein the output result represents the scratch mask of the target image of the sample predicted by the initial model;
[0078] The first loss function calculation submodule is used to calculate the loss function based on the output result, obtain the loss function value, and adjust the parameters of the initial model based on the loss function value; the loss function value represents the magnitude of the difference between the output result and the label of the training sample;
[0079] The first repeating submodule is used to repeatedly run the first sample selection submodule, the first calculation submodule, and the first loss function calculation submodule until the loss function converges, thereby ending the training and obtaining the scratch detection model.
[0080] In one optional embodiment, the apparatus further includes: a scratch repair model training module for training the scratch repair model; the scratch repair model training module includes:
[0081] The second sample selection submodule is used to select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images and a sample scratch mask, the n+1th frame of the 2n+1 consecutive frames of images is the sample target image, the sample scratch mask is used to indicate the location of the scratch in the sample target image, and the original image content of the sample target image is used as the label of the training sample;
[0082] The second calculation submodule is used to input the training samples and the labels of the training samples into the initial model to obtain the output result of the initial model. The output result represents the repaired image obtained by the initial model after repairing the scratch location of the target image of the sample.
[0083] The second loss function calculation submodule is used to calculate the loss function based on the output result, obtain the loss function value, and adjust the parameters of the initial model based on the loss function value; the loss function value represents the magnitude of the difference between the output result and the label of the training sample;
[0084] The second repetition submodule is used to repeatedly run the second sample selection submodule, the second calculation submodule, and the second loss function calculation submodule until the loss function converges, thereby ending the training and obtaining the scratch repair model.
[0085] A third aspect of this application also provides an electronic device, including a memory, a processor, and a computer program stored in the memory, wherein the processor executes the computer program to implement the steps in the video restoration method described in the first aspect of this application.
[0086] A fourth aspect of this application also provides a computer-readable storage medium having a computer program / instructions stored thereon, which, when executed by a processor, implements the steps in the video restoration method described in the first aspect of this application.
[0087] The fifth aspect of this application also provides a computer program product that, when run on an electronic device, causes a processor to execute the steps in the video restoration method described in the first aspect of this application.
[0088] This application provides a video restoration method, apparatus, electronic device, and storage medium. The method involves: acquiring multiple consecutive frames of a target video, wherein the multiple consecutive frames include the target image; performing scratch detection on the target image using a scratch detection model to obtain a scratch mask for the target image, the scratch mask indicating the location of scratches in the target image; inputting the multiple consecutive frames and the scratch mask of the target image into a scratch restoration model to restore the scratch locations in the target image, thereby obtaining a final restoration result. This application, on one hand, first determines the location of scratches in the target image, and then restores those locations, thus avoiding modifications to other areas of the image, preserving the graininess of the image to the greatest extent, and improving the scratch restoration effect. On the other hand, by utilizing the scratch detection model and the scratch restoration model, the scratch detection and scratch restoration are decoupled and do not interfere with each other, making the entire restoration process clearer and improving scratch restoration efficiency. Attached Figure Description
[0089] To more clearly illustrate the technical solutions of the embodiments of this application, the drawings used in the description of the embodiments of this application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0090] Figure 1 This is a flowchart illustrating the steps of a video restoration method provided in an embodiment of this application;
[0091] Figure 2 This is a schematic diagram of a scratch mask output by a scratch detection model provided in an embodiment of this application;
[0092] Figure 3 This is a schematic diagram of a scratch mask after image dilation provided in an embodiment of this application;
[0093] Figure 4 This is a schematic diagram of a scratch repair process provided in an embodiment of this application;
[0094] Figure 5 This is a schematic diagram of the structure of a video restoration device provided in an embodiment of this application;
[0095] Figure 6 This is a schematic diagram of an electronic device provided in an embodiment of this application. Detailed Implementation
[0096] Exemplary embodiments of this application will now be described in more detail with reference to the accompanying drawings. While exemplary embodiments of this application are shown in the drawings, it should be understood that this application may be implemented in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided to enable a more thorough understanding of this application and to fully convey the scope of this application to those skilled in the art.
[0097] In the past, many film reels suffered from poor storage conditions and wear and tear during projection, resulting in mold and scratches on the film. This caused flickering and scratches on the screen during playback, severely impacting the viewing experience. With the advancement of film digitization technology, old film reels can be scanned into digital videos using methods such as film-to-digital or magnetic-to-digital conversion, providing the necessary conditions for the digital restoration of scratches on older videos.
[0098] However, a typical movie is 90-120 minutes long, containing hundreds of thousands of frames. Traditional manual restoration methods require film restorers to repair scratches and mold spots frame by frame, a process that usually requires dozens of people and two to three months to complete, making it time-consuming and labor-intensive. Most existing video scratch removal solutions employ deep learning methods for end-to-end scratch removal processing. That is, given a set of scratched images as input, the model outputs the scratch-removed results for that set of images. These methods mostly utilize optical flow and preceding / following frames to repair scratches in the current image. However, when there is significant motion in the preceding and following frames, the accuracy of optical flow drops drastically. It is difficult to obtain accurate repair results for scratches in fast-moving scenes in movies (such as fight scenes). Furthermore, high-resolution videos (such as older 4K movies) have excessively high computational resource requirements, consuming a large amount of video memory, making these methods unsuitable for handling scenes with large movements and high-resolution videos. Additionally, these end-to-end scratch removal methods often cause wear and tear on image details, losing the original "graininess" of the image. The background of older film often contains a lot of grainy noise, which is a unique texture of old movies. When using deep learning methods to restore images, the restoration is often performed on the entire image, which can easily damage the original texture of the image and make it difficult to achieve the desired restoration effect.
[0099] In view of the above problems, this application proposes a video restoration method to solve the problems of unsatisfactory scratch restoration effects in video images. The video restoration method provided by this application will be described in detail below with reference to the accompanying drawings and through some embodiments and application scenarios.
[0100] The first aspect of this application provides a video restoration method, referring to... Figure 1 , Figure 1 A flowchart illustrating the steps of a video restoration method provided in this application embodiment is shown below. Figure 1 As shown, the method includes:
[0101] Step S101: Obtain multiple consecutive frames of the target video, wherein the multiple consecutive frames include the target image.
[0102] The term "multi-frame continuous image" refers to multiple frames of images obtained by capturing a target video in a certain order. These frames can be extracted from a video and arranged sequentially in playback order. The multi-frame continuous image includes the target image to be repaired. In practice, the target image to be repaired (e.g., frame 510 in the video) can be identified first. Then, based on the position of the target image, several consecutive frames (e.g., frames 509 and 511 in the video) are obtained and defined as the multi-frame continuous image. Optionally, the multi-frame continuous image is a series of 2n+1 frames, where the (n+1)th frame is the target image, and n is a constant greater than or equal to 1. For example, for the target image, the first two frames and the last two frames can be selected to form five consecutive frames as the multi-frame continuous image.
[0103] Furthermore, the present application provides a scratch repair method. It should be noted that the scratch repair method proposed in the present application is also applicable to the repair of mold spots, creases or other damage in images.
[0104] Step S102: Scratch detection is performed on the target image using a scratch detection model to obtain a scratch mask for the target image. The scratch mask is used to indicate the location of the scratches in the target image.
[0105] A scratch mask is used to indicate the location of scratches in a target image. It is a mask that carries the shape of the scratch and can display the image content at the location of the scratch, while covering the image content of the target image other than the scratch.
[0106] In practical implementation, multiple consecutive image frames can be input into the scratch detection model simultaneously. The scratch detection model processes and calculates the scratches in the target image, outputting a scratch mask. In this process, the scratch detection model is essentially an image segmentation model used to automatically locate scratches in the image. In this embodiment, the scratch detection model can be any deep neural network capable of processing inter-frame information and equipped with an inter-frame information fusion module, such as Video Restoration with Enhanced Deformable Convolutional Networks (EDVR), 3D image segmentation models (3D-Unet), etc. This embodiment does not impose restrictions on the specific architecture of the model.
[0107] In one alternative implementation, the scratch detection model is trained according to the following steps:
[0108] Step S201: Select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images, the n+1th frame of the 2n+1 consecutive frames of images is the target image of the sample, and the shape and position of the scratch in the target image of the sample are determined as the label of the training sample;
[0109] Step S202: Input the training samples and the labels of the training samples into the initial model to obtain the output result of the initial model. The output result represents the scratch mask of the target image of the sample predicted by the initial model.
[0110] Step S203: Calculate the loss function based on the output result to obtain the loss function value, and adjust the parameters of the initial model based on the loss function value; the loss function value represents the magnitude of the difference between the output result and the labels of the training samples.
[0111] Step S204: Repeat the above steps (steps S201-S203) until the loss function converges, end the training, and obtain the scratch detection model.
[0112] In this embodiment, the scratch detection model can be pre-trained using a large dataset of training samples, enabling the model to become familiar with the shapes of various scratches. Specifically, a set of 2n+1 consecutive frames is used as a training sample, and the (n+1)th frame is designated as the target image. Scratches of different shapes, similar to real scratches, are artificially constructed on this target image. The shape and location of the scratches in this image are used as the label of the training sample. This training sample and its label are input into the initial model, allowing the model to learn and become familiar with the shapes of real scratches. The model then predicts the location and shape of the scratches in the (n+1)th frame (target image) of this training sample, outputting the corresponding scratch mask. Based on this output (scratch mask), a loss function is calculated, and the model parameters are adjusted accordingly. This loss function value represents the magnitude of the difference between the output result and the label of the training sample. If the difference between the output result (the model-predicted location and shape of the scratches) and the label is large, the loss function value is larger. By repeating the above steps, the model is trained multiple times using training samples and labels, gradually decreasing the loss function value (as the similarity between the model's output and the labels gradually increases) until the loss function value stabilizes, at which point training ends, resulting in the scratch detection model. Thus, by utilizing a large training sample dataset, the scratch detection model becomes familiar with the shape of scratches.
[0113] Generally, in a multi-frame continuous image containing a real scratch, the shape and location of the scratch are not identical across the frames. For example, in a typical video, the image changes continuously within the same shot, with minimal differences between adjacent frames. If an object appears in frame t but not in frames t-1 and t+1, the object in frame t can be considered a scratch. Based on this, scratch detection models can determine scratch locations by comparing abrupt changes in continuous images. Specifically, the scratch detection model, based on the input multi-frame continuous images, identifies abrupt changes in the target image based on the image content of frames preceding and following the target image. Then, using pre-trained knowledge of various scratch shapes, it determines whether these abrupt changes constitute a scratch, thus determining the location and shape of the scratch in the target image and outputting a scratch mask, achieving rapid scratch detection in the image.
[0114] In an optional implementation, after performing step S102 of inputting the multi-frame continuous images into the scratch detection model to obtain the scratch mask of the target image, the method further includes:
[0115] The image at the location of the scratch indicated by the scratch mask is dilated to obtain the dilated scratch mask;
[0116] Accordingly, step S103 involves inputting the scratch mask of the multi-frame continuous images and the target image into the scratch repair model to repair the scratch location in the target image, thereby obtaining the final repair result, including:
[0117] The multi-frame continuous images and the dilated scratch mask are input into the scratch repair model to repair the scratch location in the target image, thus obtaining the final repair result.
[0118] Reference Figure 2 , Figure 2 A schematic diagram of a scratch mask output by a scratch detection model is shown, as follows: Figure 2 As shown, the scratch mask is a mask that displays the image content at the location of the scratch. Figure 2 The white area in the image indicates the location of the scratch, and can display the corresponding image content at that location. Figure 2 The black areas in the image represent non-scratched areas, which can cover the image content at that location. By comparing this scratch mask with any frame, the image content at the location of the white area can be obtained. In this embodiment, considering that the scratch mask output by the scratch detection model may not completely cover the scratch location, resulting in unrepaired gaps after scratch repair and affecting the scratch repair effect, image dilation is performed on the scratch location indicated in the scratch mask. That is, a morphological image dilation operation is performed on the scratch location to expand the mask area, resulting in a dilated scratch mask. The area of the scratch location indicated by the dilated scratch mask will be larger than the area of the scratch location indicated by the scratch mask output by the scratch detection model. By inputting multiple consecutive frames of images and the dilated scratch mask into the scratch repair model, the scratch location of the target image is repaired, ensuring that the repaired area can completely cover the actual scratch location in the target image, avoiding unrepaired scratch gaps after repair.
[0119] Specifically, an m*m matrix (where m is an odd number greater than 1, typically 3 or 5) can be used as a sliding window to slide across the scratch mask (during this process, the scratch mask is as follows...). Figure 2The image shown is a binary image composed of values 0 and 255, where the pixel value of the scratched area is 255 and the pixel value of the non-scratched area is 0. Specifically, an m*m sliding window is sequentially slid across the target image, acquiring pixel information at the window's location. If a pixel with a value of 255 exists within the m*m window (i.e., the window's location intersects with the scratch's location, and the window's location is closer to the scratch), the pixel at the window's center is assigned a value of 255 (including the window's center location within the scratch's location), thus changing the pixel value at the window's center from 0 to 255. This increases the number of pixels with a value of 255 in the target image, expanding the scratched area. If all pixel values within the window are 0, the pixel value at the window's center remains 0 (if there is no intersection between the window's location and the scratch's location, the window's center is defined as a non-scratched area). (Refer to...) Figure 3 , Figure 3 A schematic diagram of a scratch mask after image dilation is shown. Figure 3 The white area in the image represents the location of the scratches after image dilation (compared to...). Figure 2 The white area in the middle, Figure 3 The white area in the example is slightly larger. Figure 3 The vertical scratch A' in the middle is greater than Figure 2 The vertical scratch A in the image is thicker and more noticeable. Figure 3 The black areas in the image are non-scratched areas. By comparing the scratch mask with any frame of the image, the image content at the location of the white area in that frame can be obtained. This embodiment of the application slightly enlarges the scratch location by dilating the scratch mask, thereby ensuring that the scratch location indicated by the scratch mask completely covers the scratch in the target image, further guaranteeing the scratch repair effect of the video image.
[0120] Step S103: Input the scratch mask of the multi-frame continuous images and the target image into the scratch repair model to repair the scratch location of the target image and obtain the final repair result.
[0121] In practical implementation, the scratch repair model repairs scratches on the target image based on multiple consecutive images and a scratch mask, obtaining the final repair result. In this embodiment, the scratch repair model can be any deep neural network capable of video inpainting, such as a self-attention model based on fine-grained information fusion (FuseFormer), or a self-attention model based on spatiotemporal information fusion (Learning JointSpatial-Temporal Transformations for Video Inpainting (STTN), etc. This embodiment does not limit the specific architecture of the model. (Refer to...) Figure 4 , Figure 4 A schematic diagram of a scratch repair process is shown, such as Figure 4 As shown, multiple consecutive frames of images are input into the scratch detection model and the scratch repair model, respectively. The scratch detection model outputs the scratch mask of the target image to the scratch repair model. Then, the scratch repair model repairs the scratches in the target image based on the multiple consecutive frames of images and the scratch mask, and obtains the final repair result.
[0122] In an optional implementation, before performing step S103, which inputs the scratch mask of the multi-frame continuous images and the target image into the scratch repair model, the method further includes:
[0123] Using the scratch mask, the target image is processed according to the following formula, setting the pixel value at the scratch location in the target image to 0:
[0124]
[0125] Among them, img_masked n+1 This represents the processed target image, where mask represents the scratch mask, and img n+1 This represents the target image before processing. Following the formula above, pixels within the scratch mask area of the target image are assigned a value of 0 to avoid interfering with the subsequent scratch repair model's repair of the scratch area.
[0126] In this embodiment, the scratch repair model uses a scratch mask to obtain reference image content from multiple consecutive frames of the target video. The reference image content is the image content corresponding to the scratch location in the multiple consecutive frames. For example, in step S102, the scratch detection model determines that the scratch in the target image is located in the upper right corner and is shaped like an ellipse C, and outputs the corresponding scratch mask (a mask where the upper right corner is an ellipse C and the rest of the area is covered). Based on the scratch mask, the scratch repair model obtains the image content inside the ellipse C in the upper right corner of each frame of the multiple consecutive frames of the target video and uses it as the reference image content.
[0127] The scratch repair model uses the content of the reference image and the image texture information around the scratch in the target image to complete the image content at the location of the scratch, generating a scratch-repaired image img_pred. n+1 Finally, the content of the scratch location (mask area) in the scratch-repaired image is pasted back into the original image (target image) to obtain the final repair result.
[0128] In one alternative implementation, the scratch repair model is trained through the following steps:
[0129] Step S301: Select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images and a sample scratch mask, the n+1th frame of the 2n+1 consecutive frames of images is the sample target image, the sample scratch mask is used to indicate the location of the scratch in the sample target image, and the original image content of the sample target image is used as the label of the training sample;
[0130] Step S302: Input the training samples and their labels into the initial model to obtain the output of the initial model. The output represents the repaired image obtained after the initial model repairs the scratch location of the target image of the sample.
[0131] Step S303: Calculate the loss function based on the output result to obtain the loss function value, and adjust the parameters of the initial model based on the loss function value; the loss function value represents the magnitude of the difference between the output result and the labels of the training samples.
[0132] Step S304: Repeat the above steps (steps S301-S303) until the loss function converges, end the training, and obtain the scratch repair model.
[0133] In practical implementation, the scratch repair model can also be pre-trained using a large dataset of training samples, enabling the model to automatically generate image content at the location of the scratch. Specifically, a set of 2n+1 consecutive frames is first acquired, where n is any positive integer greater than or equal to 1. The (n+1)th frame is designated as the target image. Scratches of different shapes, similar to the real scratches, are artificially constructed on this target image and randomly placed at any position in the image. The pixel values at the scratch locations in the target image are set to 0, generating a corresponding scratch mask (a mask image used to indicate the location and shape of the scratch). The original image content of the target image is used as the label for the training sample and input into the initial model for training. The model learns to automatically generate image content at the scratch locations and repairs the target image (automatically generating corresponding image content at the scratch locations in the target image), thus generating the repaired image. Then, based on the output (the repaired image), a loss function is calculated to obtain the loss function value. The model parameters are adjusted according to the loss function value, which represents the magnitude of the difference between the output result and the labels of the training samples. If the difference between the output result (the image content of the repaired image generated by the model) and the label (the original image content of the target image) is large, the loss function value is large. By repeating the above steps, the model is trained multiple times using training samples and labels, and the loss function value gradually decreases (the similarity between the model's output result and the label gradually increases) until the loss function value tends to stabilize, at which point training ends, and the scratch repair model is obtained. Thus, by using a large training sample dataset, this scratch repair model can automatically generate the image content of the scratch location and complete the image repair.
[0134] When using deep learning models to repair images, related technologies perform overall image restoration. However, when this method is applied to restoring film-shot video images, it modifies areas other than the scratches, causing detail loss, loss of graininess, and damage to the original texture of the film (film movies have a unique grainy background noise). Specifically, by performing overall image restoration using related technologies, the resulting image (img_pred) after scratch restoration is obtained. n+1 Then, it is directly output as the final repair result. According to the scratch repair method proposed in this embodiment, the scratch repair model processes the content of reference images in multiple consecutive frames to obtain the scratch-repaired image img_pred. n+1Then, the image content at the location of the scratch in the target image is generated, and this part of the image content is pasted back to the scratch location in the target image. This achieves the goal of repairing only the image content at the scratch location, while the rest of the target image can directly copy the original image content. This achieves the maximum preservation of the image graininess of old photos or videos, achieving the effect of restoring the old as before.
[0135] Furthermore, related technologies employ deep learning methods for end-to-end scratch removal processing (inputting a set of scratched images, the model processes and calculates, outputting the scratch-removed result for that set of images). These methods mostly utilize the optical flow information of the image and the preceding and following frames to repair scratches in the current image. Optical flow information can be understood as the motion information of objects between adjacent frames. When the motion between preceding and following frames is too large, the accuracy of optical flow will decrease significantly. Therefore, such methods are difficult to handle scenes with large movements and high-resolution videos, such as scratches in old 4K resolution movies and fast-moving shots in movies, such as fight scenes. The video restoration method proposed in this application uses a scratch detection model to determine the location of scratches in the target image, generating a scratch mask. Then, a scratch restoration model automatically generates image content at the scratch location based on multiple consecutive images and the scratch mask, repairing the scratch location in the target image to obtain the final restoration result. This application embodiment does not introduce optical flow information, but repairs the scratch location based on the reference image content of adjacent frame images. This can solve the problem of image content distortion caused by inaccurate optical flow in the end-to-end automatic scratch removal scheme based on optical flow, and further improve the scratch repair effect.
[0136] In an optional implementation, step S102, which involves using a scratch detection model to perform scratch detection on the target image to obtain a scratch mask for the target image, includes:
[0137] Step S1021: Reduce the pixel size of the multi-frame continuous image according to a first magnification to obtain a multi-frame first continuous image; wherein the first magnification is less than or equal to a preset magnification.
[0138] Step S1022: Input the multi-frame first continuous image into the scratch detection model to perform scratch detection and obtain the scratch mask of the target image.
[0139] In this embodiment, in application scenarios where the image to be detected is a high-resolution image, such as multiple consecutive frames of high-resolution 4K images, before using the scratch detection model for scratch detection, the pixels of the multiple consecutive frames are reduced by a first factor, for example, from 4K to 1080p. Then, the first consecutive image obtained after reduction is input into the scratch detection model for scratch detection to obtain the scratch mask of the target image. It should be noted that when the image resolution is high, the corresponding model has a large computational load and requires a long processing time. This embodiment of the application greatly reduces the image processing time of the scratch detection model by reducing the image pixels to a certain extent, thereby improving the scratch detection efficiency.
[0140] Accordingly, step S103 involves inputting the scratch mask of the multi-frame continuous images and the target image into the scratch repair model to repair the scratch location in the target image, thereby obtaining the final repair result, including:
[0141] Step S1031: Reduce the pixel size of the multi-frame continuous image according to the second magnification to obtain the multi-frame second continuous image.
[0142] Step S1032: Input the scratch mask of the multi-frame second consecutive image and the target image into the scratch repair model to repair the scratch location of the target image and obtain the final repair result.
[0143] In this embodiment, in application scenarios where the image to be detected is a high-resolution image, such as multiple consecutive frames of 4k pixels, before using the scratch repair model to repair scratches on the target image, the pixels of the multiple consecutive frames are reduced by a second factor, for example, from 4k to 540p. Then, the reduced second consecutive image is input into the scratch repair model to perform scratch repair on the target image at a lower resolution, obtaining the final repair result. Therefore, by reducing the image pixels to a certain extent and performing scratch repair at a lower resolution, the model's inference speed can be improved, thereby increasing the efficiency of scratch repair and enabling scratch repair of high-resolution images.
[0144] like Figure 4As shown, the scratch detection model and the scratch repair model are decoupled. Multiple consecutive images are input into the scratch detection model and the scratch repair model respectively. The multiple consecutive images are reduced by a first magnification to obtain multiple first consecutive images, which are then input into the scratch detection model. The multiple consecutive images are then reduced by a second magnification to obtain multiple second consecutive images, which are then input into the scratch repair model. The first magnification must be less than or equal to a preset magnification. During scratch detection, if the first magnification is too large, the image pixel count decreases, causing scratches to become too small. The scratch detection model may then overlook small scratches, resulting in a less than ideal scratch repair effect. Therefore, to improve scratch detection efficiency while ensuring the scratch repair effect is not affected, the first magnification must be controlled to be less than or equal to the preset magnification.
[0145] In an optional implementation, step S1032, which involves inputting the scratch mask of the multiple frames of the second consecutive images and the target image into the scratch repair model to repair the scratch location in the target image and obtain the final repair result, includes:
[0146] Step S1032-1: Using the scratch mask, obtain the reference image content in the multi-frame second continuous image, where the reference image content is the image content corresponding to the location of the scratch in the multi-frame second continuous image.
[0147] Step S1032-2: Based on the content of the reference image and the image texture information around the scratch in the target image, a first scratch repair image is obtained. In specific implementation, for the multiple frames of the second consecutive images, a weight ratio can be set according to the distance from the target image (for example, the weight ratio of the previous frame of the target image is set to 0.4, and the weight ratio of the next frame of the target image is set to 0.3; the closer to the target image, the higher the weight ratio, and the farther away from the target image, the lower the weight ratio). The pixel values of each pixel in the content of the reference image and the image texture information are weighted and fused according to the weight ratio to obtain the first scratch repair image.
[0148] Step S1032-3: Magnify the pixels of the first scratch repair image according to the second magnification to obtain the second scratch repair image.
[0149] Step S1032-4: Using the scratch mask, obtain the repair image content in the second scratch repair image, wherein the repair image content is the image content corresponding to the location of the scratch in the scratch repair image.
[0150] Step S1032-5: Paste the repaired image content back into the target image to obtain the final repair result.
[0151] In an optional implementation, step S1032-5, pasting the repaired image content back into the target image to obtain the final repair result, includes:
[0152] The final repair result is obtained by replacing the image content at the location of the scratch in the target image with the content of the repaired image using the following formula:
[0153]
[0154] Among them, img_res n+1 For the final repair result, img n+1 For the target image, img_pred n+1 The second scratch repair image is defined as follows: `mask` is the scratch mask, a binary image constructed from 0s and 255s, where a pixel value of 255 represents a scratch at that location. This refers to the image content of the non-scratched area in the original target image. This refers to the content of the image being repaired.
[0155] In this embodiment, the scratch repair model uses a scratch mask to obtain reference image content from multiple frames of second consecutive images. The reference image content is the image content corresponding to the scratch location in the multiple frames of second consecutive images. Then, based on the reference image content and the image texture information around the scratch in the target image, the scratch repair model completes the image content at the scratch location in the target image, obtaining a first scratch-repaired image. The first scratch-repaired image is enlarged to the pixel size of the original image to obtain a second scratch-repaired image. Using the scratch mask, the repaired image content in the second scratch-repaired image is obtained. The repaired image content is the image content corresponding to the scratch location in the scratch-repaired image. For example, based on the scratch mask, it is determined that the scratch in the target image is located at the image center, and the shape of the scratch is a circle B. The scratch repair model extracts the image content inside the circle B at the image center of the scratch-repaired image based on the scratch mask, and uses this as the repaired image content.
[0156] In this embodiment, since the input image is a multi-frame second consecutive image reduced by a second magnification, the resulting first scratch repair image is the size after being reduced by the second magnification. Therefore, it is necessary to enlarge the pixels of the first scratch repair image by the second magnification to obtain the second scratch repair image. Then, the repaired image content in the second scratch repair image is pasted back into the target image to repair the scratches in the target image, obtaining the final repair result. On the one hand, this embodiment processes the image by reducing its size to generate the first scratch repair image, thereby improving the image repair efficiency. On the other hand, this embodiment utilizes the characteristic that the scratches in the image occupy a small area and the image content to be repaired is relatively simple. It directly enlarges the first scratch repair image by the second magnification to obtain the image repair content in the second scratch repair image and pastes it back into the original image. This does not affect the scratch repair effect and also preserves the graininess of the original image.
[0157] In one optional implementation, the method further includes:
[0158] If a repair error occurs in the final repair result, the model that caused the repair error is located from the scratch detection model and the scratch repair model based on the scratch mask and the final repair result.
[0159] The model parameters of the model that caused the repair error were adjusted.
[0160] In this embodiment, the scratch detection model and the scratch repair model are decoupled and do not interfere with each other, making the entire scratch repair process clearer. If a repair error (or poor repair effect) occurs in the final repair result, the model causing the error can be identified by evaluating the outputs of the two models (the scratch mask and the final repair result). Specifically, the scratch mask can be compared with the target image to determine if the scratch detection model failed to detect the scratch in the target image, and the final repair result can be compared with the scratch mask to determine if the scratch repair model failed to repair the scratch.
[0161] This embodiment adjusts the model parameters of the model that caused the repair error based on the localization results to improve the scratch repair effect. For example, if the localization results determine that the scratch detection model failed to detect the scratch, the parameters of the scratch detection model are adjusted, or the scratch detection model is retrained to improve its sensitivity to scratches, thereby improving the scratch repair effect.
[0162] In related technologies, when using end-to-end models to repair scratches in images, scratch detection and scratch repair are often coupled. If the image repair effect is unsatisfactory, it is difficult to determine which specific step has a problem, and the entire image repair model must be adjusted. However, the embodiments of this application decouple scratch detection and scratch repair, which makes it easy to locate whether the model causing the scratch repair misalignment is the scratch detection model or the scratch repair model, thereby allowing for targeted adjustments and improving the repair effect.
[0163] In one optional implementation, the method further includes:
[0164] Each frame of the target video is used sequentially as the target image for video scratch repair.
[0165] During the process of video scratch repair of the target video, while using the scratch detection model to detect scratches in the current frame image, the scratch repair model is used to repair the scratches in the previous frame image.
[0166] The existing technology employs deep learning for end-to-end scratch removal. This involves inputting a set of scratched images, outputting the scratch-removed result from the model, and then inputting the next set of scratched images for further processing. For typical videos, especially long videos like movies containing hundreds of thousands of frames, processing each frame individually using the above method is time-consuming and inefficient. This application proposes a method for scratch repair of target videos where each frame is treated sequentially as the target image. Furthermore, by decoupling the scratch detection model and the scratch repair model, the scratch detection model detects scratches in the current frame (i.e., it has already detected scratches in the previous frame and outputs the scratch mask to the scratch repair model), while the scratch repair model repairs the scratches in the previous frame. This parallel processing of scratch detection and repair improves the efficiency of scratch repair for target videos.
[0167] A second aspect of this application provides a video restoration apparatus, referring to... Figure 5 , Figure 5 A schematic diagram of a video restoration device is shown, as follows: Figure 5 As shown, the device includes:
[0168] The image acquisition module is used to acquire multiple consecutive frames of images of the target video, wherein the multiple consecutive frames include the target image;
[0169] The scratch detection module is used to perform scratch detection on the target image using a scratch detection model to obtain a scratch mask of the target image, and the scratch mask is used to indicate the location of the scratch in the target image.
[0170] The scratch repair module is used to input the scratch mask of the multi-frame continuous images and the target image into the scratch repair model, repair the scratch location of the target image, and obtain the final repair result.
[0171] In one optional implementation, the scratch detection module includes:
[0172] The first reduction submodule is used to reduce the pixels of the multi-frame continuous images according to a first magnification ratio to obtain a multi-frame first continuous image; wherein the first magnification ratio is less than or equal to a preset magnification ratio;
[0173] The first input submodule is used to input the multiple frames of the first consecutive images into the scratch detection model for scratch detection, and obtain the scratch mask of the target image;
[0174] The scratch repair module includes:
[0175] The second reduction submodule is used to reduce the pixels of the multi-frame continuous image according to the second magnification rate to obtain the multi-frame second continuous image;
[0176] The second input submodule is used to input the scratch mask of the multi-frame second consecutive image and the target image into the scratch repair model, repair the scratch location of the target image, and obtain the final repair result.
[0177] In one optional implementation, the second input submodule includes:
[0178] In one optional implementation, the second input submodule includes:
[0179] The reference image content determination unit is used to obtain the reference image content in the multi-frame second consecutive image using the scratch mask, wherein the reference image content is the image content corresponding to the location of the scratch in the multi-frame second consecutive image;
[0180] The first scratch repair image generation unit is used to obtain a first scratch repair image based on the content of the reference image and the image texture information around the scratch in the target image;
[0181] The second scratch repair image generation unit is used to enlarge the pixels of the first scratch repair image according to the second magnification to obtain the second scratch repair image;
[0182] The image content acquisition unit is used to acquire the repaired image content in the second scratch repair image using the scratch mask, wherein the repaired image content is the image content corresponding to the location of the scratch in the scratch repair image;
[0183] The final repair result acquisition unit is used to paste the repaired image content back into the target image to obtain the final repair result.
[0184] In one optional implementation, the final repair result acquisition unit includes:
[0185] The replacement subunit is used to replace the image content at the location of the scratch in the target image with the content of the repaired image according to the following formula, to obtain the final repair result:
[0186]
[0187] Among them, img_res n+1 For the final repair result, img n+1 For the target image, img_pred n+1 The second scratch repair image is defined as follows: `mask` is the scratch mask, a binary image constructed from 0s and 255s, where a pixel value of 255 represents a scratch at that location. This refers to the image content of the non-scratched area in the target image. This refers to the content of the image being repaired.
[0188] In one alternative embodiment, the device further includes:
[0189] The positioning module is used to locate the model that caused the repair error from the scratch detection model and the scratch repair model, based on the scratch mask and the final repair result, when a repair error occurs in the final repair result.
[0190] The adjustment module is used to adjust the model parameters of the model that caused the repair error.
[0191] In one alternative embodiment, the device further includes:
[0192] The image dilation module is used to dilate the image at the location of the scratch indicated by the scratch mask after inputting the multi-frame continuous images into the scratch detection model to obtain the scratch mask of the target image, so as to obtain the dilated scratch mask.
[0193] The scratch repair module is further used to input the multi-frame continuous images and the inflated scratch mask into the scratch repair model to repair the scratch location of the target image and obtain the final repair result.
[0194] In one alternative embodiment, the device further includes:
[0195] The video scratch repair module is used to sequentially use each frame of the target video as the target image to repair video scratches.
[0196] During the process of video scratch repair of the target video, while using the scratch detection model to detect scratches in the current frame image, the scratch repair model is used to repair the scratches in the previous frame image.
[0197] In one optional embodiment, the apparatus further includes: a scratch detection model training module for training the scratch detection model; the scratch detection model training module includes:
[0198] The first sample selection submodule is used to select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images, the n+1th frame of the 2n+1 consecutive frames of images is the target image of the sample, and the shape and position of the scratch in the target image of the sample are determined as the label of the training sample;
[0199] The first calculation submodule is used to input the training samples and the labels of the training samples into the initial model to obtain the output result of the initial model, wherein the output result represents the scratch mask of the target image of the sample predicted by the initial model;
[0200] The first loss function calculation submodule is used to calculate the loss function based on the output result, obtain the loss function value, and adjust the parameters of the initial model based on the loss function value; the loss function value represents the magnitude of the difference between the output result and the label of the training sample;
[0201] The first repeating submodule is used to repeatedly run the first sample selection submodule, the first calculation submodule, and the first loss function calculation submodule until the loss function converges, thereby ending the training and obtaining the scratch detection model.
[0202] In one optional embodiment, the apparatus further includes: a scratch repair model training module for training the scratch repair model; the scratch repair model training module includes:
[0203] The second sample selection submodule is used to select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images and a sample scratch mask, the n+1th frame of the 2n+1 consecutive frames of images is the sample target image, the sample scratch mask is used to indicate the location of the scratch in the sample target image, and the original image content of the sample target image is used as the label of the training sample;
[0204] The second calculation submodule is used to input the training samples and the labels of the training samples into the initial model to obtain the output result of the initial model. The output result represents the repaired image obtained by the initial model after repairing the scratch location of the target image of the sample.
[0205] The second loss function calculation submodule is used to calculate the loss function based on the output result, obtain the loss function value, and adjust the parameters of the initial model based on the loss function value; the loss function value represents the magnitude of the difference between the output result and the label of the training sample;
[0206] The second repetition submodule is used to repeatedly run the second sample selection submodule, the second calculation submodule, and the second loss function calculation submodule until the loss function converges, thereby ending the training and obtaining the scratch repair model.
[0207] This application also provides an electronic device, which is described in reference to... Figure 6 , Figure 6 This is a schematic diagram of the electronic device proposed in an embodiment of this application. Figure 6 As shown, the electronic device 100 includes a memory 110 and a processor 120. The memory 110 and the processor 120 are connected via a bus for communication. The memory 110 stores a computer program that can run on the processor 120 to implement the steps in the video repair method disclosed in the embodiments of this application.
[0208] This application also provides a computer-readable storage medium storing a computer program / instructions thereon, which, when executed by a processor, implements the steps in the video restoration method disclosed in this application.
[0209] This application also provides a computer program product that, when run on an electronic device, causes a processor to execute the steps in the video restoration method disclosed in this application.
[0210] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on the differences from other embodiments. The same or similar parts between the various embodiments can be referred to each other.
[0211] This application describes embodiments with reference to flowchart illustrations and / or block diagrams of methods, apparatuses, electronic devices, and computer program products according to embodiments of this application. It should be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing terminal device to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing terminal device, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0212] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing terminal device to operate in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0213] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal equipment, causing a series of operational steps to be performed on the computer or other programmable terminal equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable terminal equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0214] Although preferred embodiments of the present application have been described, those skilled in the art, upon learning the basic inventive concept, can make other changes and modifications to these embodiments. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments as well as all changes and modifications falling within the scope of the embodiments of the present application.
[0215] Finally, it should be noted that in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or terminal device that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or terminal device. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or terminal device that includes said element.
[0216] The video restoration method, apparatus, electronic device, and storage medium provided in this application have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this application. The description of the above embodiments is only for the purpose of helping to understand the method and core ideas of this application. At the same time, for those skilled in the art, there will be changes in the specific implementation methods and application scope based on the ideas of this application. Therefore, the content of this specification should not be construed as a limitation of this application.
Claims
1. A video restoration method, characterized in that, The method includes: Acquire multiple consecutive frames of images from a target video, wherein the multiple consecutive frames include the target image; The target image is scratched using a scratch detection model to obtain a scratch mask for the target image. The scratch mask is used to indicate the location of the scratches in the target image. The pixels of the multi-frame continuous images are reduced according to the second magnification to obtain multi-frame second continuous images; Using the scratch mask, obtain the reference image content in the multi-frame second consecutive image, where the reference image content is the image content corresponding to the location of the scratch in the multi-frame second consecutive image; A first scratch repair image is obtained based on the content of the reference image and the image texture information around the scratch in the target image; The pixels of the first scratch repair image are magnified according to the second magnification to obtain the second scratch repair image; Using the scratch mask, obtain the repair image content in the second scratch repair image, wherein the repair image content is the image content corresponding to the location of the scratch in the scratch repair image; The final repair result is obtained by replacing the image content at the location of the scratch in the target image with the content of the repaired image using the following formula: ; in, The final repair result is as described. The target image, The second scratch repair image is shown below. The mask is the scratch mask, which is a binary image constructed from 0s and 255s, where a pixel value of 255 represents a scratch at that location. This represents the image content of the non-scratched area in the target image. This refers to the content of the image being repaired.
2. The video restoration method according to claim 1, characterized in that, The step of using a scratch detection model to detect scratches on the target image and obtaining a scratch mask for the target image includes: The pixels of the multiple consecutive images are reduced according to a first magnification ratio to obtain multiple first consecutive images; the first magnification ratio is less than or equal to a preset magnification ratio. The first consecutive images of the multiple frames are input into the scratch detection model for scratch detection to obtain the scratch mask of the target image.
3. The video restoration method according to claim 1, characterized in that, The method further includes: In the event of a repair error in the final repair result, the model causing the repair error is located from the scratch detection model and the scratch repair model based on the scratch mask and the final repair result. The model parameters of the model that caused the repair error were adjusted.
4. The video restoration method according to claim 1, characterized in that, After inputting the multi-frame continuous images into the scratch detection model to obtain the scratch mask of the target image, the method further includes: The image at the location of the scratch indicated by the scratch mask is dilated to obtain the dilated scratch mask; The step involves inputting the scratch mask of the multiple consecutive images and the target image into the scratch repair model to repair the scratch location in the target image, thereby obtaining the final repair result, including: The multi-frame continuous images and the dilated scratch mask are input into the scratch repair model to repair the scratch location in the target image, thus obtaining the final repair result.
5. The video restoration method according to claim 1, characterized in that, The method further includes: Each frame of the target video is used sequentially as the target image for video scratch repair. During the process of video scratch repair of the target video, while using the scratch detection model to detect scratches in the current frame image, the scratch repair model is used to repair the scratches in the previous frame image.
6. The video restoration method according to claim 1, characterized in that, The scratch detection model was trained according to the following steps: Select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images, the n+1th frame of the 2n+1 consecutive frames of images is the target image of the sample, and the shape and position of the scratch in the target image of the sample are determined as the label of the training sample; The training samples and their labels are input into the initial model to obtain the output of the initial model, which represents the scratch mask of the target image of the sample predicted by the initial model. Based on the output, a loss function is calculated to obtain a loss function value, and the parameters of the initial model are adjusted based on the loss function value; the loss function value represents the magnitude of the difference between the output and the labels of the training samples. Repeat the above steps until the loss function converges, then end the training to obtain the scratch detection model.
7. The video restoration method according to claim 1, characterized in that, The scratch repair model was trained through the following steps: Select a training sample and its label from the training sample dataset; the training sample is a set of 2n+1 consecutive frames of images and a sample scratch mask, the n+1th frame of the 2n+1 consecutive frames of images is the sample target image, the sample scratch mask is used to indicate the location of the scratch in the sample target image, and the original image content of the sample target image is used as the label of the training sample. The training samples and their labels are input into the initial model to obtain the output of the initial model. The output represents the repaired image obtained by the initial model after repairing the scratch location of the target image of the sample. Based on the output, a loss function is calculated to obtain a loss function value, and the parameters of the initial model are adjusted based on the loss function value; the loss function value represents the magnitude of the difference between the output and the labels of the training samples. Repeat the above steps until the loss function converges, then end the training to obtain the scratch repair model.
8. A video restoration device, characterized in that, The device includes: The image acquisition module is used to acquire multiple consecutive frames of images of the target video, wherein the multiple consecutive frames include the target image; The scratch detection module is used to perform scratch detection on the target image using a scratch detection model to obtain a scratch mask of the target image, and the scratch mask is used to indicate the location of the scratch in the target image. The scratch repair module is used to input the scratch mask of the multi-frame continuous images and the target image into the scratch repair model, repair the scratch location of the target image, and obtain the final repair result. The scratch repair module includes: The second reduction submodule is used to reduce the pixels of the multi-frame continuous image according to the second magnification rate to obtain the multi-frame second continuous image; The second input submodule is used to input the scratch mask of the multi-frame second consecutive image and the target image into the scratch repair model, repair the scratch location of the target image, and obtain the final repair result. The second input submodule includes: The reference image content determination unit is used to obtain the reference image content in the multi-frame second consecutive image using the scratch mask, wherein the reference image content is the image content corresponding to the location of the scratch in the multi-frame second consecutive image; The first scratch repair image generation unit is used to obtain a first scratch repair image based on the content of the reference image and the image texture information around the scratch in the target image; The second scratch repair image generation unit is used to enlarge the pixels of the first scratch repair image according to the second magnification to obtain the second scratch repair image; The image content acquisition unit is used to acquire the repaired image content in the second scratch repair image using the scratch mask, wherein the repaired image content is the image content corresponding to the location of the scratch in the scratch repair image; The final repair result acquisition unit is used to paste the repaired image content back into the target image to obtain the final repair result; The final repair result acquisition unit includes: The replacement subunit is used to replace the image content at the location of the scratch in the target image with the content of the repaired image according to the following formula, to obtain the final repair result: ; in, The final repair result is as described. The target image, The second scratch repair image is defined as follows: `mask` is the scratch mask, a binary image constructed from 0s and 255s, where a pixel value of 255 represents a scratch at that location. This refers to the image content of the non-scratched area in the target image. This refers to the content of the image being repaired.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory, characterized in that, The processor executes the computer program to implement the steps of the video restoration method according to any one of claims 1 to 7.
10. A computer-readable storage medium having a computer program / instructions stored thereon, characterized in that, When the computer program / instruction is executed by the processor, it implements the steps of the video restoration method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Method for detecting and repairing movie scratch damage
CN102129670A
Video processing method and device, electronic equipment and storage medium
CN115049555A
