Example one
The present embodiment provides an image processing method, which is applied to an image capturing device with an image capturing function, such as a camera, a mobile phone, a tablet computer, a personal digital assistant, a monitoring device, and the like, and can also be applied to a computing device such as a PC (personal computer) client or a server that is in communication connection with the image capturing device.
As shown in fig. 1, the image processing method provided by the present embodiment includes:
s101, performing image preprocessing on an original image; the original image is an image acquired under an environment with brightness lower than a preset illuminance.
In a specific application, the preset illuminance can be set according to actual needs. The environment with the brightness lower than the preset illuminance generally includes a night environment, a weak environment or a dark room environment.
In one embodiment, the original image may also be an image acquired in an environment with a brightness lower than a preset illuminance and having an exposure time shorter than a preset exposure time.
In a specific application, the preset exposure time may be set according to actual needs, and the preset exposure time is generally less than or equal to the exposure time of the image pickup apparatus under a normal exposure condition.
In one embodiment, step S101 is preceded by:
and step S100, acquiring an original image under the environment that the brightness is lower than the preset illuminance.
In a specific application, step S100 may be performed by the image capturing apparatus, or may be performed by the computing apparatus connected to the image capturing apparatus in communication with the image capturing apparatus to control the image capturing apparatus.
In a particular application, image pre-processing may include color channel separation, black level correction, normalization, magnification, clamping, cropping, and the like.
In one embodiment, step S101 includes:
step S1011, performing color channel separation on the original image, and storing the original image as an image with a preset number of color channels according to the number and sequence of the color channels of the original image.
In a specific application, the value of the preset number is determined by the number of color channels of the photosensitive device of the image pickup apparatus. The image pickup apparatus capable of color imaging includes at least three color channels of R (red), G (green), and B (blue), and may further include a fourth color channel, where the fourth color channel may be any one of R, G, B color channels, and may also be a yellow or white color channel.
In one embodiment, the original image has color channels in the order of R, G, B, G, and the original image is separated into R, G, B, G images with 4 color channels, and stored as images with 4 color channels in the order of R, G, B, G.
Step S1012, performing black level correction on the images of the preset number of color channels.
In a specific application, the black level correction is to subtract a black level value from an image of each color channel to correct the deviation of the pixel value of each pixel point in the image.
And step S1013, carrying out normalization processing on the images of the preset number of color channels after the black level correction.
In a specific application, the normalization process is to normalize the pixel value of each pixel point in the image of each color channel from which the black level value is subtracted to [0,1], and define a normalization coefficient as the maximum pixel value minus the black level value in the original image, where the original image obtained by the image capturing device is usually 14 bits, the maximum pixel value in the original image is 16383, and the normalization operation is to divide the pixel value of each pixel point from which the black level value is subtracted by the normalization coefficient.
And step 1014, performing amplification processing on the normalized images of the preset number of color channels.
In a specific application, the amplification processing is to multiply the pixel value of each pixel point in the image of each color channel after the normalization processing by an exposure coefficient, wherein the exposure coefficient is a multiple between the expected long exposure time and the expected short exposure time. In the present embodiment, the short exposure time refers to an exposure time shorter than a preset exposure time, and generally, the short exposure time is 0.1s in an environment where the brightness is lower than the preset illuminance, and the desired long exposure time is 10s, and then the exposure coefficient is 100.
And step S1015, performing clamping processing on the enlarged images of the preset number of color channels.
In a specific application, the clamp processing is to clamp the pixel value of each pixel point in the image of each color channel after the amplification processing to [0,1], specifically, to set all the pixel values of the pixel points whose pixel values are greater than 1 in the image of each color channel after the amplification processing to 1, so as to prevent overexposure.
And step S1016, performing clipping operation on the clipped images of the preset number of color channels.
In a specific application, the clipping operation refers to clipping a preset number of color channel patterns arranged side by side into an equal-divided preset number of image blocks, and certain pixel points need to be overlapped between adjacent image blocks to ensure natural transition of an image in a subsequent linear weighted fusion process, and the number of the overlapped pixel points can be set according to actual needs, for example, can be set to 120 pixel points.
And S102, inputting the original image after image preprocessing into a deep neural network for forward calculation to obtain an output result.
In one embodiment, the deep neural network performs global optimization training on the long-exposure image and the short-exposure image after image preprocessing in advance until convergence.
In specific application, the deep neural network can utilize a large number of long-exposure images and a large number of short-exposure images after image preprocessing in advance, and global optimization training is carried out through a global optimization algorithm until convergence is achieved, so that the deep neural network can output a target image which is clear in imaging and equivalent to an image shot under a normal illumination environment and is infinitely close to the long-exposure images after the original image is input.
In one embodiment, the deep neural network is trained using an L1 cost function and Adam optimizer and continually adjusts parameters until convergence is achieved.
In a specific application, the short-exposure image refers to an image acquired under the same or equivalent conditions (i.e., the brightness is lower than the preset illuminance, and the exposure time is shorter than the preset exposure time) as the original image, and the long-exposure image refers to a clear image acquired under the normal illuminance environment and having an exposure time greater than or equal to the normal exposure time of the imaging device. The image pre-processing mode for the short exposure image is the same as the image pre-processing mode for the original image.
In one embodiment, the deep neural network comprises 1 feature extraction layer, a preset number of down-sampling layers, 1 intermediate processing layer, and the preset number +2 up-sampling layers;
correspondingly, step S102 includes:
and S1021, inputting the original image after image preprocessing into the 1 feature extraction layer, and performing feature extraction.
In one embodiment, the 1 feature extraction layer comprises 1 first convolution layer of a first step size and a convolution kernel size of a first size and 1 second convolution layer of a second step size and a convolution kernel size of a second size.
In a specific application, the first step size is 2, the first size is 5 × 5, the second step size is 1, and the second size is 1 × 1; when the preset number is 4, the number of output channels of the first convolution layer is 32, and the number of output channels of the second convolution layer is 16.
Step S1022, down-sampling the original image after feature extraction sequentially by a preset number of down-sampling layers.
In one embodiment, each of the downsampled layers includes 1 third convolution layer having a third step size and a convolution kernel size of a third size and 1 inverse residual block (Inverted residual) having an expansion coefficient of a preset coefficient.
In a specific application, the third step size is 2, and the third size is 3 × 3; when the preset number is 4, the number of output channels of the preset number of down-sampling layers is 32, 64, 128, 256 respectively.
Step S1023, inverse residual calculation is performed on the downsampled original image through the 1 intermediate processing layer.
In one embodiment, the 1 intermediate processing layer includes a preset number of inverse residual blocks having expansion coefficients of preset coefficients.
In a specific application, the preset coefficient is 4; when the preset number is 4, the number of output channels of the reverse residual block with the preset number of expansion coefficients being the preset coefficient is 256.
And step S1024, sequentially performing upsampling on the original image after the reverse residual error calculation through the preset number of +2 upsampling layers to obtain an output result.
In one embodiment, the pre-set number of upsampling layers are constructed based on a bilinear interpolation algorithm and a short connection form and include 1 fourth convolution layer with a fourth step size and a convolution kernel size of the fourth convolution layer and 1 inverse residual block with an expansion coefficient of a pre-set coefficient;
the last up-sampling layer comprises a first deconvolution layer with 1 fifth step size and a convolution kernel size of the fifth size, a fifth convolution layer with 1 sixth step size and a convolution kernel size of the sixth size, and a sixth convolution layer with 1 seventh step size and a convolution kernel size of the seventh size and containing no activation function;
the last of the up-sampled layers includes a second deconvolution layer of 1 eighth step size with a convolution kernel size of eighth size.
In a specific application, the fourth step size is 1, the fourth size is 1 × 1, the fifth step size is 2, the fifth size is 2 × 2, the sixth step size is 1, the sixth size is 3 × 3, the seventh step size is 1, the seventh size is 1 × 1, the eighth step size is 2, and the eighth size is 2 × 2; when the preset number is 4, the number of output channels of the previous preset number of the upsampling layers is 128, 64, 32 and 16 respectively; the number of output channels of the first deconvolution layer is 16, the number of output channels of the fifth convolution layer is 16, and the number of output channels of the sixth convolution layer is 12; the number of output channels of the second deconvolution layer is 3.
In one embodiment, the short connection form of the up-sampling layers with the preset number is constructed in the following manner:
and adding the output result of the fourth convolution layer of each up-sampling layer in the up-sampling layers with the preset number with the output result with the same number of output channels in the feature extraction layer or the down-sampling layer.
In a specific application, when the preset number is 4, the output results of the first 4 upsampling layers with the number of output channels of 128, 64, 32, and 16 are added in a one-to-one correspondence with the output results of the third convolutional layer with the number of output channels of 128, 64, and 32, and the second convolutional layer with the number of output channels of 16.
In one embodiment, all activation functions in the deep neural network are Relu activation functions.
As shown in fig. 2, a schematic diagram of a deep neural network is exemplarily shown; in the figure, the number on the network structure of each layer indicates the number of output channels of the layer, and the arrow direction indicates the transmission direction of image data.
And step S103, generating a target image according to the output result.
In one embodiment, step S103 includes:
and performing clamping processing, stretching processing and splicing processing on the output result to generate a target image.
In specific application, the clamp processing is to clamp the pixel value of each pixel point in the image of each color channel of the image output by the deep neural network to [0,1], specifically, to set all the pixel values of the pixel points whose pixel values are greater than 1 in the image of each color channel in the image to 1, so as to prevent overexposure.
In a specific application, the stretching process is to multiply the output result after the clamping process by a coefficient, which may be 255.
In a specific application, the splicing process can be realized by adopting a linear weighted fusion method.
In one embodiment, the model of the linear weighted fusion algorithm is as follows:
Wa=1-Wb;
Xmerge=Xa*Wa+Xb*Wb;
wherein, X1To the left boundary where image a and image b overlap, X2Is the right boundary where image a and image b overlap, X is a specific column position where image a and image b overlap, WaAs a fusion weight of the image a at the X position, WbAs a fusion weight of image b at the X position, XaFor data on image a at X position, XbFor data on image b at X position, XmergeIs the fused image data at the X position, [0, X2]Is the length of image a, [ X ]1,X3]Is the length of image b, [ X ]1,X2]Is the overlapping region of image a and image b, [0, X3]The image length after the image a and the image b are fused.
Fig. 3 schematically shows a diagram of the change of the weighting weights for overlapping pixel points.
Fig. 4 exemplarily shows a process of generating a target image after an original image including four color channels is subjected to image preprocessing, a deep neural network, a clamping process, a stretching process and a stitching process.
Fig. 5 exemplarily shows an original image, an original image after image preprocessing, and a target image. As can be seen from fig. 5, the image processing method provided by the embodiment can effectively improve the signal-to-noise ratio and the definition of the short-exposure image acquired in the dark environment.
According to the method, the original image acquired in the dark environment is subjected to image preprocessing, the original image subjected to image preprocessing is input into the deep neural network to be subjected to forward calculation, an output result is obtained, the target image is generated according to the output result, the original image acquired in the dark environment can be processed into the target image with high signal-to-noise ratio and low noise level, and the definition of the original image is effectively improved.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present invention.
EXAMPLE III
As shown in fig. 7, the present embodiment provides aterminal device 6, which includes: aprocessor 60, amemory 61 and acomputer program 62, such as a depth information estimation program, stored in saidmemory 61 and executable on saidprocessor 60. Theprocessor 60, when executing thecomputer program 62, implements the steps in the various depth information estimation method embodiments described above, such as steps S101 to S103 shown in fig. 1. Alternatively, theprocessor 60, when executing thecomputer program 62, implements the functions of the modules in the above device embodiments, such as the functions of themodules 501 to 505 shown in fig. 6.
Illustratively, thecomputer program 62 may be partitioned into one or more modules that are stored in thememory 61 and executed by theprocessor 60 to implement the present invention. The one or more modules may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution of thecomputer program 62 in theterminal device 6. For example, thecomputer program 62 may be divided into a preprocessing module, a computing module, and an image processing module, each of which functions specifically as follows:
the preprocessing module is used for preprocessing the original image; the original image is an image acquired in an environment with brightness lower than a preset illuminance;
the calculation module is used for inputting the original image after image preprocessing into a deep neural network for forward calculation to obtain an output result; and the image processing module is used for generating a target image according to the output result.
Theterminal device 6 may be a desktop computer, a notebook, a palm computer, a cloud server, or other computing devices. The terminal device may include, but is not limited to, aprocessor 60, amemory 61. Those skilled in the art will appreciate that fig. 7 is merely an example of aterminal device 6 and does not constitute a limitation ofterminal device 6 and may include more or fewer components than shown, or some components may be combined, or different components, for example, the terminal device may also include input output devices, network access devices, buses, etc.
TheProcessor 60 may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
Thememory 61 may be an internal storage unit of theterminal device 6, such as a hard disk or a memory of theterminal device 6. Thememory 61 may also be an external storage device of theterminal device 6, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like, which are provided on theterminal device 6. Further, thememory 61 may also include both an internal storage unit and an external storage device of theterminal device 6. Thememory 61 is used for storing the computer program and other programs and data required by the terminal device. Thememory 61 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
In the embodiments provided in the present invention, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, the division of the modules or units is only one logical division, and there may be other divisions when actually implemented, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated module, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method according to the embodiments of the present invention may also be implemented by a computer program, which may be stored in a computer-readable storage medium, and when the computer program is executed by a processor, the steps of the method embodiments may be implemented. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, etc. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present invention, and not for limiting the same; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present invention, and are intended to be included within the scope of the present invention.