Image distortion correction method, electronic device, storage medium and chip
The de-distortion model is used to extract and decode the features of the distorted images captured by electronic devices to generate distortion-corrected grid images, which solves the problem of image deformation caused by optical distortion, improves the authenticity and aesthetics of the image, and enhances the user experience.
Patent Information
- Application Number
- CN202410645594.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-23
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2044-05-23
AI Technical Summary
Images captured by electronic devices are deformed and distorted due to optical distortion, which affects the user experience.
The de-distortion model is used to extract and decode features of the distorted image to generate a distortion-corrected grid image, and then use this image to correct the original image to obtain an image that is more in line with the actual situation and human eye aesthetics.
Effectively removes distortion in images, enhances the authenticity and aesthetics of images, and improves user experience.
Smart Images

Figure CN118247186B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and more specifically, to an image distortion correction method, electronic device, storage medium, and chip. Background Art
[0002] In recent years, the photography function of electronic devices (such as mobile phones and tablets) has become one of their most important features. Using wide-angle lenses on these devices allows users to capture a wider and more comprehensive picture of the real scene. However, due to numerous factors, images captured through wide-angle lenses can experience a certain degree of distortion during the imaging process. The resulting image distortion becomes increasingly noticeable, not conforming to human vision, and resulting in a poor user experience.
[0003] Distortion is a deviation from the projection of a straight line. This means that a straight line in a real scene should remain a straight line when projected onto an image. However, due to distortion, this straight line does not remain a straight line when projected onto an image. This means that a straight line in a real scene appears unnaturally deformed or distorted in the image. For example, a mobile phone with a wide-angle lens can capture images with a larger field of view, but it can also easily introduce significant image distortion. For example, a portrait positioned outside the image (i.e., with a wider field of view) will appear more distorted.
[0004] Therefore, how to make images more consistent with actual conditions becomes an urgent problem to be solved. Summary of the Invention
[0005] The present application provides an image distortion correction method, electronic device, storage medium and chip, so that the images captured by the electronic device are more consistent with the actual situation and the user experience is improved.
[0006] In a first aspect, the present application provides an image distortion correction method, the method comprising: obtaining a distorted image and an initial grid image of the distorted image, wherein the initial grid image is a grid image obtained based on the distorted image; performing feature extraction processing on the distorted image through a dedistortion model to obtain feature data of the distorted image; decoding the initial grid image using the feature data of the distorted image through the dedistortion model to obtain a distortion-corrected grid image of the distorted image; and correcting the distorted image using the distortion-corrected grid image through the dedistortion model to obtain a distortion-corrected image.
[0007] The image distortion correction method can be applied to electronic devices provided with a dedistortion model.
[0008] A distorted image refers to an image that is distorted, and the content of the distorted image is not specifically limited. For example, the distorted image may include at least one photographed object, which may be, but is not limited to, a person, an animal, or a building.
[0009] The distortion-corrected image is an image obtained after performing distortion correction processing on the distorted image. The distortion-corrected image can be understood as an image without distortion.
[0010] The dedistortion model can be understood as a neural network model obtained through training.
[0011] In the above technical solution, the electronic device uses a dedistortion model to extract features from a distorted image to obtain feature data of the distorted image. Subsequently, the electronic device uses the dedistortion model to decode the feature data of the distorted image and the initial grid image of the distorted image to obtain a distortion-corrected grid image. Since the distortion-corrected grid image is a grid image obtained by correcting the initial grid image based on the feature data of the distorted image, the distortion-corrected grid image is more consistent with actual conditions. Thereafter, the electronic device uses the distortion-corrected grid image to correct the distorted image using the dedistortion model. The resulting distortion-corrected image is more consistent with actual conditions and the aesthetics of the human eye, thereby improving the user experience.
[0012] In a possible implementation, the initial grid image is a grid image obtained by performing gridding processing on the distorted image.
[0013] There is no specific limitation on the method for obtaining the initial grid image based on the distorted image. For example, the distorted image can be processed based on a method in the related art to obtain the initial grid image.
[0014] In the above technical solution, the initial grid image acquired by the electronic device is a grid image obtained by directly performing gridding processing on the distorted image, and the implementation process is relatively simple.
[0015] In another possible implementation, the initial grid image is a grid image obtained by performing gridding processing on the initial distortion-corrected image, wherein the initial distortion-corrected image is an image obtained after performing a preset distortion correction process on the distorted image.
[0016] The distortion degree of the initial distortion-corrected image is smaller than that of the distorted image.
[0017] The preset distortion correction process can be understood as a distortion correction method in related art. In the embodiments of this application, the distortion correction method in related art is not specifically limited. For example, the distortion correction method in related art can be, but is not limited to, the Zhang Zhengyou camera calibration method.
[0018] In the above technical solution, the initial grid image is a grid image obtained by processing the initial distortion-corrected image with a smaller degree of distortion. Afterwards, the electronic device uses the dedistortion model to process the initial grid image with a smaller degree of distortion and the distorted image, which can reduce the computational complexity of the electronic device and enable the dedistortion model to converge quickly, thereby improving the efficiency of image distortion correction and better enhancing the user experience.
[0019] In another possible implementation, the distorted image includes N first pixel points, and the distortion-corrected grid image includes N second pixel points, where the N second pixel points correspond one-to-one to the N first pixel points, and N is a positive integer; the distorted image is corrected using the distortion-corrected grid image through a dedistortion model to obtain a distortion-corrected image, including: using the dedistortion model, using the coordinate value of each second pixel point to update the coordinate value of each corresponding first pixel point to obtain the distortion-corrected image.
[0020] The number of first pixels included in the distorted image is the same as the number of second pixels included in the distortion-corrected grid image. It can be understood that the size of the distorted image is the same as the size of the distortion-corrected grid image. For example, the distorted image is (Unit: pixel) size image, the distortion correction grid image is (Unit: pixels) Size of the grid image.
[0021] Optionally, the number of first pixels included in the distorted image may be greater than N, and the number of second pixels included in the distortion-corrected grid image is equal to N. In this implementation, the number of first pixels included in the distorted image is greater than the number of second pixels included in the distortion-corrected grid image. This can be understood as the size of the distorted image being greater than the size of the distortion-corrected grid image. For example, the distorted image is (Unit: pixel) size image, the distortion correction grid image is (unit: pixel) size image. For ease of description, the number of first pixels included in the distorted image in this implementation is recorded as H. In this case, the N first pixels are N first pixels out of H first pixels, where H is a positive integer greater than N.
[0022] In the above technical solution, the electronic device uses the distortion correction grid image obtained after the distortion correction processing to correct the distorted image, which can effectively remove the distortion in the distorted image, so that the obtained distortion correction image is more in line with the actual situation and the aesthetics of the human eye, thereby improving the user experience.
[0023] In another possible implementation, the coordinate value of the second pixel point is obtained by interpolating the coordinate values of multiple pixel points in the distortion-corrected grid image associated with the second pixel point.
[0024] The above interpolation algorithm is not specifically limited and can be selected according to needs or scenarios. For example, the interpolation algorithm can be, but is not limited to, bilinear interpolation or grayscale interpolation.
[0025] In another possible implementation, obtaining the distorted image includes: performing scaling processing on the obtained initial distorted image to obtain the distorted image, wherein a size of the distorted image is smaller than a size of the initial distorted image.
[0026] The distorted image retains the characteristics of the initial distorted image, and the amount of data in the distorted image is smaller than that in the initial distorted image. For example, the initial distorted image is (Unit: pixel) size image, the distorted image is (Unit: pixels) The size of the image.
[0027] The method by which the electronic device performs scaling processing on the initial distorted image is not specifically limited. For example, the electronic device may perform scaling processing on the initial distorted image using a convolutional neural network, where the convolutional neural network and the dedistortion model may be, but are not limited to, two independent models. For example, the electronic device may also perform scaling processing using algorithms other than convolutional neural networks.
[0028] In the above technical solution, the electronic device processes the distorted image with a smaller data volume and the initial grid image of the distorted image through the dedistortion model, which can reduce the amount of calculation and make the dedistortion model converge quickly, thereby improving the efficiency of image distortion correction and better enhancing the user experience.
[0029] In another possible implementation, before performing feature extraction processing on the distorted image through the dedistortion model to obtain feature data of the distorted image, the method further includes: obtaining at least one training sample pair, wherein the at least one training sample pair includes a training distorted image and a first grid image of the training distorted image as training data, and a label image as label data, the first grid image is a grid image obtained based on the training distorted image, and the label image is an image without distortion obtained based on the training distorted image; performing feature extraction processing on the training distorted image through the initial dedistortion model to obtain feature data of the training distorted image; decoding the first grid image of the training distorted image using the feature data of the training distorted image through the initial dedistortion model to obtain a second grid image of the training distorted image; correcting the training distorted image using the second grid image of the training distorted image through the initial dedistortion model to obtain a distortion-corrected image corresponding to the training distorted image; and adjusting parameters of the initial dedistortion model according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model.
[0030] The label image is an undistorted image obtained based on the distorted training image. The method for obtaining the label image is not specifically limited. For example, the distorted training image (which has distortion) can be dedistorted using image processing software to obtain an image that conforms to both the actual situation and the aesthetics of the human eye. This image that conforms to the actual situation and the aesthetics of the human eye can then be used as the label image.
[0031] In another possible implementation, the first grid image is a grid image obtained by performing gridding processing on the training distorted image.
[0032] In another possible implementation, the first grid image is a grid image obtained by gridding an initial training distortion-corrected image, wherein the initial training distortion-corrected image is an image obtained by performing a preset distortion correction process on the training distortion image.
[0033] In another possible implementation, the initial dedistortion model includes an initial encoder, an initial decoder and an output layer, and: performing feature extraction processing on the training distorted image through the initial dedistortion model to obtain feature data of the training distorted image, including: performing feature extraction processing on the training distorted image through the initial encoder to obtain feature data of the training distorted image; decoding the first grid image of the training distorted image using the feature data of the training distorted image through the initial dedistortion model to obtain a second grid image of the training distorted image, including: decoding the feature data of the training distorted image and the first grid image of the training distorted image through the decoder to obtain the second grid image of the training distorted image; correcting the training distorted image using the second grid image of the training distorted image through the initial dedistortion model to obtain a distortion-corrected image corresponding to the training distorted image, including: correcting the training distorted image using the second grid image of the training distorted image through the output layer to obtain a distortion-corrected image corresponding to the training distorted image; adjusting the parameters of the initial encoder and the parameters of the initial decoder according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model.
[0034] In another possible implementation, the distortion removal model is a transformer model in a generative model.
[0035] The dedistortion model is a generative model. Specifically, the dedistortion model is a transformer model.
[0036] In the above technical solution, the distortion correction model is a generative model. Its core concept is to learn the distribution of data and then generate new data similar to the actual data. (For example, if we have a collection of cat pictures, the goal of the generative model is to learn the characteristics of these pictures and generate new cat pictures.) This generative model is highly robust. The distortion correction model, derived from deep learning, corrects distorted images to produce distortion-corrected images that are more realistic and aesthetically pleasing to the human eye, thereby improving the user experience.
[0037] In another possible implementation, the dedistortion model includes a decoder, an encoder and an output layer, and; performing feature extraction processing on the distorted image through the dedistortion model to obtain feature data of the distorted image, including: performing feature extraction processing on the distorted image through the encoder to obtain feature data of the distorted image; decoding the initial grid image using the feature data of the distorted image through the dedistortion model to obtain a distortion-corrected grid image of the distorted image, including: decoding the initial grid image using the feature data of the distorted image through the decoder to obtain a distortion-corrected grid image; correcting the distorted image using the distortion-corrected grid image through the dedistortion model to obtain a distortion-corrected image, including: correcting the distorted image using the distortion-corrected grid image through the output layer to obtain a distortion-corrected image.
[0038] In another possible implementation, the method is applied to an electronic device including a camera to obtain a distorted image, including: displaying a shooting interface; obtaining a distorted image through the camera in response to a shooting operation on the shooting interface; after correcting the distorted image using a distortion correction grid image through a dedistortion model to obtain a distortion corrected image, the method also includes: displaying an interface including the distortion corrected image.
[0039] In the above technical solution, after the electronic device obtains a distorted image through a camera, the electronic device automatically performs image distortion correction processing on the distorted image in the background. Afterwards, the electronic device automatically presents the obtained distortion-corrected image that is more in line with the actual situation and in line with the aesthetics of the human eye to the user, which can improve the user experience.
[0040] In another possible implementation, the method is applied to an electronic device including a gallery application to obtain a distorted image, including: displaying an interface of the gallery application; obtaining the distorted image in response to a selection operation for the distorted image in the interface of the gallery application; after correcting the distorted image using a distortion correction grid image through a dedistortion model to obtain a distortion-corrected image, the method also includes: displaying an interface including the distortion-corrected image.
[0041] Optionally, the gallery application may be replaced by other applications in the electronic device that can be called to open images. For example, the other application may be, but is not limited to, a chat application or an image editing application.
[0042] In the above technical solution, the user can trigger the electronic device to perform distortion correction processing on the images pre-stored in the gallery application of the electronic device according to his or her own needs. After that, the electronic device automatically presents the obtained distortion-corrected image that is more in line with the actual situation and in line with the aesthetics of the human eye to the user, which can improve the user experience.
[0043] In a second aspect, the present application provides an image distortion correction device, which includes a processing unit, and the processing unit is used to execute any image distortion correction method in the first aspect.
[0044] In a third aspect, the present application provides an electronic device comprising a unit for executing any of the image distortion correction methods described in the first aspect. The electronic device may be a terminal device or a chip within the terminal device. The electronic device may include an input unit and a processing unit.
[0045] When the electronic device is a terminal device, the processing unit may be a processor, and the input unit may be a communication interface; the terminal device may also include a memory for storing computer program code, and when the processor executes the computer program code stored in the memory, the terminal device executes any one of the image distortion correction methods in the first aspect.
[0046] When the electronic device is a chip within a terminal device, the processing unit may be a processing unit within the chip, and the input unit may be an output interface, a pin, or a circuit, etc.; the chip may further include a memory, which may be a memory within the chip (for example, a register, a cache, etc.), or a memory located outside the chip (for example, a read-only memory, a random access memory, etc.); the memory is used to store computer program code, and when the processor executes the computer program code stored in the memory, the chip executes any one of the image distortion correction methods in the first aspect.
[0047] In one possible implementation, a memory is used to store computer program code; a processor executes the computer program code stored in the memory, and when the computer program code stored in the memory is executed, the processor is used to execute any one of the image distortion correction methods in the first aspect.
[0048] In a fourth aspect, the present application provides a computer-readable storage medium storing a computer program code. When the computer program code is executed by an electronic device, the electronic device executes any one of the image distortion correction methods in the first aspect.
[0049] In a fifth aspect, the present application provides a computer program product, comprising: a computer program code, which, when executed by an electronic device, enables the electronic device to perform any one of the image distortion correction methods in the first aspect.
[0050] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here.
[0051] It should be understood that the description of technical features, technical solutions, beneficial effects or similar language in this application does not imply that all features and advantages can be achieved in any single embodiment. On the contrary, it is understood that the description of a feature or beneficial effect means that a specific technical feature, technical solution or beneficial effect is included in at least one embodiment. Therefore, the description of a technical feature, technical solution or beneficial effect in this specification does not necessarily refer to the same embodiment. Furthermore, the technical features, technical solutions and beneficial effects described in the present embodiment can also be combined in any appropriate manner. Those skilled in the art will understand that the embodiment can be implemented without one or more specific technical features, technical solutions or beneficial effects of a specific embodiment. In other embodiments, additional technical features and beneficial effects can also be identified in specific embodiments that do not embody all embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0052] Figure 1 Schematic diagram of a distorted image and an undistorted image provided in an embodiment of the present application.
[0053] Figure 2 Schematic diagram of a distorted image and an undistorted image provided in an embodiment of the present application.
[0054] Figure 3 Schematic diagram of a grid image of a distorted image and a grid image of an undistorted image provided in an embodiment of the present application.
[0055] Figure 4A This is a schematic diagram of an application scenario suitable for the image distortion correction method provided in an embodiment of the present application.
[0056] Figure 4B This is a schematic diagram of an application scenario suitable for the image distortion correction method provided in an embodiment of the present application.
[0057] Figure 5This is a schematic diagram of a user interface of an electronic device executing the image distortion correction method provided in an embodiment of the present application.
[0058] Figure 6 This is a schematic diagram of a user interface of an electronic device executing the image distortion correction method provided in an embodiment of the present application.
[0059] Figure 7 It is a schematic diagram of the principle of a model training method provided in an embodiment of the present application.
[0060] Figure 8 It is a schematic diagram of a model training method provided in an embodiment of the present application.
[0061] Figure 9 This embodiment of the present application provides a method for obtaining the above Figure 8 Schematic diagram of the method for a grid image A of a distorted image A.
[0062] Figure 10 is the above Figure 8 Schematic diagram of the structure of the initial dedistortion model trained by the provided model training method.
[0063] Figure 11 This is a schematic diagram of an image distortion correction method provided in an embodiment of the present application.
[0064] Figure 12 This is a schematic diagram of an image distortion correction method provided in an embodiment of the present application.
[0065] Figure 13 This is a schematic diagram of an image distortion correction device provided in an embodiment of the present application.
[0066] Figure 14 Schematic diagram of a software system of an electronic device 100 provided in an embodiment of the present application.
[0067] Figure 15 Schematic diagram of the hardware structure of an electronic device 100 provided in an embodiment of the present application. DETAILED DESCRIPTION
[0068] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0069] The terms "first," "second," and so on, in this specification, claims, and accompanying drawings are used to distinguish between different objects and should not be construed as indicating or implying relative importance or implicitly specifying the quantity of the technical features indicated. Therefore, the terms "first" and "second" may explicitly or implicitly include one or more of the features.
[0070] In the embodiments of this application, words such as "exemplary" or "for example" are used to indicate examples, illustrations, or descriptions. Any embodiment or design described as "exemplary" or "for example" in the embodiments of this application should not be interpreted as being preferred or advantageous over other embodiments or designs. Rather, the use of words such as "exemplary" or "for example" is intended to present the relevant concepts in a concrete manner.
[0071] In the embodiments of the present application, "correction" is also referred to as "calibration", that is, "correction" and "calibration" have the same meaning and express the same meaning.
[0072] First, a brief introduction is given to the relevant terms involved in the embodiments of this application.
[0073] 1. Source image
[0074] A source image is the original image captured by the camera of an electronic device (such as a mobile phone or tablet). The camera of an electronic device includes an optical lens module and a photosensitive element. For example, the photosensitive element includes a charge-coupled device (CCD). During recording, light from the scene is focused by the optical lens module and projected onto the CCD. CCDs are made of highly sensitive semiconductor materials and typically contain numerous photosensitive units, typically measured in megapixels. When light strikes the CCD surface, each photosensitive unit reflects an electrical charge on the component, converting the light into an electrical signal. The signals generated by all photosensitive units are combined to form a complete electrical signal. The CCD then transmits the electrical signal to the image signal processor (ISP), which converts it into a digital image signal. The image signal processor (ISP) then outputs the digital image signal to the digital signal processor (DSP) for processing. DSP converts digital image signals into standard red, green, blue (RGB), YUV (a color encoding method) and other formats. Among them, Y represents brightness (luminance or luma), that is, grayscale value, and U and V represent chrominance (chroma), which describes the color and saturation of the image.
[0075] Since an optical lens module generally has a certain degree of optical distortion (eg, barrel distortion), this causes the image content of the source image captured by the camera device of the electronic device to be deformed and distorted.
[0076] In the embodiment of the present application, the source image may also be referred to as a "distorted image", which will not be emphasized below.
[0077] For example, Figure 1 Figure (1) in the figure, Figure 1 Figure (3) or Figure 2 The image shown in (1) is a specific example of a source image (distorted image).
[0078] 2. Distortion and Optical Distortion
[0079] Distortion refers to the degree to which the image formed by an optical system is distorted relative to the object itself. Specifically, a straight line in a real scene should remain a straight line when projected onto an image. However, due to distortion, this straight line does not remain a straight line when projected onto the image. In other words, a straight line in a real scene appears as an unnaturally deformed or distorted curve in the image.
[0080] Optical distortion refers to the degree of deformation calculated based on optical theory. In an image with optical distortion, straight lines in space appear curved. The distortion caused by optical distortion is highly detrimental to photo quality. Due to optical distortion, straight lines in the world coordinate system of the photographed scene may appear as curves when converted to the image pixel coordinate system. This optical distortion is particularly noticeable near the edges of the image, and wide-angle cameras experience more pronounced optical distortion than standard cameras.
[0081] When the electronic device is a mobile electronic device such as a mobile phone, tablet computer, wearable device, etc., the optical lens module usually has large optical distortion due to the influence of the optical design of the lens. This is related to the field of view of the mobile electronic device. Generally, the larger the field of view, the greater the optical distortion of the optical lens module.
[0082] Optical distortion can also be called image distortion, lens distortion, video distortion, camera distortion, lens distortion, etc. The types of optical distortion mainly include radial distortion and tangential distortion.
[0083] Tangential distortion is usually caused by manufacturing defects in the camera device located in the electronic device, which makes the lens itself non-parallel to the image plane.
[0084] Radial distortion occurs because light is bent more away from the center of the lens than near the center. Radial distortion mainly includes barrel distortion and pincushion distortion. For example, Figure 3They respectively show the grid images of the pincushion distortion image (such as Figure 3 (1) in Figure ), the grid image of the undistorted image (such as Figure 3 (2) in ), and the grid image of the barrel distorted image (such as Figure 3 A comparative diagram of Figure (3) in .
[0085] Barrel distortion, also known as barrel distortion, is a phenomenon caused by the physical properties of the lens and the structure of the lens elements, resulting in the image appearing barrel-shaped and bulging. Barrel distortion is typically most noticeable when using wide-angle lenses or zoom lenses at their wide-angle end. For example, the image of a funhouse mirror that makes a person appear shorter and pudgier is a vivid example of barrel distortion.
[0086] Pincushion distortion, also known as pincushion distortion, is a lens-induced distortion that causes the image to "pinch" toward the center. Pincushion distortion is most noticeable when using a telephoto lens or at the telephoto end of a zoom lens. It's particularly common when using a focal converter. For example, the image in a funhouse mirror that makes a person appear taller and thinner is an example of pincushion distortion.
[0087] The image distortion correction method provided in the embodiments of the present application is described in detail below.
[0088] In recent years, with the advancement of terminal technology, the various functions of electronic devices have continued to improve, and people's entertainment, communication, and work styles have undergone significant changes. Taking mobile phones as an example, the camera function is frequently used in daily life. For example, when users encounter beautiful scenery or architecture while traveling, they want to capture it as a souvenir. For example, when users gather with friends or have family dinners, they want to use their phones to capture these joyful moments. However, when users use their phones to take photos, they often encounter poor quality photos due to factors such as poor angle and distance. However, users' demand for selfies and other photography is increasing, and they want to capture high-quality images.
[0089] Currently, in mobile phone photography, when a person is projected onto the imaging plane through the lens, deformation occurs due to factors such as lens module deformation and perspective projection, causing the captured image to have a certain degree of distortion, which does not conform to human vision and leads to a poor user experience. For example, Figure 1 In Figure (1), when the person being photographed is close to the lens, the portrait in the image will be deformed with a large nose, a long face, and small ears. Figure 1 In Figure (3), when the person is far away from the lens, the facial features of the person in the image will become flat. For example, Figure 2 In Figure (1), when taking a selfie, if there are many people in the photo and the subject is in a wide field of view, the portrait in the image will be deformed by stretching towards the four corners (hereinafter referred to as wide-angle deformation). In addition, when the person being photographed is close to or far away from the lens, the portrait in the image will show perspective deformation, for example Figure 1 (1) Figure and Figure 1 The portrait shown in (3) in FIG.
[0090] Therefore, how to make images more consistent with actual conditions and human vision has become an urgent problem that needs to be solved.
[0091] The embodiments of the present application provide an image distortion correction method, an electronic device, a storage medium, and a chip. The method includes: the electronic device uses a dedistortion model to extract features from a distorted image with distortion to obtain feature data of the distorted image. Afterwards, the electronic device uses the dedistortion model to decode the feature data of the distorted image and the initial grid image of the distorted image to obtain a distortion-corrected grid image. Since the distortion-corrected grid image is a grid image obtained by correcting the initial grid image based on the feature data of the distorted image, the distortion-corrected grid image is more in line with the actual situation. Thereafter, the electronic device uses the distortion-corrected grid image to correct the distorted image through the dedistortion model, and the obtained distortion-corrected image is more in line with the actual situation and the aesthetics of the human eye, thereby improving the user experience.
[0092] The image distortion correction method provided in the embodiments of the present application can be applied to electronic devices such as mobile phones, tablet computers, wearable devices (e.g., smart watches), audio devices (e.g., headphones or speakers), in-vehicle devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, and personal digital assistants (PDAs). The embodiments of the present application do not impose any restrictions on the specific types of electronic devices.
[0093] The following describes application scenarios to which the image distortion correction method provided by the embodiment of the present application is applicable. It should be understood that the application scenarios 1 and 2 described below are for illustration only and do not constitute any limitation on the application scenarios to which the embodiment of the present application is applicable.
[0094] Application scenario 1: The client performs image distortion correction on the acquired distorted image.
[0095] For example, Figure 4AThis is a schematic diagram of an application scenario applicable to the image distortion correction method provided in the embodiment of the present application. For example, Figure 4A The illustrated application scenario includes at least one client 400 .
[0096] The client 400 is configured to acquire or collect a distorted image and perform the image distortion correction method provided in the embodiments of the present application on the distorted image, thereby obtaining a distortion-corrected image. The distortion-corrected image refers to an image free of any distortion. It should be understood that the type of subject included in the distortion-corrected image obtained after correcting the distorted image is the same as the type of subject included in the distorted image, except that the shape of the subject may be different.
[0097] For example, a camera installed in client 400 captures a person and obtains a distorted image. For another example, client 400 obtains a distorted image from a locally stored video stream, where the distorted image is a frame in the video stream. For another example, client 400 obtains a distorted image from an image stored in a local gallery application, where the distorted image is a single image stored in the gallery application.
[0098] The client 400 may be at least one of a tablet computer, a wearable device (e.g., a smartwatch), a smart phone, a game console, a desktop computer, an e-book reader, an augmented reality (AR) / virtual reality (VR) device, an ultra-mobile personal computer (UMPC), a personal digital assistant (PDA), an in-vehicle device, and a laptop computer. Figure 4A The client 400 shown may generally refer to one of multiple terminals, or a set of multiple terminals, which is not specifically limited in the embodiments of the present application.
[0099] Application scenario two: The server performs image distortion correction on the distorted image collected by the client.
[0100] For example, Figure 4B This is a schematic diagram of an application scenario applicable to the image distortion correction method provided in the embodiment of the present application. For example, Figure 4B The illustrated application scenario includes at least one client 410 and at least one server 420 , wherein each client 410 is connected to each server 420 via a wireless network or a wired network.
[0101] Client 410 is configured to obtain a distorted image and transmit the obtained distorted image to server 420. Upon receiving the distorted image, server 420 performs the image distortion correction method provided in the embodiments of the present application on the distorted image to obtain a distortion-corrected image. Server 420 then returns the obtained distortion-corrected image to client 410. After obtaining the distortion-corrected image, client 410 can display the distortion-corrected image to the user through a user interface.
[0102] The client 410 may be at least one of a tablet computer, a wearable device (e.g., a smartwatch), a smartphone, a game console, a desktop computer, an e-book reader, an augmented reality (AR) / virtual reality (VR) device, an ultra-mobile personal computer (UMPC), a personal digital assistant (PDA), an in-vehicle device, and a laptop computer. Figure 4B The client 410 shown may generally refer to one of multiple terminals, or a set of multiple terminals, which is not specifically limited in the embodiments of the present application.
[0103] The server 420 is configured to obtain a distorted image from the client 410 and perform the image distortion correction method provided herein on the distorted image to obtain a distortion-corrected image. The server 420 may then send the obtained distortion-corrected image to the client 410. Accordingly, after obtaining the distortion-corrected image, the client 410 may display the distortion-corrected image to the user through a user interface.
[0104] The above-mentioned server 420 can be at least one of a computing device, multiple computing devices, a cloud computing platform and a virtualization center, which is not specifically limited in the embodiments of the present application.
[0105] It should be understood that the above Figure 4A and Figure 4B The application scenarios shown are for illustration only and do not constitute any limitation on the application scenarios of the image distortion correction method provided in the embodiments of the present application. Figure 4A The application scenario shown may also include a greater number of clients 400. Figure 4B The illustrated application scenario may further include a greater number of servers 420 and a greater number of clients 410 .
[0106] The following is the above Figure 4ATaking the application scenario shown as an example, taking a mobile phone as a client executing the image distortion correction method provided in an embodiment of the present application as an example, the change process of the user interface of the mobile phone is described.
[0107] As an example, in response to a user's action on a mobile phone's camera application, the image distortion correction method provided in this application is called to perform distortion correction processing (i.e., dedistortion processing) on a distorted image captured by the mobile phone. In this application scenario, the user may not be aware of the distortion correction process being performed on the mobile phone. The user may act on the mobile phone's camera application, for example, by clicking the mobile phone's camera application with a finger or sending a voice command to the mobile phone to open the camera application.
[0108] For example, Figure 5 As an example, the mobile phone's desktop S1 displays an application icon for each of multiple applications, including an application icon 10 for a camera application. After the user triggers the application icon 10 for the camera application in the desktop S1, the mobile phone displays Figure 5 The shooting interface S2 shown in (2) of the figure shows the person being shot. In response to the user triggering the camera control 20 in the shooting interface S2, the mobile phone can then shoot the subject. Since the mobile phone can execute the image distortion correction method provided in the embodiment of the present application, when the user uses the front camera of the mobile phone to take a photo, regardless of the shooting distance or the size of the field of view, the mobile phone can correct the perspective distortion and wide-angle distortion in the captured image, and finally obtain the following Figure 5 (3) in the figure shows a distortion-corrected image (an image without distortion). It can be understood that in this application, the distortion-corrected image is an image that is closer to the user's actual state, and the distorted image can be an image with perspective distortion or wide-angle distortion, which will not be emphasized below.
[0109] It should be noted that the image distortion correction method provided in this application is not limited to performing distortion correction processing on images captured by the front camera of a mobile phone. Optionally, when a user uses a mobile phone to take a photo, the mobile phone can also activate the rear camera and use the rear camera to capture the user and the environment they are in. The mobile phone can also use the image distortion correction method provided in this application to perform distortion correction processing on the distortion in the image captured by the user through the rear camera to obtain a distortion-corrected image.
[0110] As another example, at least one distorted image is saved in the gallery application of the mobile phone, and the mobile phone uses the image distortion correction method provided in the embodiment of the present application to perform distortion correction processing on the at least one distorted image saved in the gallery application.
[0111] For example, Figure 6Taking Figure (1) in the example, a plurality of application icons corresponding to a plurality of application programs are displayed on the desktop S4 of the mobile phone, and the plurality of application images include an application icon 40 of the gallery application. When a user acts on the application icon 40 of the gallery application in the desktop S4, for example, the user clicks the application icon 40 of the gallery application with a finger, or the user sends a command to the mobile phone to open the gallery application by voice, the mobile phone detects the click operation on the application icon 40 of the gallery application or receives the command to open the gallery application, opens the gallery application, and displays the images stored in the gallery application, see Figure 6 The gallery interface S5 shown in (2) of FIG. 5 includes 4 images, including a distorted image 50 of a male. The portrait in the distorted image 50 is in a rather uncoordinated state. The central area of the face (with the nose as the axis) is swollen, especially the nose at the center (the nose is obviously too large), and the face shape is also deformed (the face is elongated). After the user selects the distorted image 50 in the gallery interface S5, the mobile phone displays the following Figure 6 The user interface S6 shown in (3) of FIG. 1 includes an editing control 60. When the user needs to edit the distorted image in the user interface S6, the user can actively perform a touch operation on the editing control 60, so that the mobile phone displays the following Figure 6 The user interface S7 shown in (4) includes multiple functional controls, including a text control, a filter control, a dedistortion control 71, and a cropping control. When the user needs to dedistort the distorted image in the user interface S7, the user can actively perform a touch operation on the dedistortion control 71, so that the mobile phone performs the image distortion correction method provided by the embodiment of the present application on the distorted image, and then the mobile phone displays the following Figure 6 The user interface S8 including the distortion-corrected image shown in (5) of FIG. 1 is an image obtained by performing the image distortion correction method on the image in the user interface S7. Figure 6 As shown in FIG. 5 , the user interface S8 may further include a save control 81 . After the user performs a touch operation on the save control 81 , the distortion-corrected image in the user interface S8 may be stored in the gallery of the mobile phone.
[0112] It should be noted that the image distortion correction method provided in the embodiment of the present application includes but is not limited to performing distortion correction processing on the distortion (perspective distortion and wide-angle distortion) of human portraits. The image distortion correction method provided in the embodiment of the present application can also perform distortion correction processing on the distortion produced by animals with strong three-dimensional sense (such as cats and / or dogs, etc.), objects (such as human portrait models and / or animal models) and other objects such as buildings.
[0113] The image distortion correction method provided in this application involves the steps of an electronic device calling a dedistortion model to perform dedistortion processing on a distorted image. Figure 7 Shown is how model training works and Figure 8 The model training method shown in the figure describes the model training method of the dedistortion model involved in the image distortion correction method provided in the embodiment of the present application. It should be noted that the application of the dedistortion model will be further introduced below.
[0114] Figure 8 Schematic diagram of a model training method provided in an embodiment of the present application. The model training method provided in an embodiment of the present application can be executed by an electronic device. It is understood that the electronic device can be implemented as software, or a combination of software and hardware. For example, the electronic device in the embodiment of the present application can be, but is not limited to, Figure 4A The client 400 is shown, Figure 4B The server 420 shown, or Figure 15 For ease of description, the following description will be made by taking electronic device A as an example to implement the method provided in the embodiment of the present application. Figure 8 As shown, the model training method provided in the embodiment of the present application includes steps S810 to S850. Steps S810 to S850 are described in detail below.
[0115] In step S810, electronic device A obtains a training data set, where the training data set includes one or more training sample pairs, each training sample pair includes a distorted image A and a grid image A of the distorted image A as a training image, and an undistorted image A as a label image.
[0116] In step S810 above, each training sample in the training dataset is presented in the form of a sample pair, that is, each training sample includes a training image and a label image, wherein the training image includes the distorted image A and a grid image A of the distorted image A, and the label image is the undistorted image A. It should be understood that the undistorted image A is not distorted and is a rectified image of the distorted image A. In other words, the object included in the undistorted image A is the same as the object included in the distorted image A, but the difference is that the shape of the same object included in the two images may be different. For example, the shape of object 1 included in the undistorted image A is not distorted, while the shape of object 1 included in the distorted image A is distorted and elongated.
[0117] For example, the undistorted image A can be Figure 1 The undistorted image shown in (2) is the distorted image A. Figure 1 The distorted image shown in (1) or Figure 1 The distorted image is shown in (3) in the figure. For example, the undistorted image A can be Figure 2 The undistorted image shown in (2) is the distorted image A. Figure 2 The distorted image shown in (1) in the figure.
[0118] Optionally, before electronic device A obtains the training dataset, electronic device A may further perform the step of obtaining a distorted image A. In the embodiment of the present application, the manner in which electronic device A obtains the distorted image A is not specifically limited and may be determined based on actual circumstances. For example, electronic device A may photograph the subject to be photographed to obtain a distorted image A. For example, electronic device A may obtain a distorted image A from a video stream, where the distorted image A is a frame of image in the video stream.
[0119] Optionally, before electronic device A obtains the training dataset, electronic device A may further perform the step of obtaining an undistorted image A. In this embodiment of the present application, the manner in which electronic device A obtains the undistorted image A is not specifically limited and may be determined based on actual circumstances. For example, electronic device A may use image processing software to adjust the captured distorted image A to obtain a distortion-free distorted image A (i.e., undistorted image A).
[0120] The training dataset includes one or more training sample pairs. The number of training sample pairs included in the training dataset can be set based on actual needs and is not specifically limited. When the training dataset includes multiple training sample pairs, the multiple training sample pairs can be the same or different and is not specifically limited. For example, the training dataset can include, but is not limited to, 1, 2, 5, 10, or 20 training sample pairs.
[0121] In one example, two training sample pairs are different in that the two distorted images A corresponding to the two training sample pairs are different, the grid images A of the two distorted images A corresponding to the two training sample pairs are different, and the two label images corresponding to the two training sample pairs are different. For example, the training dataset includes training sample pair 1 and training sample pair 2. The training image in training sample pair 1 is Figure 1 The distorted image shown in (1) in the figure, the label image in the training sample pair 1 is Figure 1 The undistorted image shown in (2) in the figure; the training image in training sample pair 2 is Figure 2 The distorted image shown in (1) of the figure, the label image in the training sample pair 2 is Figure 1 The undistorted image is shown in (2).
[0122] In another example, two training sample pairs are different means that the two distorted images A corresponding to the two training sample pairs are the same, the grid images A of the two distorted images A corresponding to the two training sample pairs are different, and the two label images corresponding to the two training sample pairs are the same.
[0123] It should be understood that the above examples of two different training sample pairs are merely illustrative and do not constitute any limitation. In the embodiments of the present application, when the content (training images and / or label images) corresponding to two training sample pairs differs, the two training sample pairs can be considered to be two different training sample pairs. When the content (training images and / or label images) corresponding to two training sample pairs do not differ, the two training sample pairs can be considered to be the same training sample pair.
[0124] The following describes two implementations (i.e., implementation 1 and implementation 2) for the electronic device A provided in the embodiments of the present application to obtain the grid image A of the distorted image A in each training sample pair. It should be understood that the two implementations described below are merely illustrative and do not constitute any limitation on the methods for obtaining the grid image A of the distorted image A involved in the embodiments of the present application.
[0125] Implementation method 1
[0126] In implementation method 1, the distorted image included as a training image in each training sample pair in the training dataset is a distorted image A captured by the electronic device, and the distorted image A is an image that has not been distorted after capture by the electronic device. Based on this, the grid image A of the distorted image A included as a training image in each training sample pair is a grid image of the distorted image A.
[0127] In an embodiment of the present application, electronic device A can obtain a grid image of distorted image A by performing image gridding processing on distorted image A. Image gridding is a process of converting a continuous image into an image composed of discrete grids. The method of image gridding processing is not specifically limited. For example, electronic device A can adopt a gridding processing method in the prior art. For example, after electronic device A performs gridding processing on distorted image A, the grid image of distorted image A obtained is an image composed of multiple polygonal grids. The shape of the polygons can be set according to actual needs and is not specifically limited to this. For example, the polygons can be, but are not limited to, triangles or quadrilaterals.
[0128] Exemplarily, when the distorted image A only includes a face, electronic device A can perform feature extraction on the face area in the distorted image A to obtain facial feature points; electronic device A obtains a grid image A of the distorted image A based on the facial feature points and the facial constraints of the face.
[0129] Implementation method 2
[0130] In the second implementation, each training sample pair in the training data set includes a distorted image as a training image, which is a distortion-corrected image A' obtained by performing dedistortion processing on the distorted image A captured by the electronic device. Each training sample pair includes a grid image A of the distorted image A as a training image, which is a grid image of the distortion-corrected image A'. The distortion-corrected image A' is a distorted image, and the degree of distortion of the distortion-corrected image A' can be less than that of the distorted image A. It should be understood that in actual applications, due to the low accuracy of the algorithm for dedistorting the distorted image A (referred to as the conventional dedistortion processing algorithm), the resulting distortion-corrected image A' still has some distortion.
[0131] In the embodiment of the present application, there is no specific limitation on the traditional dedistortion processing algorithm, that is, the traditional dedistortion processing algorithm can adopt the distortion processing algorithm provided by the existing technology.
[0132] For example, Figure 9 FIG. 1 shows a schematic diagram of a method for electronic device A to obtain a grid image A of distorted image A based on the collected distorted image A. Figure 9 As shown, after the camera of the electronic device A captures the face of the person and obtains the distorted image A, the process of initializing the grid processing can be performed according to the image size of the distorted image A to obtain Figure 9 The initial grid image of the distorted image A is shown, wherein the initialization grid image includes a plurality of grid units, the plurality of grid units have the same size, and one grid unit can be as follows Figure 9 The image size of the initialization grid image is the same as the image size of the distorted image A. There is no specific limitation on the size of the grid cells in the initialization grid image and it can be customized by the user. For example, the size of the grid cells in the initialization grid image can be (Unit: pixel) size square. Then, electronic device A performs spherical projection processing based on the distorted image A and the initial grid image of the distorted image A to obtain Figure 9The grid image A' is shown. Optionally, the above-mentioned spherical projection can also be replaced by other projection methods, and other projection methods can be set according to the photographed objects included in the distorted image A, and there is no specific limitation on this. For example, the electronic device A can use a spherical projection algorithm to process the head area of the portrait, and use a Mercator algorithm to process the body area to present different deformation amounts, so that the stretching deformation of the head area and the stretching deformation of the body area of the portrait in the distorted image are corrected respectively. Afterwards, the electronic device A performs grid optimization processing on the output grid image A' obtained in the above steps. The grid optimization processing mainly adjusts the grid image A' based on preset constraints, so that the grid image A obtained after the grid optimization processing is more consistent with human vision. The preset constraints include portrait constraints and background constraints, wherein the portrait constraints may include the head area of the portrait and / or the body area of the portrait.
[0133] Optionally, in an embodiment of the present application, after electronic device A acquires distorted image A, electronic device A may first perform data scaling processing on distorted image A, thereby reducing the amount of data in the scaled distorted image A. In this implementation, each training sample pair used by electronic device A to train the initial dedistortion model includes the scaled distorted image A and a grid image of the scaled distorted image A as training images, and the scaled undistorted image A as training labels. This implementation facilitates rapid convergence of the initial dedistortion model and improves model training efficiency.
[0134] The method for performing data scaling processing on the electronic device A is not specifically limited and can be set according to actual conditions.
[0135] In some implementations, electronic device A may utilize Figure 7 The dotted line in the figure shows that the convolutional neural network (CNN) performs data scaling on the distorted image A. In this way, the image features of the distorted image A are retained as much as possible in the scaled distorted image A, which is beneficial to improving the accuracy of the model. For example, the distorted image A is (Unit: pixel) size image, the distorted image A after scaling is (Unit: pixels) The size of the image.
[0136] Optionally, the above data scaling process may also be other methods besides CNN, for example, other methods may be but are not limited to bilinear interpolation or grayscale interpolation.
[0137] In step S820, electronic device A uses the initial encoder in the initial dedistortion model to perform feature extraction processing on the distorted image A in each training sample to obtain a feature map of the distorted image A in each training sample.
[0138] The initial encoder has a feature extraction function, which is used to perform feature extraction on the input distorted image A to extract features of the distorted image A, thereby obtaining a feature map of the distorted image A. It should be understood that electronic device A can restore the distorted image A through decoding based on the feature map of the distorted image A. For example, when the distorted image A includes human object 1 and human object 2, the feature map of the distorted image A includes feature information of human object 1 and feature information of human object 2 included in the distorted image A.
[0139] The feature map of the distorted image A may also be referred to as the feature image of the distorted image A or feature data of the distorted image A.
[0140] In the embodiment of the present application, the structure of the initial encoder in the initial dedistortion model is not specifically limited and can be set according to actual conditions.
[0141] In some implementations, the initial encoder in the initial dedistortion model may be an encoder in a transformer model.
[0142] For example, the structure of the initial encoder in the initial dedistortion model can be seen in Figure 10 The encoder shown. See Figure 10Before electronic device A inputs the distorted image A into the embedding layer (embedding) of the encoder, the distorted image A can be divided into image blocks (patches) of length P, that is, each patch can be regarded as a word (word). It should be understood that a patch is a sub-region of the distorted image A, a patch can be square or rectangular, and the patch has a fixed size. Afterwards, electronic device A performs word embedding processing (embedding) on each word segment (that is, each patch) to obtain a word vector sequence corresponding to the distorted image A. The word vector sequence can be used as the input of the initial encoder in the initial dedistortion model. The word vector sequence can also be first processed by position encoding to add the position information of each word in the word vector sequence to the word vector sequence. For specific operations, please refer to the introduction of the transformer model in the relevant technology, which will not be repeated here. The encoder consists of M layers (M is a positive integer, for example, M = 4), each of which has two sublayers. The first is a multi-head attention layer, which uses a self-attention mechanism to process the word vector sequence to learn the internal relationships within the word vector sequence, that is, the relationships between words (i.e., patches) in the distorted image A. The second is a feedforward layer, which is a simple fully connected network. Residual connections (Add & Norm) are used between each sublayer of the encoder (for example, the multi-head attention layer and the feedforward layer). The output of the first layer in the encoder serves as the input to the second layer. After similar processing, the second layer continues to input to the next layer, and so on.
[0143] In step S830, electronic device A uses the initial decoder in the initial dedistortion model to decode the feature map of the distorted image A in each training sample and the grid image A of the distorted image A in each training sample to obtain the grid image B of the distorted image A in each training sample.
[0144] The initial decoder is used to decode the feature map of the distorted image A output from the initial decoder and the distorted image A input to the initial dedistortion model to obtain a distortion-corrected grid image of the predicted distorted image A, which is abbreviated as grid image B.
[0145] In the embodiment of the present application, the structure of the initial decoder is not specifically limited and can be set according to actual conditions.
[0146] In some implementations, when the initial encoder in the initial dedistortion model is an encoder in a transformer model, the initial decoder in the initial dedistortion model may be a decoder in the transformer model.
[0147] For example, the structure of the initial decoder in the initial dedistortion model can be found in Figure 10 The decoder shown. Figure 10 As shown, the decoder includes M (e.g., M = 4) layers, each of which includes three sublayers. The first sublayer is a masked multi-head self-attention layer, which uses a self-attention mechanism to process the input word vector sequence to learn the internal relationships of the word vector sequence, that is, the relationships between words in the grid image A of the distorted image A. The word vector sequence is a word vector sequence obtained by performing word embedding processing on the image patches (patches) after image segmentation of the grid image A of the distorted image A. Since the training task of the initial dedistortion model in this embodiment of the application is to learn the relationship between the distorted image A and the grid image A of the distorted image A, the decoder randomly masks some of the words in the input grid image A and then performs self-attention processing. The random mask can be a mask operation on a predetermined proportion of the word vectors in the word vector sequence obtained based on the grid image A, which are then processed by the first sublayer of the decoder (i.e., the multi-head self-attention layer). The second sublayer performs attention calculations on the output of the encoder and the output of the first sublayer. The third sublayer is a fully connected layer. Residual connections are used between each of the above sub-layers in the decoder. Figure 10 As shown, the output of each encoder layer is fed into the corresponding decoder layer, which then processes the attention mechanism. This means that the output of the first encoder layer feeds into the first decoder layer, the output of the second encoder layer feeds into the second decoder layer, and the output of the mth encoder layer (m = 1, 2, …, M) feeds into the mth decoder layer. The output of the mth decoder layer passes through a fully connected (linear) layer and then a multi-classification softmax function to calculate the probability that each word (i.e., each patch) in the distorted image A is converted to the corresponding word (i.e., each patch) in the grid image A, resulting in the grid image B.
[0148] In step S840, electronic device A uses the output layer of the initial dedistortion model to obtain a distortion-corrected image A corresponding to the distorted image A in each training sample based on the grid image B of the distorted image A in each training sample and the distorted image A in each training sample.
[0149] In step S840, for each training sample pair, electronic device A uses interpolation processing based on the distorted image A in each training sample pair and the grid image B predicted by the decoder of the initial dedistortion model to restore the distortion-corrected image A. This distortion-corrected image A is more consistent with actual conditions. It should be understood that the distortion-corrected image A is the predicted distortion-corrected image obtained after the initial dedistortion model processes the distorted image A and the grid image A of the distorted image A.
[0150] In the embodiment of the present application, the distortion-corrected image A is an image without distortion, that is, the degree of distortion of the distortion-corrected image A is less than the degree of distortion of the distorted image A.
[0151] In some implementations, the distorted image A includes N pixel points #1, and the grid image B of the distorted image A includes N pixel points #2, wherein the N pixel points #2 correspond one-to-one to the N pixel points #1, and N is a positive integer; the above-mentioned electronic device A uses the output layer of the initial dedistortion model to obtain the distortion-corrected image A corresponding to the distorted image A in each training sample based on the grid image B of the distorted image A in each training sample and the distorted image A in each training sample, including: the electronic device A uses the output layer to update the coordinate value of each corresponding pixel point #1 using the coordinate value of each pixel point #2 to obtain the distortion-corrected image A.
[0152] N is a positive integer. The value of N can be, but is not limited to, a preset value. For example, N can be, but is not limited to, equal to 50.
[0153] The coordinate value of the pixel point #2 is obtained by interpolating the coordinate values of multiple pixel points in the distortion-corrected grid image associated with the pixel point #2.
[0154] It should be noted that the above implementation is described using bilinear interpolation as an example interpolation algorithm used by electronic device A. Optionally, the above interpolation algorithm may be another interpolation algorithm, such as, but not limited to, a nearest neighbor interpolation algorithm or a cubic polynomial interpolation algorithm.
[0155] In step S850, electronic device A adjusts the parameters of the initial dedistortion model according to the difference between the predicted distortion-corrected image A corresponding to the distorted image A in each training sample and the label image in each training sample to obtain a dedistortion model.
[0156] In step S850 , electronic device A adjusting the parameters of the initial dedistortion model can be understood as electronic device A adjusting the weights of the initial dedistortion model. The parameters of the initial dedistortion model include parameters of the initial decoder and parameters of the initial encoder.
[0157] In an embodiment of the present application, electronic device A adjusts the parameters of the initial dedistortion model according to the difference between the predicted distortion-corrected image A corresponding to the distorted image A in each training sample and the label image in each training sample to obtain a dedistortion model, which may include the following steps: electronic device A determines the loss value #1 according to the difference between the predicted distortion-corrected image A corresponding to the distorted image A in each training sample and the label image in each training sample; electronic device A adjusts the parameters of the initial encoder and the parameters of the initial decoder according to the loss value #1 until the preset training conditions are met, ends the model training, and obtains a trained dedistortion model.
[0158] In the above implementation, electronic device A adjusts parameters of the initial dedistortion model based on the difference between the predicted distortion-corrected image A corresponding to the distorted image A in each training sample and the labeled image in each training sample to obtain the dedistortion model. The model training process may include K iterations. During each iteration, electronic device A adjusts parameters of the initial dedistortion model based on the difference between the predicted distortion-corrected image A corresponding to the distorted image A in each training sample and the labeled image in each training sample. Electronic device A determines the initial dedistortion model obtained from the last iteration as the dedistortion model, where K is a positive integer. During each iteration, electronic device A may associate the K iterations with K batches of training sample pairs in the training dataset. The training sample pairs utilized by electronic device A during each iteration include the corresponding batches of training sample pairs. The K batches of training sample pairs are obtained by dividing the training sample pairs in the training dataset. The number of training sample pairs included in each batch of training sample pairs is not limited and can be set according to actual circumstances.
[0159] The preset training conditions may be predefined conditions, and are not specifically limited to these conditions and may be set based on actual circumstances. For example, the preset training conditions may include, but are not limited to, at least one of the following conditions: the loss value of the loss function is less than or equal to a preset threshold, the current number of iterations meets the preset number of iterations requirement, the user actively triggers the termination of the current iteration process, or the current model training time meets the preset training duration requirement.
[0160] During the training of a neural network model, the goal is to ensure that the output of the neural network model is as close as possible to the desired predicted value. This is achieved by comparing the current network's predicted value with the desired target value and then updating the weight vectors of each layer of the neural network based on the difference between the two. (Of course, before the first update, there is usually an initialization process, which pre-configures the parameters for each layer in the neural network model.) For example, if the model's predicted value is too high, the weight vectors are adjusted to predict a lower value. This adjustment is repeated until the neural network model can predict the desired target value or a value very close to the desired target value. Therefore, it is necessary to predefine how to compare the difference between the predicted value and the target value. This is the loss function or objective function, which is an important equation used to measure the difference between the predicted value and the target value. For example, the loss function output value (loss) indicates a greater difference, so training the neural network model becomes a process of minimizing this loss. In the embodiments of this application, the loss function is not specifically limited and can be selected based on user needs. For example, the loss function can be, but is not limited to, a mean square error (MSE) loss function or a mean absolute error (MAE) loss function.
[0161] For example, taking the above loss value #1 as obtained by calculating the MSE loss function, the loss value #1 can be expressed by the following formula:
[0162]
[0163] In the above formula, MSE represents the loss value #1, represents the predicted distortion-corrected image A corresponding to the distorted image A in each training sample, represents the label image in each training sample, It represents the difference between the predicted distortion-corrected image A corresponding to the distorted image A in each training sample and the label image in each training sample.
[0164] In the above step S850, electronic device A adjusts the parameters of the initial decoder and the initial encoder according to the obtained loss value #1 in order to make the loss value #1 as small as possible to better meet the requirements of image distortion correction.
[0165] It should be understood that the above Figure 8 The model training method shown is for illustration only and does not constitute any limitation on the training method of the dedistortion model involved in the image distortion correction method provided in the embodiment of the present application.
[0166] In an embodiment of the present application, an electronic device first extracts features from a distorted image A using an initial encoder in an initial dedistortion model to obtain a feature map of distorted image A. Next, the electronic device decodes the feature map of distorted image A and a grid image A of the distorted image A using an initial decoder in the initial dedistortion model to obtain an adjusted grid image B. Then, the electronic device uses an initial output layer in the initial dedistortion model to obtain a predicted distortion-corrected image A based on the adjusted grid image B and the distorted image A. The electronic device then adjusts the parameters of the initial decoder and encoder based on the difference between the predicted distortion-corrected image A and the label image corresponding to the distorted image A (i.e., the distorted image A without distortion), thereby obtaining a trained dedistortion model. This training method improves the encoding and decoding capabilities of the encoder and decoder of the dedistortion model, resulting in a stronger distortion correction capability. Furthermore, after the electronic device uses this dedistortion model to correct the distortion of the distorted image, the resulting distortion-corrected image better reflects the actual situation, thereby improving the user experience.
[0167] and Figure 8 Corresponding to the model training method provided, Figure 11 is a schematic diagram of an image distortion correction method provided by an embodiment of the present application, wherein the image distortion correction method is Figure 8 The inference process of the dedistortion model obtained by the model training method shown. The image distortion correction method provided in the embodiment of the present application can be executed by an electronic device. It is understandable that the electronic device can be implemented as software, or a combination of software and hardware. For example, the electronic device in the embodiment of the present application can be, but is not limited to, Figure 4A The client 400 is shown, Figure 4B The server 420 shown, or Figure 15 For ease of description, the following description will take electronic device A executing the method provided in the embodiment of the present application as an example.
[0168] For example, Figure 11 As shown, the image distortion correction method provided by the embodiment of the present application includes steps S1110 to S1140. Steps S1110 to S1140 are described in detail below.
[0169] In step S1110 , electronic device A obtains image 1 and grid image 1 of image 1 .
[0170] Image 1 is a distorted image including at least one photographed subject, where the at least one photographed subject may be, but is not limited to, a person, an animal, an object, a landscape, or a building.
[0171] In the embodiment of the present application, there is no specific limitation on the way in which the electronic device A acquires the image 1 and it can be set according to actual conditions.
[0172] In some implementations, the image 1 may be a source image captured by the electronic device A, wherein the source image may be a distorted image. For example, the image 1 may be, but is not limited to, Figure 1 Figure (1) in the figure, or Figure 2 The distorted image shown in (1) in FIG. For example, image 1 may also be a distorted image including a building. For example, image 1 may also be a distorted image including an animal (eg, a dog or a cat, etc.).
[0173] In other implementations, the image 1 may be an image obtained by scaling a source image captured by the electronic device A, and the size of the image 1 is smaller than the size of the source image.
[0174] Grid Image 1 of Image 1 is a grid image obtained based on Image 1.
[0175] In some implementations, the grid image 1 is a grid image obtained by performing gridding processing on the image 1 .
[0176] In other implementations, the grid image 1 is a grid image obtained by performing gridding processing on the initial distortion-corrected image 1 , and the initial distortion-corrected image 1 is an image obtained after performing a preset distortion correction process on the image 1 .
[0177] The method for electronic device A to obtain the grid image 1 of image 1 can be referred to above. Figure 8 The description of implementation method 1 or implementation method 2 in step S810 in the provided model training method will not be repeated here in detail.
[0178] In step S1120 , electronic device A uses the encoder in the dedistortion model to extract features of image 1 to obtain a feature map of image 1 .
[0179] The dedistortion model is based on the above Figure 8 The neural network model obtained by the model training method provided is understood to be the encoder in the dedistortion model based on the above Figure 8 The model training method provided is obtained by training the initial encoder in the initial dedistortion model. For details not described in detail here, please refer to the above Figure 8 The relevant description of step S820 in the training method is provided.
[0180] The feature map of image 1 may also be referred to as the feature image of image 1 or the feature data of image 1 .
[0181] In step S1130 , electronic device A uses the decoder in the dedistortion model to decode the feature map of image 1 and grid image 1 of image 1 to obtain the predicted grid image 2 of image 1 .
[0182] The dedistortion model is based on the above Figure 8 The neural network model obtained by the model training method provided is understood to be the decoder in the dedistortion model based on the above Figure 8 The model training method provided is obtained by training the initial decoder in the initial dedistortion model. For details not described in detail here, please refer to the above Figure 8 The relevant description of step S830 in the training method is provided.
[0183] Electronic device A uses the decoder in the dedistortion model to decode the feature map of image 1 and the grid image 1 of image 1, that is, electronic device A uses the feature map of image 1 through the decoder in the dedistortion model to decode the grid image 1 of image 1.
[0184] In step S1140 , electronic device A uses the output layer of the dedistortion model to perform correction processing on image 1 using the grid image 2 of image 1 to obtain a distortion-corrected image 1 .
[0185] For example, take the image 1 in step S1110 above as Figure 1 For example, the distortion-corrected image 1 in step S1140 is the image 1 in (2). Figure 2 Taking Figure (1) in the figure as an example, the distortion-corrected image 1 in the above step S1140 is Figure (2) in the image 2.
[0186] The contents not described in detail in the above steps S1120 to S1140 can be referred to above. Figure 8 The descriptions of steps S820 to S840 in the provided method are not repeated here.
[0187] It should be understood that the above Figure 11 The image distortion correction method shown is for illustration only and does not constitute any limitation on the image distortion correction method provided in the embodiments of the present application. Figure 11 The image distortion correction method provided is described by taking the case where image 1 is a distorted image as an example. Based on this, the obtained distortion-corrected image 1 and image 1 are two different images. Optionally, when image 1 is an image without distortion, the above-mentioned method can also be performed on image 1. Figure 11 In the image distortion correction method shown, in this implementation, the obtained distortion-corrected image 1 and image 1 are the same image.
[0188] In an embodiment of the present application, the dedistortion model as a generative model in the electronic device is a deep neural network model obtained through deep learning training, and the model robustness of the dedistortion model is high. Based on this, the electronic device uses the dedistortion model to perform image distortion correction processing on the image 1 as a distorted image and the grid image 1 of the distorted image 1. The obtained distortion-corrected image 1 as a distortion-corrected image is more in line with the actual situation and the aesthetics of the human eye, thereby improving the user experience. Specifically, on the one hand, when the grid image 1 of the image 1 is a grid image obtained by directly performing gridding processing on the image 1, the image distortion correction method provided in the embodiment of the present application fine-tunes the grid image 1 based on the dedistortion model obtained by the deep learning method. After that, the distortion-corrected image 1 obtained by correcting the distorted image using the grid image 2 of the predicted image 1 obtained after fine-tuning is more in line with the actual situation and the aesthetics of the human eye. On the other hand, when the grid image 1 of image 1 is an image obtained after performing a traditional distortion correction method (i.e., a preset distortion correction process) on image 1, the image distortion correction method provided in the embodiment of the present application is based on the traditional distortion correction method, and the dedistortion model obtained based on the deep learning method is used to fine-tune the grid parameters (i.e., grid image 1) obtained by the traditional distortion correction method. After that, the distortion-corrected image 1 obtained by correcting the distorted image using the predicted grid image 2 of image 1 obtained after fine-tuning is more in line with the actual situation and the aesthetics of the human eye.
[0189] Figure 12 Schematic diagram of an image distortion correction method provided in an embodiment of the present application. The image distortion correction method provided in an embodiment of the present application can be executed by an electronic device. It is understood that the electronic device can be implemented as software, or a combination of software and hardware. For example, the electronic device in the embodiment of the present application can be, but is not limited to, Figure 4A The client 400 is shown, Figure 4B The server 420 shown, or Figure 15 The electronic device 100 is shown. For ease of description, the following description is based on an example of an electronic device A executing the method provided in the embodiment of the present application. For ease of description, the following description is based on an electronic device as the execution subject to describe the image distortion correction method provided in the embodiment of the present application.
[0190] For example, Figure 12 As shown, the image distortion correction method provided by the embodiment of the present application includes steps S1210 to S1240. Steps S1210 to S1240 are described in detail below.
[0191] In step S1210, the electronic device obtains a distorted image and an initial grid image of the distorted image, wherein the initial grid image is a grid image obtained according to the distorted image.
[0192] A distorted image refers to an image with distortion, and the content of the distorted image is not specifically limited. The distorted image may be an image including at least one photographed object, wherein the at least one photographed object may be, but is not limited to, a person, a building, or an animal (e.g., a dog or a cat). For example, the distorted image in step S1210 may be Figure 1 Figure (1) in the figure, Figure 1 Figure (3) in the figure, or Figure 2 The distorted image shown in (1) in the figure.
[0193] In actual applications, the source image obtained by an electronic device when photographing the object is usually distorted. Therefore, the distorted image in the embodiment of the present application can also be called the source image.
[0194] The initial grid image is a grid image obtained based on the distorted image. The initial grid image is an image composed of multiple polygonal grids. The shape of the polygons can be set according to actual needs and is not specifically limited. For example, the polygons can be, but are not limited to, triangles or quadrilaterals. There is no specific limitation on the method for obtaining the initial grid image based on the distorted image. For example, the electronic device can be, but is not limited to, the aforementioned method. Figure 9 The principle of obtaining the grid image shown above obtains the initial grid image of the distorted image. For example, the electronic device may also process the distorted image based on a method in related art to obtain the initial grid image.
[0195] In some implementations, the initial grid image is a grid image obtained by performing gridding processing on the distorted image.
[0196] In some other implementations, the initial grid image is a grid image obtained by performing gridding processing on the initial distortion-corrected image, wherein the initial distortion-corrected image is an image obtained after performing a preset distortion correction process on the distorted image.
[0197] Since the initial distortion-corrected image is an image obtained after the distorted image is corrected, the distortion degree of the initial distortion-corrected image is smaller than the distortion degree of the distorted image.
[0198] The preset distortion correction process can be understood as an image distortion correction method in related art. There is no specific limitation on the image distortion correction method in related art, that is, the method can correct the distortion in the image. For example, the preset distortion correction process can be, but is not limited to, the Zhang Zhengyou camera calibration method.
[0199] The size of the initial grid image can be smaller than or equal to the size of the distorted image. For example, the size of the initial grid image is (Unit: pixel) size grid image, the distorted image is (Unit: pixel) size of the image. For example, the size of the initial grid image is (Unit: pixel) size grid image, the distorted image is (Unit: pixels) The size of the image.
[0200] In the embodiments of the present application, the method for obtaining a distorted image by an electronic device is not specifically limited. For example, the distorted image can be a distorted image captured by a wide-angle lens of the electronic device, or a distorted panoramic image captured by a panoramic lens of the electronic device. In another example, the distorted image can be a distorted ordinary image captured by an ordinary lens of the electronic device.
[0201] In actual applications, the size of the image obtained by the electronic device when photographing the object to be photographed is large, and the amount of computation required to process the image is large. Based on this, in some implementations, the electronic device obtains a distorted image, including: the electronic device scales the obtained initial distorted image to obtain a distorted image, wherein the size of the distorted image is smaller than the size of the initial distorted image.
[0202] The distorted image retains the characteristics of the initial distorted image, that is, the initial distorted image can be restored based on the distorted image. The size of the distorted image is smaller than the size of the initial distorted image, that is, the amount of data in the distorted image is smaller than the amount of data in the initial distorted image. For example, the initial distorted image is (Unit: pixel) size image, the distorted image is (Unit: pixels) The size of the image.
[0203] The method by which the electronic device performs scaling processing on the initial distorted image is not specifically limited. For example, the electronic device may perform scaling processing on the initial distorted image using a convolutional neural network, where the convolutional neural network and the dedistortion model may be, but are not limited to, two independent models. For example, the electronic device may also perform scaling processing using algorithms other than convolutional neural networks.
[0204] For example, the above Figure 11 The electronic device A in step S1110 of the provided image distortion correction method is a specific example of the electronic device in the above-mentioned step S1210, the image 1 in step S1110 is a specific example of the distorted image in step S1210, and the grid image 1 of the image 1 in step S1110 is a specific example of the initial grid image of the distorted image in step S1210.
[0205] In step S1220, the electronic device performs feature extraction processing on the distorted image using the dedistortion model to obtain feature data of the distorted image.
[0206] The dedistortion model is a deep neural network model obtained through training. There is no specific limitation on the model structure of the dedistortion model, and it can be selected according to the actual scenario requirements. In some implementations, the dedistortion model is a converter model in the generative model. For example, Figure 10 The transformer model shown can be a specific example of a dedistortion model. Figure 10 For details not described in detail, please refer to the relevant description in the above step S820. In other implementations, the dedistortion model is a U-Net network model.
[0207] The feature data of the distorted image includes important features of the distorted image, that is, the distorted image can be successfully restored based on the feature data of the distorted image. The feature data of the distorted image can be presented in a form that is not limited to a feature image.
[0208] Exemplarily, continuing with the example that the image 1 in the above step S1110 is a specific example of the distorted image in step S1210, the feature map of the image 1 in the above step S1120 is a specific example of the feature data of the distorted image in step S1210.
[0209] Optionally, before the electronic device performs the above step S1220, the electronic device may further perform a step of model training to obtain a dedistortion model. The training method for the electronic device to perform model training to obtain the dedistortion model is not specifically limited.
[0210] Exemplarily, in some implementations, before the electronic device performs feature extraction processing on the distorted image through the dedistortion model to obtain feature data of the distorted image, the electronic device may further perform the following operations: the electronic device obtains at least one training sample pair, wherein the at least one training sample pair includes a training distorted image and a first grid image of the training distorted image as training data, and a label image as label data, the first grid image is a grid image obtained based on the training distorted image, and the label image is an image without distortion obtained based on the training distorted image; the electronic device performs feature extraction processing on the training distorted image through the initial dedistortion model to obtain feature data of the training distorted image; the electronic device uses the feature data of the training distorted image to decode the first grid image of the training distorted image through the initial dedistortion model to obtain a second grid image of the training distorted image; the electronic device uses the second grid image of the training distorted image to correct the training distorted image through the initial dedistortion model to obtain a distortion-corrected image corresponding to the training distorted image; the electronic device adjusts the parameters of the initial dedistortion model according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model.
[0211] The at least one training sample pair can be understood as a training data set used to train the initial dedistortion model. The number of the at least one training sample pair is not specifically limited and can be set according to actual circumstances. For example, the at least one training sample pair can include, but is not limited to, 1, 10, or 20 training sample pairs.
[0212] In an embodiment of the present application, when there are multiple training sample pairs, the multiple training sample pairs may be the same or different. Any one of the at least one training sample pairs includes a training distorted image and a first grid image of the training distorted image as training data, and a label image as label data. Based on this, when there is a difference in the content corresponding to the two training sample pairs (i.e., the training image and / or the label image), the two training sample pairs can be considered to be two different training sample pairs. When there is no difference in the content corresponding to the two training sample pairs (i.e., the training image and / or the label image), the two training sample pairs can be considered to be the same training sample pair.
[0213] Exemplarily, training sample pair 1 includes training distorted image 1 and grid image 1 of training distorted image 1 as training data, and label image 1 as label data; training sample pair 2 includes training distorted image 1 and grid image 1 of training distorted image 1 as training data, and label image 1 as label data; therefore, training sample pair 1 and training sample pair 2 are the same training sample pair.
[0214] Exemplarily, training sample pair 1 includes training distorted image 1 and grid image 1 of training distorted image 1 as training data, and label image 1 as label data; training sample pair 2 includes training distorted image 2 and grid image 2 of training distorted image 2 as training data, and label image 2 as label data, wherein training distorted image 1 and training distorted image 1 are different, grid image 1 and grid image 2 are different, and label image 1 and label image 2 are different; therefore, training sample pair 1 and training sample pair 2 are two different training sample pairs.
[0215] The label image is an undistorted image obtained based on the distorted training image. The method for obtaining the label image based on the distorted training image is not specifically limited. For example, the distorted training image (which has distortion) can be dedistorted using image processing software to obtain an image that conforms to both actual conditions and human aesthetics. This image that conforms to actual conditions and human aesthetics can then be used as the label image.
[0216] The electronic device in the above implementation method adjusts the parameters of the initial dedistortion model according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model. Exemplarily, the following steps may be included: the electronic device determines the target loss value according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image corresponding to the training distorted image; the electronic device adjusts the parameters of the initial encoder and the parameters of the initial decoder according to the target loss value until the preset training conditions are met, ends the model training, and obtains the trained dedistortion model.
[0217] The target loss value can be calculated using a loss function. The loss function is not specifically limited and can be set according to the actual scenario. For example, the loss function can be, but is not limited to, an MSE loss function or a MAE loss function.
[0218] The preset training conditions may be predefined conditions, and are not specifically limited to these conditions and may be set based on actual circumstances. For example, the preset training conditions may include, but are not limited to, at least one of the following conditions: the loss value of the loss function is less than or equal to a preset threshold, the current number of iterations meets the preset number of iterations requirement, the user actively triggers the termination of the current iteration process, or the current model training time meets the preset training duration requirement.
[0219] The initial dedistortion model in the above implementation method includes an initial encoder, an initial decoder and an output layer. Specifically, the electronic device performs feature extraction processing on the training distorted image through the initial encoder in the initial dedistortion model to obtain a feature map of the training distorted image; the electronic device uses the feature map of the training distorted image to decode the first grid image of the training distorted image through the initial decoder in the initial dedistortion model to obtain a second grid image of the training distorted image; the electronic device uses the second grid image of the training distorted image to correct the training distorted image through the output layer in the initial dedistortion model to obtain a distortion-corrected image corresponding to the training distorted image; the electronic device adjusts the parameters of the initial encoder and the parameters of the initial decoder according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model.
[0220] For example, the above Figure 8 The initial dedistortion model in step S820 of the provided model training method is a specific example of the initial dedistortion model in the above implementation. The initial encoder in step S820 is a specific example of the initial encoder in the above implementation. The initial decoder in step S830 is a specific example of the initial decoder in the above implementation. The output layer in step S840 is a specific example of the output layer in the above implementation. For details not described in detail here, please refer to the above. Figure 8Relevant description in the provided model training method.
[0221] In step S1230, the electronic device decodes the initial grid image using the feature data of the distorted image through the dedistortion model to obtain a distortion-corrected grid image of the distorted image.
[0222] The dedistortion model is a trained neural network model with decoding capabilities. Therefore, after the electronic device decodes the initial grid image using the feature data of the distorted image through the dedistortion model, it can obtain a restored distortion-corrected grid image. The distortion-corrected grid image can be understood as a grid image without distortion.
[0223] For example, the above Figure 11 The feature map of image 1 in step S1130 of the provided image distortion correction method is a specific example of the feature data of the distorted image in the above-mentioned implementation method, the grid image 1 of image 1 in the above-mentioned step S1130 is a specific example of the initial grid image in the above-mentioned implementation method, and the grid image 2 of image 1 in the above-mentioned step S1130 is a specific example of the distortion-corrected grid image of the distorted image in the above-mentioned implementation method. For matters not described in detail here, please refer to the relevant description above.
[0224] In step S1240, the electronic device corrects the distorted image using the distortion correction grid image through the dedistortion model to obtain a distortion corrected image.
[0225] The distortion-corrected image is an image obtained after performing distortion correction processing on the distorted image. The distortion-corrected image can be understood as an image without any distortion.
[0226] For example, continuing to take the example that the image 1 in the above step S1110 is a specific example of the distorted image in step S1210, the distortion-corrected image 1 in the above step S1140 is a specific example of the distortion-corrected image in step S1240.
[0227] In some implementations, the distorted image includes N first pixel points, and the distortion correction grid image includes N second pixel points, wherein the N second pixel points correspond one-to-one to the N first pixel points, and N is a positive integer; the electronic device executes the above-mentioned step S1240, that is, the electronic device uses the distortion correction grid image through the dedistortion model to correct the distorted image to obtain the distortion corrected image. Exemplarily, the following steps may be included: the electronic device uses the dedistortion model to update the coordinate value of each corresponding first pixel point using the coordinate value of each second pixel point to obtain the distortion corrected image.
[0228] In the above implementation, the distorted image includes N first pixel points, and at the same time, the distortion-corrected grid image includes N second pixel points, that is, the number of pixel points included in the distorted image is the same as the number of pixel points included in the distortion-corrected grid image. It can be understood that the size of the distorted image is the same as the size of the distortion-corrected grid image.
[0229] Optionally, the size of the distorted image and the size of the distortion-corrected grid image may be different. In this implementation, the number of first pixel points included in the distorted image is greater than the number of second pixel points in the distortion-corrected grid image, that is, the number of first pixel points included in the distorted image is greater than N.
[0230] Optionally, the coordinate value of the second pixel point is obtained by interpolating the coordinate values of multiple pixel points in the distortion-corrected grid image associated with the second pixel point.
[0231] The above interpolation processing algorithm is not specifically limited and can be selected according to needs or scenarios. For example, the interpolation algorithm can be, but is not limited to, bilinear interpolation or grayscale interpolation.
[0232] The above describes the image distortion correction method provided in an embodiment of the present application in combination with steps S1210 to S1240. Below, two different application scenarios of the above-mentioned image distortion correction method are introduced. It should be understood that the application scenarios described below are only for illustration and do not constitute any limitation on the application scenarios to which the image distortion correction method provided in the embodiment of the present application is applicable.
[0233] In one application scenario, the image distortion correction method of steps S1210 to S1240 is applied to an electronic device including a camera, and the electronic device obtains a distorted image, including: the electronic device displays a shooting interface; in response to a shooting operation on the shooting interface, the electronic device obtains a distorted image through the camera; after the electronic device corrects the distorted image using a distortion correction grid image through a de-distortion model to obtain a distortion-corrected image, the electronic device can also display an interface including the distortion-corrected image.
[0234] For example, Figure 5 The user interface of the mobile phone shown may be the user interface of the electronic device in the above application scenario. For details not described in detail here, please refer to the above Figure 5 Related description in .
[0235] In another application scenario: the image distortion correction method of steps S1210 to S1240 is applied to an electronic device including a gallery application, and the electronic device obtains a distorted image, including: the electronic device displays the interface of the gallery application; in response to a selection operation for the distorted image in the interface of the gallery application, the electronic device obtains the distorted image; after the electronic device corrects the distorted image using a distortion correction grid image through a dedistortion model to obtain a distortion corrected image, the electronic device can also display an interface including the distortion corrected image.
[0236] For example, Figure 6 The user interface of the mobile phone shown may be the user interface of the electronic device in the above application scenario. For details not described in detail here, please refer to the above Figure 6 Related description in .
[0237] Optionally, the gallery application may also be other applications in the electronic device except the gallery application. For example, the other applications may be, but are not limited to, chat applications or image processing applications.
[0238] When introducing steps S1210 to S1240 above, the electronic device uses the dedistortion model to process the distorted image and the initial grid image of the distorted image to obtain the distortion-corrected image as an example. In some implementations, the dedistortion model includes a decoder, an encoder, and an output layer. For example, Figure 10 The structure of the encoder shown may be an example of the structure of the encoder included in the dedistortion model. Figure 10 The structure of the decoder shown can be an example of the structure of the decoder included in the dedistortion model. In this implementation, the electronic device performs feature extraction processing on the distorted image through the dedistortion model to obtain feature data of the distorted image, including: the electronic device performs feature extraction processing on the distorted image through the encoder to obtain feature data of the distorted image; the electronic device uses the feature data of the distorted image to decode the initial grid image through the dedistortion model to obtain a distortion-corrected grid image of the distorted image, including: the electronic device uses the feature data of the distorted image to decode the initial grid image through the decoder to obtain a distortion-corrected grid image; the electronic device uses the distortion-corrected grid image through the dedistortion model to correct the distorted image to obtain a distortion-corrected image, including: the electronic device uses the distortion-corrected grid image through the output layer to correct the distorted image to obtain a distortion-corrected image.
[0239] It should be understood that the above Figure 12 The image distortion correction method shown is for illustration only and does not constitute any limitation on the image distortion correction method provided in this application. Figure 12The image distortion correction method provided is described by taking the case where the image to be processed in step S1210 is a distorted image (with distortion) as an example. Based on this, the distortion-corrected distorted image and the distorted image obtained after the electronic device performs the image distortion correction method on the distorted image are two different images. Optionally, when the image to be processed in step S1210 is an image without distortion, the above-mentioned correction method can also be performed on the image without distortion. Figure 12 In the image distortion correction method shown in FIG, in this implementation, the obtained distortion-corrected distorted image and the image without distortion are the same image.
[0240] In an embodiment of the present application, an electronic device uses a dedistortion model to extract features from a distorted image to obtain feature data of the distorted image. Subsequently, the electronic device uses the dedistortion model to decode the feature data of the distorted image and the initial grid image of the distorted image to obtain a distortion-corrected grid image. Since the distortion-corrected grid image is a grid image obtained by correcting the initial grid image based on the feature data of the distorted image, the distortion-corrected grid image is more consistent with the actual situation. Thereafter, the electronic device uses the distortion-corrected grid image to correct the distorted image using the dedistortion model. The resulting distortion-corrected image is more consistent with the actual situation and the aesthetics of the human eye, thereby improving the user experience.
[0241] Combined with the above Figures 1 to 12 , describes in detail the application scenario and image distortion correction method of the embodiment of the present application, and will be combined with Figure 13 Describing the device embodiments of the present application. It should be understood that the image distortion correction device in the embodiments of the present application can perform the various image distortion correction methods of the aforementioned embodiments of the present application, that is, the specific working processes of the following various products can refer to the corresponding processes in the aforementioned method embodiments.
[0242] Figure 13 Schematic diagram of an image distortion correction device provided by an embodiment of the present application. Figure 13 The image distortion correction device 1300 shown includes a processing unit 1310. The function of the processing unit 1310 is described below.
[0243] The processing unit 1310 is used to: obtain a distorted image and an initial grid image of the distorted image, wherein the initial grid image is a grid image obtained based on the distorted image; perform feature extraction processing on the distorted image using a dedistortion model to obtain feature data of the distorted image; perform decoding processing on the initial grid image using the feature data of the distorted image using the dedistortion model to obtain a distortion-corrected grid image of the distorted image; and perform correction processing on the distorted image using the distortion-corrected grid image using the dedistortion model to obtain a distortion-corrected image.
[0244] In a possible implementation, the initial grid image is a grid image obtained by performing gridding processing on the distorted image.
[0245] In another possible implementation, the initial grid image is a grid image obtained by performing gridding processing on the initial distortion-corrected image, wherein the initial distortion-corrected image is an image obtained after performing a preset distortion correction process on the distorted image.
[0246] In another possible implementation, the distorted image includes N first pixel points, and the distortion-corrected grid image includes N second pixel points, wherein the N second pixel points correspond one-to-one to the N first pixel points, and N is a positive integer; the processing unit 1310 is further used to: through the dedistortion model, use the coordinate value of each second pixel point to update the coordinate value of each corresponding first pixel point to obtain the distortion-corrected image.
[0247] In another possible implementation, the coordinate value of the second pixel point is obtained by interpolating the coordinate values of multiple pixel points in the distortion-corrected grid image associated with the second pixel point.
[0248] In another possible implementation, the processing unit 1310 is further configured to: perform scaling processing on the acquired initial distorted image to obtain the distorted image, wherein the size of the distorted image is smaller than the size of the initial distorted image.
[0249] In another possible implementation, the processing unit 1310 is further configured to perform the following operations before performing feature extraction processing on the distorted image through the dedistortion model to obtain feature data of the distorted image: obtaining at least one training sample pair, wherein the at least one training sample pair includes a training distorted image as training data and a first grid image of the training distorted image, and a label image as label data, the first grid image is a grid image obtained based on the training distorted image, and the label image is an image without distortion obtained based on the training distorted image; performing feature extraction processing on the training image through the initial dedistortion model; The training distorted image is subjected to feature extraction processing to obtain feature data of the training distorted image; the first grid image of the training distorted image is decoded by the initial dedistortion model using the feature data of the training distorted image to obtain a second grid image of the training distorted image; the training distorted image is corrected by the initial dedistortion model using the second grid image of the training distorted image to obtain a distortion-corrected image corresponding to the training distorted image; and the parameters of the initial dedistortion model are adjusted according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model.
[0250] In another possible implementation, the initial dedistortion model includes an initial encoder, an initial decoder and an output layer, and; the processing unit 1310 is also used to: obtain at least one training sample pair, wherein the at least one training sample pair includes a training distorted image as training data and a first grid image of the training distorted image, and a label image as label data, the first grid image is a grid image obtained based on the training distorted image, and the label image is an image without distortion obtained based on the training distorted image; perform feature extraction processing on the training distorted image by the initial encoder to obtain feature data of the training distorted image; perform decoding processing on the first grid image of the training distorted image by the initial decoder using the feature data of the training distorted image to obtain a second grid image of the training distorted image; perform correction processing on the training distorted image by the initial dedistortion model using the second grid image of the training distorted image to obtain a distortion-corrected image corresponding to the output layer; adjust the parameters of the initial encoder and the parameters of the initial decoder according to the difference between the distortion-corrected image corresponding to the training distorted image and the label image to obtain the dedistortion model.
[0251] In another possible implementation, the first grid image is a grid image obtained by performing gridding processing on the training distorted image.
[0252] In another possible implementation, the first grid image is a grid image obtained by gridding an initial training distortion-corrected image, wherein the initial training distortion-corrected image is an image obtained by performing a preset distortion correction process on the training distortion image.
[0253] In another possible implementation, the dedistortion model is a converter model in a generative model.
[0254] In another possible implementation, the dedistortion model includes an encoder, a decoder and an output layer, and; the processing unit 1310 is also used to: perform feature extraction processing on the distorted image through the encoder to obtain feature data of the distorted image; use the feature data of the distorted image to decode the initial grid image through the decoder to obtain a distortion-corrected grid image; use the distortion-corrected grid image to correct the distorted image through the output layer to obtain a distortion-corrected image.
[0255] In another possible implementation, the device is applied to an electronic device including a camera, and the processing unit 1310 is further used to: display a shooting interface; obtain the distorted image through the camera in response to a shooting operation on the shooting interface; the processing unit 1310 is also used to perform the following operations after correcting the distorted image using the distortion correction grid image through the dedistortion model to obtain the distortion corrected image: display an interface including the distortion corrected image.
[0256] In another possible implementation, the device is applied to an electronic device including a gallery application, and the processing unit 1310 is further used to: display the interface of the gallery application; obtain the distorted image in response to a selection operation of the distorted image in the interface of the gallery application; the processing unit 1310 is further used to perform the following operations after the distorted image is corrected using the distortion correction grid image through the dedistortion model to obtain the distortion corrected image: display the interface including the distortion corrected image.
[0257] It should be noted that the image distortion correction device 1300 is implemented in the form of a functional unit. The term "unit" here can be implemented in the form of software and / or hardware, and is not specifically limited to this.
[0258] For example, a "unit" may be a software program, a hardware circuit, or a combination of the two that implements the aforementioned functionality. The hardware circuit may include an application specific integrated circuit (ASIC), an electronic circuit, a processor (e.g., a shared processor, a dedicated processor, or a group of processors) and memory for executing one or more software or firmware programs, combined logic circuits, and / or other suitable components that support the described functionality.
[0259] Therefore, the units of each example described in the embodiments of this application can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0260] The following describes the software system of electronic device 100 suitable for use with the image distortion correction method provided in the embodiments of this application. The software system of an electronic device can adopt a layered architecture, an event-driven architecture, a microkernel architecture, a microservice architecture, or a cloud architecture. This embodiment of the application uses a layered architecture as an example to exemplify the software system of electronic device 100.
[0261] For example, Figure 14 Schematic diagram of a software system of an electronic device 100 provided in an embodiment of the present application. Figure 14The software system adopts a layered architecture. The layered architecture divides the software into several layers, each with a clear role and division of labor. Layers communicate with each other through software interfaces. In some embodiments, the Android system is divided into five layers: from top to bottom, the application layer 210, the application framework layer 220, the Android runtime and core library layer 230, the hardware abstraction layer (HAL) 240, and the kernel layer 250.
[0262] The application layer 210 may include a series of application packages. For example, the application package may include applications such as gallery, image processing software, chat, video, voice assistant, clipping, camera, call, map, navigation, calendar, Bluetooth, music, etc.
[0263] Each of the aforementioned applications can be used to generate application data, and each of the aforementioned applications can include more specific functional modules. For example, a gallery can include a service module and a notification module, where the service module includes a control for performing image distortion correction on an image. For example, a camera can include a photo module, which is used to capture a subject to obtain an image (e.g., a distorted image, an initially distorted image, or a distortion-corrected image).
[0264] The application framework layer 220 provides an application programming interface (API) and a programming framework for the applications in the application layer. The application framework layer 220 includes some predefined functions.
[0265] like Figure 14 As shown, the application framework layer 220 may include a window manager, a notification manager, an activity manager, an input manager, a view system, a content provider, a resource manager, and the like.
[0266] The window manager provides window management services (WMS). WMS can be used for window management, window animation management, surface management, and as a transfer station for the input system.
[0267] Content providers are used to store and retrieve data and make it accessible to applications. This data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.
[0268] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images. For example, a display interface can be, but is not limited to, Figure 5 and / or Figure 6 The user interface shown.
[0269] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.
[0270] The Notification Manager allows applications to display notifications in the status bar. These messages can be displayed briefly and then disappear automatically without user interaction. For example, the Notification Manager is used to notify users of completed downloads and message reminders. The Notification Manager can also display notifications in the top status bar of the system as icons or scrolling text, such as notifications from background applications, or as dialog windows on the screen. Examples include text messages in the status bar, beeps, vibrations on electronic devices, and flashing indicator lights.
[0271] The activity manager can provide activity management services (AMS), which can be used to start, switch, and schedule system components (such as activities, services, content providers, and broadcast receivers) as well as manage and schedule application processes.
[0272] The input manager provides input management services (IMS), which can be used to manage system input, such as touch screen input, key input, and sensor input. The IMS retrieves events from input device nodes and, through interaction with the WMS, distributes the events to the appropriate window.
[0273] The Android Runtime includes core libraries and a virtual machine. The Android Runtime is responsible for scheduling and management of the Android system.
[0274] The core library consists of two parts: one part is the function that the programming language (for example, Java) needs to call, and the other part is the Android core library.
[0275] The application layer 210 and the application framework layer 220 run in a virtual machine. The virtual machine executes the programming files (e.g., Java files) of the application layer 210 and the application framework layer 220 as binary files. The virtual machine manages object lifecycles, stacks, threads, security, exceptions, and garbage collection.
[0276] The core library layer 230 may include multiple functional modules, such as a surface manager, a media framework, libc, SQLite, OpenGL ES, and Webkit.
[0277] The surface manager is used to manage the display subsystem and provide the fusion of two-dimensional (2D) and three-dimensional (3D) layers for multiple applications.
[0278] The media framework supports playback and recording of a variety of common audio and video formats, as well as static image files.
[0279] libc (C library) is the standard library for the C language. It's a low-level library in the system and is implemented through Linux system calls. For example, libc can be used to connect to and disconnect from the camera service, set camera shooting parameters, start and stop previewing, and take pictures.
[0280] The Hardware Abstraction Layer (HAL) 240 is an interface layer located between the operating system kernel and upper-level software. Its purpose is to abstract the hardware. The Hardware Abstraction Layer is an abstract interface driven by the device kernel, which is used to implement an application programming interface that provides access to the underlying device to the higher-level Java API framework. The HAL contains multiple library modules, such as the camera HAL (for example, aperture, time-of-flight sensor, lens, or focus motor), the Vendor pod, the display, Bluetooth, and audio. Each library module implements an interface for a specific type of hardware component. It can be understood that the camera HAL can provide the camera FWK with an interface to access hardware components such as the camera. The Vendor pod can provide the media FWK with an interface to access hardware components such as the encoder. When the system framework layer API requires access to the hardware of the portable device, the Android operating system will load the library module for that hardware component.
[0281] The kernel layer 250 is the foundation of the Android operating system, and all of the Android operating system's ultimate functions are performed through the kernel layer. Kernel layer 250 includes at least a display driver, an audio driver, a camera driver, and a Bluetooth driver. The camera driver is used to drive the camera of electronic device 100 for shooting, and the display driver is used to display images (e.g., distortion-corrected images) on the display panel.
[0282] It should be noted that the application provides Figure 14 The software structure diagram of the electronic device shown is merely an example and does not limit the specific module divisions within the different layers of the Android operating system. For details, please refer to the conventional art description of the Android operating system software structure. Furthermore, the image distortion correction method provided in this application can also be implemented based on other operating systems (e.g., iOS or Hongmeng), and this application will not further cite individual examples.
[0283] The following introduces the hardware structure of the electronic device 100 suitable for the image distortion correction method provided in the embodiment of the present application.
[0284] For example, Figure 15 Schematic diagram of the hardware structure of an electronic device 100 provided in an embodiment of the present application.
[0285] Figure 15 The electronic device 100 shown can be a mobile phone, a smart screen, a tablet computer, a wearable electronic device (such as a smart watch, etc.), an in-vehicle electronic device, an augmented reality (AR) device, a virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), a projector, an in-vehicle device, etc. The embodiment of the present application does not impose any restrictions on the specific type of the electronic device 100.
[0286] The electronic device 100 may include, but is not limited to, a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, an earphone interface 170D, a sensor module 180, a button 190, a motor 191, an indicator 192, a camera 193, a display 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, an air pressure sensor 180C, a magnetic sensor 180D, an acceleration sensor 180E, a distance sensor 180F, a proximity light sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.
[0287] It should be noted that Figure 15 The hardware structure of the electronic device shown does not constitute a specific limitation on the electronic device 100. In other embodiments of the present application, the electronic device 100 may include Figure 15 More or fewer components than those shown, or the electronic device 100 may include Figure 15 Combinations of some of the components shown, or alternatively, the electronic device 100 may include Figure 15 Subassemblies of some of the components shown. Figure 15 The components shown can be implemented in hardware, software, or a combination of software and hardware.
[0288] The processor 110 can implement the functions of the processor 110 in various possible implementations of the electronic device 100. The processor 110 may include one or more processing units. For example, the processor 110 may include at least one of the following processing units: an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and a neural-network processing unit (NPU). The different processing units may be independent devices or integrated devices.
[0289] The controller may be the nerve center and command center of the electronic device 100. The controller may generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.
[0290] The processor 110 is used to perform the following steps: obtaining a distorted image and an initial grid image of the distorted image, wherein the initial grid image is a grid image obtained based on the distorted image; performing feature extraction processing on the distorted image using a dedistortion model to obtain feature data of the distorted image; decoding the initial grid image using the feature data of the distorted image using the dedistortion model to obtain a distortion-corrected grid image of the distorted image; and correcting the distorted image using the distortion-corrected grid image using the dedistortion model to obtain a distortion-corrected image.
[0291] Processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in processor 110 is a cache memory. This memory can store instructions or data that have just been used or are being recycled by processor 110. If processor 110 needs to use the same instruction or data again, it can directly access the memory. This avoids duplicate accesses, reduces processor 110 latency, and thus improves system efficiency.
[0292] It should be understood that Figure 15 The connection relationship between the modules shown is only for illustrative purposes and does not limit the connection relationship between the modules of the electronic device 100. Optionally, the modules of the electronic device 100 may also adopt a combination of multiple connection methods in the above embodiments.
[0293] The charging management module 140 is configured to receive power from a charger. The charger can be either a wireless charger or a wired charger. In some wired charging embodiments, the charging management module 140 can receive current from the wired charger via the USB interface 130. In some wireless charging embodiments, the charging management module 140 can receive electromagnetic waves from the wireless charging coil of the electronic device 100 (the current path is shown as a dashed line). While charging the battery 142, the charging management module 140 can also provide power to the electronic device 100 via the power management module 141.
[0294] The power management module 141 is used to connect the battery 142, the charging management module 140, and the processor 110. The power management module 141 receives input from the battery 142 and / or the charging management module 140 and provides power to the processor 110, the internal memory 121, the display 194, the camera 193, and the wireless communication module 160. The power management module 141 can also monitor parameters such as battery capacity, battery cycle count, and battery health status (e.g., leakage, impedance). Optionally, the power management module 141 can be provided within the processor 110, or the power management module 141 and the charging management module 140 can be provided within the same device.
[0295] Electronic device 100 can implement display functionality through a GPU, display screen 194, and an application processor. A GPU is a microprocessor for image processing that connects display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations for graphics rendering. Processor 110 may include one or more GPUs that execute program instructions to generate or modify display information.
[0296] The display screen 194 is used to display an image, for example, the image may be, but is not limited to, the distorted image, the initial distortion-corrected image, or the distortion-corrected image described above. Optionally, the display screen 194 is also used to display an application interface, for example, the application interface may be, but is not limited to, Figure 5 or Figure 6 The application interface is shown.
[0297] Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a mini light-emitting diode (Mini LED), a micro light-emitting diode (Micro LED), a micro OLED, or a quantum dot light-emitting diode (QLED). In some embodiments, electronic device 100 may include one or Q display screens 194, where Q is a positive integer greater than 1.
[0298] The electronic device 100 can implement a shooting function through an ISP, a camera 193, a video codec, a GPU, a display screen 194, and an application processor.
[0299] The ISP processes data fed back by camera 193. For example, when taking a photo, the shutter is opened, and light is transmitted through the lens to the camera's photosensitive element. The light signal is converted into an electrical signal, which is then passed to the ISP for processing and converted into a visible image. The ISP can perform algorithmic optimization on image noise, brightness, and color. It can also optimize parameters such as exposure and color temperature of the captured scene. In some embodiments, the ISP can be located within camera 193.
[0300] The camera 193 is used to capture still images or videos. For example, the still image can be the distorted image described above. For example, the video can be a video stream of the distorted image obtained as described above. The object generates an optical image through the lens and projects it onto the photosensitive element. The photosensitive element can be a charge coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, and then transmits the electrical signal to the ISP to be converted into a digital image signal. The ISP outputs the digital image signal to the DSP for processing. The DSP converts the digital image signal into an image signal in a standard RGB, YUV or other format. The image signal can then be displayed through the display screen 194, and / or the image signal can be saved to the internal memory 121 or the external memory.
[0301] In some embodiments, the electronic device 100 may include L cameras 193 , each of the L cameras 193 may be a camera or a rear camera, and L is a positive integer greater than 1.
[0302] In some embodiments, camera 193 may include a camera for collecting images required for facial recognition, such as an infrared camera or other camera. The camera for collecting images required for facial recognition is generally located on the front of the electronic device, such as above the touch screen, but may also be located in other locations, and this embodiment of the application is not limited thereto.
[0303] In some embodiments, the camera 193 includes, but is not limited to, an optical camera, an infrared camera, and a depth camera, and can be a monocular camera or a multi-camera camera. The camera lens can be a standard lens, a wide-angle lens, an ultra-wide-angle lens, a fisheye lens, a telephoto lens, or a combination of these lenses.
[0304] In the embodiment of the present application, the image signal output by the camera 193 may be referred to as a “source image.” The source image may be output to a processor to execute the image distortion correction method provided in the present application.
[0305] The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. For example, when the electronic device 100 selects a frequency point, the digital signal processor is used to perform Fourier transform on the frequency point energy.
[0306] External memory interface 120 can be used to connect an external memory card, such as a secure digital (SD) card, to expand the storage capacity of electronic device 100. The external memory card communicates with processor 110 via external memory interface 120 to implement data storage. For example, files such as music and videos can be stored on the external memory card.
[0307] The internal memory 121 can be used to store computer executable program code, which includes instructions. The internal memory 121 may include a program storage area and a data storage area. The program storage area may store an operating system and application programs required for at least one function (for example, a sound playback function and an image playback function). The data storage area may store data created during the use of the electronic device 100 (for example, audio data and a phone book). In addition, the internal memory 121 may include a high-speed random access memory and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, and a universal flash storage (UFS). The processor 110 executes various processing methods of the electronic device 100 by running instructions stored in the internal memory 121 and / or instructions stored in a memory provided in the processor.
[0308] The gyro sensor 180B can be used to determine the motion posture of the electronic device 100. In some embodiments, the angular velocity of the electronic device 100 around three axes (i.e., the x-axis, y-axis, and z-axis) can be determined by the gyro sensor 180B. The gyro sensor 180B can be used for anti-shake shooting. For example, when the shutter is pressed, the gyro sensor 180B detects the angle of the electronic device 100 shaking, calculates the distance that the lens module needs to compensate based on the angle, and allows the lens to offset the shaking of the electronic device 100 through reverse movement to achieve anti-shake. The gyro sensor 180B can also be used in scenarios such as navigation and somatosensory games.
[0309] Accelerometer 180E can detect the magnitude of acceleration of electronic device 100 in various directions (typically the x-, y-, and z-axes). When electronic device 100 is stationary, it can detect the magnitude and direction of gravity. Accelerometer 180E can also be used to identify the posture of electronic device 100, serving as an input parameter for applications such as landscape / portrait switching and pedometers.
[0310] The distance sensor 180F is used to measure distance. The electronic device 100 can measure distance using infrared or laser. In some embodiments, for example, in a photography scenario, the electronic device 100 can use the distance sensor 180F to measure distance to achieve fast focusing.
[0311] The touch sensor 180K is also called a touch-sensitive device. In some embodiments, the touch sensor 180K can be provided on the display screen 194. The touch sensor 180K and the display screen 194 form a touch screen, which is also called a touch screen. The touch sensor 180K is used to detect touch operations acting on or near it. The touch sensor 180K can pass the detected touch operations to the application processor to determine the type of touch event. Visual output related to the touch operation can be provided through the display screen 194. For example, Figure 5 or Figure 6 After the user touches the touch screen of the client, the touch sensor of the client can detect the touch operation. In other embodiments, the touch sensor 180K can also be set on the surface of the electronic device 100 and is set at a different position from the display screen 194.
[0312] The buttons 190 include a power button and a volume button. The buttons 190 can be mechanical buttons or touch buttons. The electronic device 100 can receive button input signals and implement functions related to the case input signals.
[0313] Motor 191 can generate vibrations. Motor 191 can be used for incoming call notifications or touch feedback. Motor 191 can generate different vibration feedback effects for touch operations on different applications. Motor 191 can also generate different vibration feedback effects for touch operations on different areas of the display 194. Different application scenarios (for example, time reminders, receiving messages, alarms, and games) can correspond to different vibration feedback effects. Touch vibration feedback effects can also be customized.
[0314] The present application also provides a computer program product, which, when executed by an electronic device, implements the image distortion correction method and / or model training method of any method embodiment in the present application.
[0315] The computer program product may be stored in a memory, for example, a program, which is converted into an executable target file that can be executed by a processor after undergoing processes such as preprocessing, compilation, assembly, and linking.
[0316] This application also provides a computer-readable storage medium having a computer program stored thereon. When executed by an electronic device, the computer program implements the image distortion correction method and / or model training method of any method embodiment of this application. The computer program can be a high-level language program or an executable target program.
[0317] The present application also provides a chip, which is applied to an electronic device. The chip includes one or more processors, which are used to call computer instructions so that the electronic device can implement the image distortion correction method and / or model training method of any method embodiment in the present application when executing.
[0318] In this application, "at least one" means one or more, and "plurality" means two or more. "At least one of the following" or similar expressions refers to any combination of these items, including any combination of single or plural items. For example, "at least one of a, b, or c" can mean: a, b, c, ab, ac, bc, or abc, where a, b, and c can be single or plural.
[0319] It should be understood that in the various embodiments of the present application, the size of the serial numbers of the above-mentioned processes does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0320] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0321] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.
[0322] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for example, the division of the units is merely a logical function division, and there may be other division methods in actual implementation; for example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection of some interfaces, devices or units, which can be electrical, mechanical or other forms.
[0323] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of these units may be selected to achieve the purpose of this embodiment according to actual needs.
[0324] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0325] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
Claims
1. A method for correcting image distortion, characterized in that: The method comprises: Acquire a distorted image and an initial grid image of the distorted image, wherein the initial grid image is a grid image obtained according to the distorted image; Performing feature extraction processing on the distorted image through a dedistortion model to obtain feature data of the distorted image, wherein the feature data of the distorted image is used to indicate the distorted image; Decoding the initial grid image using the feature data of the distorted image through the dedistortion model to obtain a distortion-corrected grid image of the distorted image, wherein the distortion-corrected grid image is a grid image without distortion; Using the distortion correction grid image to correct the distorted image through the dedistortion model to obtain a distortion corrected image; Wherein, before performing feature extraction processing on the distorted image by using the dedistortion model to obtain feature data of the distorted image, the method further includes: Acquire at least one training sample pair, wherein the at least one training sample pair includes a training distorted image as training data and a first grid image of the training distorted image, and a label image as label data, wherein the first grid image is a grid image obtained according to the training distorted image, and the label image is an image without distortion obtained based on the training distorted image; Performing feature extraction processing on the training distorted image through an initial dedistortion model to obtain feature data of the training distorted image; Decoding the first grid image of the training distorted image using the feature data of the training distorted image through the initial dedistortion model to obtain a second grid image of the training distorted image; Using the initial dedistortion model and the second grid image of the training distorted image, the training distorted image is corrected to obtain a distortion-corrected image corresponding to the training distorted image; According to the difference between the distortion-corrected image corresponding to the training distorted image and the label image, the parameters of the initial dedistortion model are adjusted to obtain the dedistortion model.
2. The method according to claim 1, characterized in that The initial grid image is a grid image obtained by gridding the distorted image.
3. The method according to claim 1, characterized in that The initial grid image is a grid image obtained by gridding an initial distortion-corrected image, wherein the initial distortion-corrected image is an image obtained by performing a preset distortion correction process on the distorted image.
4. The method according to claim 1 or 2, characterized in that: The distorted image includes N first pixel points, and the distortion-corrected grid image includes N second pixel points, wherein the N second pixel points correspond to the N first pixel points one by one, and N is a positive integer; The step of correcting the distorted image by using the distortion correction grid image through the dedistortion model to obtain the distortion corrected image includes: Through the dedistortion model, the coordinate value of each second pixel point is used to update the coordinate value of each corresponding first pixel point to obtain the distortion-corrected image.
5. The method according to claim 4, characterized in that The coordinate value of the second pixel point is obtained by interpolating the coordinate values of multiple pixel points in the distortion-corrected grid image associated with the second pixel point.
6. The method according to claim 1 or 2, characterized in that: The step of acquiring the distorted image comprises: The acquired initial distorted image is scaled to obtain the distorted image, wherein the size of the distorted image is smaller than the size of the initial distorted image.
7. The method according to claim 1 or 2, characterized in that: The dedistortion model is a neural network model obtained through training, and the dedistortion model includes a decoder, an encoder and an output layer, and; The step of performing feature extraction processing on the distorted image by using a dedistortion model to obtain feature data of the distorted image includes: Performing feature extraction processing on the distorted image by the encoder to obtain feature data of the distorted image; The decoding process of the initial grid image by using the feature data of the distorted image through the dedistortion model to obtain a distortion-corrected grid image of the distorted image includes: The decoder uses the characteristic data of the distorted image to decode the initial grid image to obtain the distortion-corrected grid image; The step of correcting the distorted image by using the distortion correction grid image through the dedistortion model to obtain the distortion corrected image includes: The distortion-corrected image is corrected by using the distortion-corrected grid image through the output layer to obtain the distortion-corrected image.
8. The method according to claim 1 or 2, characterized in that: The dedistortion model is a converter model in a generative model.
9. The method according to claim 1 or 2, characterized in that: Applicable to electronic devices including cameras, The step of acquiring the distorted image comprises: Display the shooting interface; In response to a shooting operation on the shooting interface, acquiring the distorted image through the camera; After the distortion-corrected image is corrected by the dedistortion model using the distortion-corrected grid image to obtain the distortion-corrected image, the method further includes: An interface including the distortion-corrected image is displayed.
10. The method according to claim 1 or 2, characterized in that: Applicable to electronic devices including gallery applications, The step of acquiring the distorted image comprises: Displaying the interface of the gallery application; In response to a selection operation on the distorted image in the interface of the gallery application, acquiring the distorted image; After the distortion-corrected image is corrected by the dedistortion model using the distortion-corrected grid image to obtain the distortion-corrected image, the method further includes: An interface including the distortion-corrected image is displayed.
11. An electronic device, characterized in that: It comprises one or more processors and one or more memories; wherein, the one or more memories are coupled to the one or more processors, and the one or more memories are used to store computer programs, and when the one or more processors execute the computer programs, the electronic device executes the method as described in any one of claims 1 to 10.
12. A chip, which is applied to electronic equipment, and includes one or more processors, characterized in that: The processor is used to call computer instructions so that the electronic device executes the method according to any one of claims 1 to 10.
13. A computer-readable storage medium comprising a computer program, characterized in that: When the computer program is executed on an electronic device, the electronic device is enabled to execute the method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Image processing method, image processing device, and storage medium
CN108898043A
