Image processing method, device, electronic device and computer readable storage medium
By performing YUV image conversion and convolution operations on the image to generate an RGB image, and using the batch normalization function to accelerate preprocessing, the problem of slow image preprocessing speed in the existing technology is solved, and the processing speed is significantly improved.
Patent Information
- Application Number
- CN202010305880.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-04-17
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2040-04-17
AI Technical Summary
Existing image preprocessing methods are slow in processing speed, resulting in long image processing time.
By converting the image to be processed into a three-channel YUV image, performing a convolution operation on the Y channel, U channel, and V channel images to generate an RGB image, and then preprocessing the RGB image, using the batch normalization function to accelerate the preprocessing process.
It shortens the time for converting YUV images into RGB images and improves the speed of image preprocessing.
Smart Images

Figure CN111508038B
Abstract
Description
Technical Field
[0001] The present application relates to the field of image processing technology, and in particular to an image processing method, device, electronic device and computer-readable storage medium. Background Art
[0002] In existing computer vision technology, image preprocessing is an essential step. The commonly used image preprocessing method is: for each pixel in the image to be processed, data formatting, RGB conversion, data normalization and other processes are performed in sequence. However, this method consumes a lot of processing time and results in slow processing speed. Summary of the invention
[0003] The embodiments of the present application provide an image processing method, an apparatus, an electronic device, and a computer-readable storage medium to solve the problem of slow processing speed of existing image preprocessing methods.
[0004] In order to solve the above technical problems, this application is implemented as follows:
[0005] In a first aspect, an embodiment of the present application provides an image processing method, comprising:
[0006] Get the image to be processed;
[0007] Convert the image to be processed into a three-channel YUV image;
[0008] Performing convolution operation on the Y channel image, the U channel image and the V channel image in the three-channel YUV image to generate an R channel image, a G channel image and a B channel image respectively, and obtaining a three-channel RGB image;
[0009] The three-channel RGB image is preprocessed.
[0010] In this way, during the image preprocessing process, the Y channel image, U channel image and V channel image in the converted three-channel YUV image can be processed with the help of convolution operation to generate a three-channel RGB image, and the three-channel RGB image is preprocessed, thereby shortening the time for converting the YUV image into the RGB image, thereby improving the image preprocessing speed.
[0011] Optionally, converting the image to be processed into a three-channel YUV image includes:
[0012] Dividing the image to be processed into a first Y channel image and a UV channel image;
[0013] Adjusting the first Y channel image to obtain a Y channel image with a dimension of (N, 1, W, H);
[0014] Separate the UV channel image to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5);
[0015] The U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) are sampled by 2 times respectively to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H);
[0016] Merge the Y channel image, U channel image and V channel image with dimensions (N, 1, W, H) to obtain a YUV image with dimensions (N, 3, W, H);
[0017] Among them, the N represents the number of images to be processed, the 1 represents that the Y channel image, the U channel image or the V channel image is 1 channel, the 3 represents that the YUV image is 3 channels, the W is equal to the width of the image to be processed, and the H is equal to the height of the image to be processed.
[0018] In this way, with the help of the above separation, sampling and merging process, a three-channel YUV image that meets the needs of subsequent convolution operations can be efficiently obtained.
[0019] Optionally, the separating the UV channel image to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5) includes:
[0020] Adjust the UV channel image to a UV channel image with a dimension of (N, 2, W*H*0.25);
[0021] Separate the UV channel image with the dimension of (N, 2, W*H*0.25) to obtain a U channel image with the dimension of (N, 1, W*H*0.25) and a V channel image with the dimension of (N, 1, W*H*0.25);
[0022] The U channel image with the dimension (N, 1, W*H*0.25) is adjusted to the U channel image with the dimension (N, 1, W*0.5, H*0.5), and the V channel image with the dimension (N, 1, W*H*0.25) is adjusted to the V channel image with the dimension (N, 1, W*0.5, H*0.5).
[0023] In this way, the separation of UV channel images can be achieved accurately.
[0024] Optionally, the U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) are respectively sampled by 2 times to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H), including:
[0025] Using the nearest interpolation function, the U channel image with the dimension (N, 1, W*0.5, H*0.5) and the V channel image with the dimension (N, 1, W*0.5, H*0.5) are respectively upsampled by 2 times to obtain the U channel image with the dimension (N, 1, W, H) and the V channel image with the dimension (N, 1, W, H).
[0026] In this way, by using the nearest interpolation function to perform 2 times nearest neighbor upsampling, the required U channel image and V channel image can be accurately sampled.
[0027] Optionally, preprocessing the three-channel RGB image includes:
[0028] The three-channel RGB image is preprocessed using a batch normalization function.
[0029] In this way, the three-channel RGB image can be uniformly preprocessed with the help of the batch normalization function, thereby accelerating the preprocessing process.
[0030] Optionally, the batch normalization function is:
[0031]
[0032] Among them, the output represents the pixel value of the image after preprocessing, the input represents the pixel value of the image before preprocessing, the scale represents the scaling factor, the bias represents the bias value, the mean represents the mean, the variance represents the variance, and the epsilon represents the preset division numerical stability coefficient.
[0033] Optionally, after obtaining the three-channel RGB image, the method further includes:
[0034] Adjusting the size of the three-channel RGB image;
[0035] The preprocessing of the three-channel RGB image comprises:
[0036] Preprocess the resized three-channel RGB image.
[0037] In a second aspect, an embodiment of the present application further provides an image processing device, including:
[0038] An acquisition module, used for acquiring an image to be processed;
[0039] A conversion module, used for converting the image to be processed into a three-channel YUV image;
[0040] An operation module is used to perform a convolution operation on a Y channel image, a U channel image and a V channel image in the three-channel YUV image to generate an R channel image, a G channel image and a B channel image respectively, so as to obtain a three-channel RGB image;
[0041] The preprocessing module is used to preprocess the three-channel RGB image.
[0042] Optionally, the conversion module includes:
[0043] A dividing unit, used for dividing the image to be processed into a first Y channel image and a UV channel image;
[0044] An adjustment unit, used for adjusting the first Y channel image to obtain a Y channel image with a dimension of (N, 1, W, H);
[0045] A separation unit is used to separate the UV channel image to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5);
[0046] A sampling unit is used to perform 2-fold sampling on the U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H);
[0047] A merging unit, used for merging a Y channel image, a U channel image and a V channel image with dimensions (N, 1, W, H) to obtain a YUV image with dimensions (N, 3, W, H);
[0048] Among them, the N represents the number of images to be processed, the 1 represents that the Y channel image, the U channel image or the V channel image is 1 channel, the 3 represents that the YUV image is 3 channels, the W is equal to the width of the image to be processed, and the H is equal to the height of the image to be processed.
[0049] Optionally, the separation unit includes:
[0050] A first adjustment subunit, used for adjusting the UV channel image into a UV channel image with a dimension of (N, 2, W*H*0.25);
[0051] A separation subunit is used to separate the UV channel image with a dimension of (N, 2, W*H*0.25) to obtain a U channel image with a dimension of (N, 1, W*H*0.25) and a V channel image with a dimension of (N, 1, W*H*0.25);
[0052] The second adjustment subunit is used to adjust the U channel image with the dimension of (N, 1, W*H*0.25) to the U channel image with the dimension of (N, 1, W*0.5, H*0.5), and adjust the V channel image with the dimension of (N, 1, W*H*0.25) to the V channel image with the dimension of (N, 1, W*0.5, H*0.5).
[0053] Optionally, the sampling unit is specifically used to: use the nearest interpolation function to perform 2 times nearest neighbor upsampling on the U channel image with the dimension (N, 1, W*0.5, H*0.5) and the V channel image with the dimension (N, 1, W*0.5, H*0.5), respectively, to obtain the U channel image with the dimension (N, 1, W, H) and the V channel image with the dimension (N, 1, W, H).
[0054] Optionally, the preprocessing module is specifically used to: preprocess the three-channel RGB image using a batch normalization function.
[0055] Optionally, the batch normalization function is:
[0056]
[0057] Among them, the output represents the pixel value of the image after preprocessing, the input represents the pixel value of the image before preprocessing, the scale represents the scaling factor, the bias represents the bias value, the mean represents the mean, the variance represents the variance, and the epsilon represents the preset division numerical stability coefficient.
[0058] Optionally, the device further comprises:
[0059] An adjustment module, used for adjusting the size of the three-channel RGB image;
[0060] The preprocessing module is specifically used to preprocess the resized three-channel RGB image.
[0061] In a third aspect, an embodiment of the present application further provides an electronic device, including:
[0062] at least one processor; and
[0063] a memory communicatively connected to the at least one processor; wherein,
[0064] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can perform the image processing method as described above.
[0065] In a fourth aspect, an embodiment of the present application further provides a non-transitory computer-readable storage medium storing computer instructions, wherein the computer instructions are used to enable the computer to execute the image processing method as described above.
[0066] One embodiment of the above application has the following advantages or beneficial effects: during the image preprocessing process, the Y channel image, U channel image and V channel image in the converted three-channel YUV image can be processed by means of convolution operation to generate a three-channel RGB image, and the three-channel RGB image is preprocessed, thereby shortening the time of converting the YUV image into the RGB image, thereby improving the image preprocessing speed. Because the image to be processed is obtained, the image to be processed is converted into a three-channel YUV image, and the Y channel image, U channel image and V channel image in the three-channel YUV image are convoluted to generate an R channel image, a G channel image and a B channel image respectively, and a three-channel RGB image is obtained, and the three-channel RGB image is preprocessed. The technical means overcomes the technical problem of slow processing speed of the existing image preprocessing method, thereby achieving the technical effect of improving the image preprocessing speed.
[0067] Other effects of the above optional manner will be described below in conjunction with specific embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0068] The accompanying drawings are used to better understand the present solution and do not constitute a limitation of the present application.
[0069] Figure 1 is a flow chart of an image processing method according to an embodiment of the present application;
[0070] Figure 2 It is a schematic diagram of the convolution operation process in the specific example of this application;
[0071] Figure 3 is a flow chart of the image conversion and preprocessing process of a specific example of the present application;
[0072] Figure 4 is a block diagram of an image processing device for implementing the image processing method of an embodiment of the present application;
[0073] Figure 5 It is a block diagram of an electronic device used to implement the image processing method of an embodiment of the present application. DETAILED DESCRIPTION
[0074] The following is a description of exemplary embodiments of the present application in conjunction with the accompanying drawings, including various details of the embodiments of the present application to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications can be made to the embodiments described herein without departing from the scope and spirit of the present application. Similarly, for the sake of clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0075] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable in appropriate circumstances, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, the process, method, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or equipment.
[0076] See also Figure 1 , Figure 1 is a flowchart of an image processing method provided in an embodiment of the present application, the method is applied to electronic devices such as Figure 1 As shown, the method comprises the following steps:
[0077] Step 101: Obtain an image to be processed.
[0078] In this embodiment, the image to be processed of the present application can be acquired by a camera device, or directly acquired from other devices such as a server device. The present application does not limit the type of the image to be processed, and illustratively, it can be a face image, an object image, a landscape image, etc.
[0079] In one implementation, after the image to be processed is obtained, the format of the image to be processed may be adjusted, for example, the format of the image to be processed may be adjusted to an array with a dimension of (W*H*1.5) and a data type of 8-bit unsigned integer (uint8), where W is equal to the width of the image to be processed and H is equal to the height of the image to be processed.
[0080] Step 102: Convert the image to be processed into a three-channel YUV image.
[0081] The YUV image converted in this step may be a YUV image with a dimension of (N, 3, W, H). N represents the number of images to be processed, 3 represents that the YUV image has 3 channels, W represents the width of the YUV image (equal to the width of the image to be processed), and H represents the height of the YUV image (equal to the height of the image to be processed).
[0082] For the format of the YUV image, there may be multiple formats such as YUV444, YUV422, YUV420, NV12, etc. Different YUV image formats have different pixel arrangements. For example, in this embodiment, the YUV image format may be YUV420, and its pixel arrangement is that all Y channel pixels and UV channel pixels are arranged alternately in columns.
[0083] Step 103: performing a convolution operation on the Y channel image, the U channel image and the V channel image in the three-channel YUV image to generate an R channel image, a G channel image and a B channel image respectively, and obtaining a three-channel RGB image.
[0084] In this embodiment, in this step, the following convolution function (conv2d) can be used to perform a convolution operation on the three-channel YUV image to generate an R channel image, a G channel image, and a B channel image, respectively, to obtain a three-channel RGB image:
[0085]
[0086] Among them, RGB_img represents a three-channel RGB image, YUV_img represents a three-channel YUV image, w and b represent the determined parameter matrix, Indicates the convolution symbol. For this part of the convolution operation, the dimension of the convolution kernel is (1,1,3,3), that is, the convolution kernel size is 1*1, the number of input channels is 3, and the number of output channels is 3.
[0087] In one implementation, the w parameter matrix may be selected as: [[1,0,1.13983], [1,-0.39465,-0.58060], [1,2.03211,0]], and the b parameter matrix may be selected as: [-128*1.13983, 128*0.39465+128*0.58060, -128*2.03211]. In this case, Figure 2 As shown, the corresponding convolution operation process (input is a three-channel YUV image, output is a three-channel RGB image) may include:
[0088] R = Y + 1.13983 * (V - 128);
[0089] G=Y-0.39465*(U-128)-0.58060*(V-128);
[0090] B = Y + 2.03211 * (U-128).
[0091] Step 104: pre-process the three-channel RGB image.
[0092] In this embodiment, the preprocessed image can be used for image target detection, video target detection and analysis, etc. The preprocessing may include image normalization. The preprocessing process in this step may be: preprocessing the three-channel RGB image using a batch normalization function. In this way, the three-channel RGB image can be uniformly preprocessed with the help of a batch normalization function, thereby accelerating the preprocessing process.
[0093] Optionally, the batch normalization function can be: Among them, output represents the pixel value of the image after preprocessing, input represents the pixel value of the image before preprocessing, scale represents the scaling factor, bias represents the bias value, mean represents the mean, variance represents the variance, and epsilon represents the preset numerical stability coefficient of division. The scale, bias, mean, variance, and epsilon can be preset.
[0094] As an optional implementation, the parameters in the batch normalization function can be specifically set as follows: scale equals [1 / σ, 1 / σ, 1 / σ], bias equals [μ1 / σ, μ2 / σ, μ3 / σ], mean equals [0, 0, 0], variance equals [0.999995, 0.999995, 0.999995], and epsilon equals 1e-5. Furthermore, the μ value can be 128, and the σ value can be 256. The reason for setting epsilon to 1e-5 is that in some cases, epsilon is not allowed to be less than 1e-5.
[0095] Optionally, after obtaining the three-channel RGB image, the method further includes: adjusting the size of the three-channel RGB image to a specified size. The above-mentioned preprocessing of the three-channel RGB image may include: preprocessing the three-channel RGB image after the size adjustment. In this way, the size of the adjusted image can be guaranteed to be uniform, and the preprocessing speed can be improved.
[0096] As an optional implementation, before preprocessing the three-channel RGB image, a resize function may be first called to adjust the size of the three-channel RGB image, that is, to adjust the three-channel RGB image to a specified size. As for the specific form of the resize function, an existing commonly used form may be selected and is not limited here.
[0097] The image processing method of the embodiment of the present application can, during the image preprocessing process, use convolution operation to process the Y channel image, U channel image and V channel image in the converted three-channel YUV image to generate a three-channel RGB image, and preprocess the three-channel RGB image, thereby shortening the time for converting the YUV image into the RGB image, thereby improving the image preprocessing speed.
[0098] In the embodiment of the present application, the process of converting the image to be processed into a three-channel YUV image in the above step 102 may include:
[0099] Divide the image to be processed into a first Y channel image and a UV channel image; wherein the division process can be understood as pointer redirection; the dimension of the first Y channel image can be (W*H), and the dimension of the UV channel image can be (W*H*0.5);
[0100] The first Y channel image is adjusted to obtain a Y channel image with a dimension of (N, 1, W, H); wherein N represents the number of images to be processed, 1 represents that the Y channel image is 1 channel, W represents the width of the Y channel image, and H represents the height of the Y channel image; optionally, the present embodiment may call a reshape function to adjust the first Y channel image;
[0101] The UV channel image is separated to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5); wherein 1 indicates that the Y channel image or the V channel image is 1 channel, W*0.5 indicates the width of the Y channel image or the V channel image, and H*0.5 indicates the height of the Y channel image or the V channel image; optionally, the split function may be called in this embodiment to separate the UV channel image;
[0102] The U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) are sampled by 2 times respectively to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H); wherein 1 indicates that the Y channel image or the V channel image is 1 channel, the W indicates the width of the Y channel image or the V channel image, and the H indicates the height of the Y channel image or the V channel image;
[0103] The Y channel image, U channel image and V channel image of dimensions (N, 1, W, H) are merged to obtain a YUV image of dimensions (N, 3, W, H); wherein 3 indicates that the YUV channel image has 3 channels, the W indicates the width of the YUV image, and the H indicates the height of the YUV image; optionally, this embodiment may call the concat function to merge the Y channel image, U channel image and V channel image of dimensions (N, 1, W, H) to obtain a YUV image of dimensions (N, 3, W, H).
[0104] In this way, with the help of the above separation, sampling and merging process, a three-channel YUV image that meets the needs of subsequent convolution operations can be efficiently obtained.
[0105] It should be noted that the above reshape function can use the existing calling format, and can transform the specified matrix into a matrix of a specific dimension, and the number of elements in the matrix remains unchanged, and the number of rows, columns, and dimensions of the matrix can be readjusted. The above split function can use the existing calling format, and can separate the UV channel image to obtain the U channel image and the V channel image. The above concat function can use the existing calling format, and is usually used to connect two or more arrays to obtain a new array.
[0106] Optionally, in order to accurately separate the UV channel image, the above process of separating the UV channel image to obtain the U channel image with dimensions (N, 1, W*0.5, H*0.5) and the V channel image with dimensions (N, 1, W*0.5, H*0.5) can be:
[0107] Adjust the UV channel image to a UV channel image with a dimension of (N, 2, W*H*0.25); wherein W*H*0.25 indicates that the width of the UV channel image is W*0.5 and the height of the UV channel image is H*0.5; and 2 indicates 2 channels of the UV channel image;
[0108] The UV channel image with the dimension of (N, 2, W*H*0.25) is separated to obtain a U channel image with the dimension of (N, 1, W*H*0.25) and a V channel image with the dimension of (N, 1, W*H*0.25); wherein W*H*0.25 indicates that the width of the U channel image is W*0.5 and the height of the U channel image is H*0.5, or indicates that the width of the V channel image is W*0.5 and the height of the V channel image is H*0.5; 1 indicates that the U channel image or the V channel image is 1 channel; optionally, this embodiment may call the split function to separate the UV channel image with the dimension of (N, 2, W*H*0.25);
[0109] The U channel image with a dimension of (N, 1, W*H*0.25) is adjusted to a U channel image with a dimension of (N, 1, W*0.5, H*0.5), and the V channel image with a dimension of (N, 1, W*H*0.25) is adjusted to a V channel image with a dimension of (N, 1, W*0.5, H*0.5); optionally, this embodiment can call the reshape function to adjust the U channel image or the V channel image with a dimension of (N, 1, W*H*0.25).
[0110] Optionally, the above process of sampling the U channel image with dimensions (N, 1, W*0.5, H*0.5) and the V channel image with dimensions (N, 1, W*0.5, H*0.5) by 2 times can be: using the nearest interpolation function, the U channel image with dimensions (N, 1, W*0.5, H*0.5) and the V channel image with dimensions (N, 1, W*0.5, H*0.5) are respectively subjected to the nearest upsampling by 2 times to obtain the U channel image with dimensions (N, 1, W, H) and the V channel image with dimensions (N, 1, W, H). In this way, by using the nearest interpolation function to perform the nearest upsampling by 2 times, the required U channel image and V channel image can be accurately sampled.
[0111] Next, combine Figure 3 The image conversion and preprocessing process of the specific example of this application is explained.
[0112] In the specific example of this application, taking the number of images to be processed as 1, the size of the image to be processed is 1080*1920, and the image conversion and preprocessing process is realized by calling the function in the neural network prediction library, and the neural network framework (such as PaddlePaddle) is used for explanation. Figure 3 As shown, the neural network framework includes an input layer, module 1, module 2, module 3 (convolution layer), module 4 and module 5 (batch normalization layer), and the corresponding process may include:
[0113] For the input layer: First, the image to be processed 1080*1920 is divided into two parts in sequence, namely the Y channel image with dimension (1080*1920) and the UV channel image with dimension (540*960*2); then, the reshape function is called to adjust the Y channel image with dimension (1080*1920) to obtain the Y channel image with dimension (1,1,1080,1920) as the input of input node 1, and the UV channel image with dimension (1,1,540*960*2) is used as the input of input node 2.
[0114] For module 1: First, call the split function to separate the UV channel image at input node 2 to obtain a U channel image with a dimension of (1,1,540*960) and a V channel image with a dimension of (N,1,540*960); then, call the reshape function to adjust the U channel image with a dimension of (1,1,540*960) to a U channel image with a dimension of (1,1,540,960), and call the reshape function to adjust the V channel image with a dimension of (1,1,540*960) to a V channel image with a dimension of (1,1,540,960).
[0115] For module 2: First, use the nearest interpolation function to perform 2 times nearest neighbor upsampling on the U channel image with dimension (1,1,540,960) and the V channel image with dimension (1,1,540,960) to obtain the U channel image with dimension (1,1,1080,1920) and the V channel image with dimension (1,1,1080,1920). Then, call the concat function to merge the Y channel image, U channel image and V channel image with dimension (1,1,1080,1920) to obtain the YUV image with dimension (1,3,1080,1920).
[0116] For module 3: call the convolution function conv2d to perform a convolution operation on the YUV image with a dimension of (1, 3, 1080, 1920), generate an R channel image, a G channel image, and a B channel image respectively, and obtain an RGB image with a dimension of (1, 3, 1080, 1920).
[0117] For module 4: call the resize_bilinear function to resize the RGB image with dimensions (1, 3, 1080, 1920) to an RGB image with dimensions (1, 3, 216, 384).
[0118] For module 5: Use the batch normalization function Batch_norm to preprocess the RGB image with a dimension of (1, 3, 216, 384) to obtain a normalized RGB image with a dimension of (1, 3, 216, 384).
[0119] In this way, by calling the functions in the neural network prediction library, the speed of image preprocessing can be significantly improved.
[0120] See also Figure 4 , Figure 4 is a schematic diagram of the structure of an image processing device provided in an embodiment of the present application, such as Figure 4 As shown, the image processing device 40 includes:
[0121] An acquisition module 41 is used to acquire an image to be processed;
[0122] A conversion module 42, used for converting the image to be processed into a three-channel YUV image;
[0123] The operation module 43 is used to perform convolution operation on the Y channel image, the U channel image and the V channel image in the three-channel YUV image to generate an R channel image, a G channel image and a B channel image respectively, so as to obtain a three-channel RGB image;
[0124] The preprocessing module 44 is used to preprocess the three-channel RGB image.
[0125] Optionally, the conversion module 42 includes:
[0126] A dividing unit, used for dividing the image to be processed into a first Y channel image and a UV channel image;
[0127] An adjustment unit, used for adjusting the first Y channel image to obtain a Y channel image with a dimension of (N, 1, W, H);
[0128] A separation unit is used to separate the UV channel image to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5);
[0129] A sampling unit is used to perform 2-fold sampling on the U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H);
[0130] A merging unit, used for merging a Y channel image, a U channel image and a V channel image with dimensions (N, 1, W, H) to obtain a YUV image with dimensions (N, 3, W, H);
[0131] Among them, the N represents the number of images to be processed, the 1 represents that the Y channel image, the U channel image or the V channel image is 1 channel, the 3 represents that the YUV image is 3 channels, the W is equal to the width of the image to be processed, and the H is equal to the height of the image to be processed.
[0132] Optionally, the separation unit includes:
[0133] A first adjustment subunit, used for adjusting the UV channel image into a UV channel image with a dimension of (N, 2, W*H*0.25);
[0134] A separation subunit is used to separate the UV channel image with a dimension of (N, 2, W*H*0.25) to obtain a U channel image with a dimension of (N, 1, W*H*0.25) and a V channel image with a dimension of (N, 1, W*H*0.25);
[0135] The second adjustment subunit is used to adjust the U channel image with the dimension of (N, 1, W*H*0.25) to the U channel image with the dimension of (N, 1, W*0.5, H*0.5), and adjust the V channel image with the dimension of (N, 1, W*H*0.25) to the V channel image with the dimension of (N, 1, W*0.5, H*0.5).
[0136] Optionally, the sampling unit is specifically used to: use the nearest interpolation function to perform 2 times nearest neighbor upsampling on the U channel image with the dimension (N, 1, W*0.5, H*0.5) and the V channel image with the dimension (N, 1, W*0.5, H*0.5), respectively, to obtain the U channel image with the dimension (N, 1, W, H) and the V channel image with the dimension (N, 1, W, H).
[0137] Optionally, the preprocessing module 44 is specifically used to: preprocess the three-channel RGB image using a batch normalization function.
[0138] Optionally, the batch normalization function is:
[0139]
[0140] Among them, the output represents the pixel value of the image after preprocessing, the input represents the pixel value of the image before preprocessing, the scale represents the scaling factor, the bias represents the bias value, the mean represents the mean, the variance represents the variance, and the epsilon represents the preset division numerical stability coefficient.
[0141] Optionally, the device further comprises:
[0142] An adjustment module, used for adjusting the size of the three-channel RGB image;
[0143] The preprocessing module 44 is specifically used to preprocess the resized three-channel RGB image.
[0144] It is understandable that the image processing device 40 of the embodiment of the present application can implement the above Figure 1 The various processes implemented in the illustrated method embodiment and the same beneficial effects achieved are not described again here to avoid repetition.
[0145] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.
[0146] like Figure 5 , is a block diagram of an electronic device for implementing the image processing method of an embodiment of the present application. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workbenches, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present application described and / or required herein.
[0147] like Figure 5 As shown, the electronic device includes: one or more processors 501, a memory 502, and interfaces for connecting various components, including high-speed interfaces and low-speed interfaces. The various components are interconnected using different buses and can be installed on a common mainboard or installed in other ways as needed. The processor can process instructions executed in the electronic device, including instructions stored in or on the memory to display the graphical information of the GUI on an external input / output device (such as a display device coupled to the interface). In other embodiments, if necessary, multiple processors and / or multiple buses can be used together with multiple memories and multiple memories. Similarly, multiple electronic devices can be connected, and each device provides some necessary operations (for example, as a server array, a group of blade servers, or a multi-processor system). Figure 5 A processor 501 is taken as an example.
[0148] The memory 502 is a non-transitory computer-readable storage medium provided in the present application. The memory stores instructions executable by at least one processor to enable the at least one processor to perform the image processing method provided in the present application. The non-transitory computer-readable storage medium of the present application stores computer instructions, which are used to enable a computer to perform the image processing method provided in the present application.
[0149] The memory 502 is a non-transient computer-readable storage medium that can be used to store non-transient software programs, non-transient computer executable programs and modules, such as program instructions / modules corresponding to the image processing method in the embodiment of the present application (for example, the attached Figure 4The processor 501 executes various functional applications and data processing of the server by running the non-transient software programs, instructions and modules stored in the memory 502, that is, the image processing method in the above method embodiment is implemented.
[0150] The memory 502 may include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function; the data storage area may store data created by the use of the electronic device, etc. In addition, the memory 502 may include a high-speed random access memory, and may also include a non-transient memory, such as at least one disk storage device, a flash memory device, or other non-transient solid-state storage device. In some embodiments, the memory 502 may optionally include a memory remotely arranged relative to the processor 501, and these remote memories may be connected to the electronic device via a network. Examples of the above-mentioned network include, but are not limited to, the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.
[0151] The electronic device of the image processing method may further include: an input device 503 and an output device 504. The processor 501, the memory 502, the input device 503 and the output device 504 may be connected via a bus or other means. Figure 5 The example of connecting through bus is taken in the following.
[0152] The input device 503 can receive input digital or character information, and generate key signal input related to user settings and function control of the electronic device of the image processing method, such as a touch screen, a keypad, a mouse, a track pad, a touch pad, an indicator rod, one or more mouse buttons, a trackball, a joystick and other input devices. The output device 504 may include a display device, an auxiliary lighting device (e.g., an LED) and a tactile feedback device (e.g., a vibration motor), etc. The display device may include, but is not limited to, a liquid crystal display (LCD), a light emitting diode (LED) display and a plasma display. In some embodiments, the display device may be a touch screen.
[0153] Various implementations of the systems and techniques described herein can be realized in digital electronic circuit systems, integrated circuit systems, dedicated ASICs (application specific integrated circuits), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0154] These computer programs (also referred to as programs, software, software applications, or code) include machine instructions for programmable processors and can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. As used herein, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or means (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including a machine-readable medium that receives machine instructions as a machine-readable signal. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0155] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0156] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0157] A computer system may include clients and servers. Clients and servers are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship to each other.
[0158] According to the technical solution of the embodiment of the present application, during the image preprocessing process, the Y channel image, U channel image and V channel image in the converted three-channel YUV image can be processed with the help of convolution operation to generate a three-channel RGB image, and the three-channel RGB image can be preprocessed, thereby shortening the time for converting the YUV image into the RGB image, thereby improving the image preprocessing speed.
[0159] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this application can be executed in parallel, sequentially or in different orders, as long as the expected results of the technical solution disclosed in this application can be achieved, and this document is not limited here.
[0160] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of this application should be included in the protection scope of this application.
Claims
1. An image processing method, It is characterized in that include: Get the image to be processed; Convert the image to be processed into a three-channel YUV image; Performing convolution operation on the Y channel image, the U channel image and the V channel image in the three-channel YUV image to generate an R channel image, a G channel image and a B channel image respectively, thereby obtaining a three-channel RGB image; Preprocessing the three-channel RGB image; The step of converting the image to be processed into a three-channel YUV image comprises: Divide the image to be processed into a first Y channel image and a UV channel image; the dimension of the first Y channel image is (W*H), and the dimension of the UV channel image is (W*H*0.5); Adjusting the first Y channel image to obtain a Y channel image with a dimension of (N, 1, W, H); Separate the UV channel image to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5); The U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) are sampled by 2 times respectively to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H); Merge the Y channel image, U channel image and V channel image with dimensions (N, 1, W, H) to obtain a YUV image with dimensions (N, 3, W, H); Wherein, N represents the number of the images to be processed, 1 represents that the Y channel image, the U channel image or the V channel image is 1 channel, 3 represents that the YUV image is 3 channels, W is equal to the width of the image to be processed, and H is equal to the height of the image to be processed; The step of performing a convolution operation on a Y channel image, a U channel image, and a V channel image in the three-channel YUV image to generate an R channel image, a G channel image, and a B channel image, respectively, to obtain a three-channel RGB image includes: Using the first parameter matrix to perform convolution operations with the Y channel image, the U channel image and the V channel image in the three-channel YUV image, respectively, to obtain convolution results corresponding to the Y channel image, the U channel image and the V channel image, respectively; The convolution results corresponding to the Y channel image, the U channel image, and the V channel image are respectively added using the second parameter matrix to obtain an R channel image, a G channel image, and a B channel image.
2. The method according to claim 1, It is characterized in that The UV channel image is separated to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5), including: Adjust the UV channel image to a UV channel image with a dimension of (N, 2, W*H*0.25); Separate the UV channel image with the dimension of (N, 2, W*H*0.25) to obtain a U channel image with the dimension of (N, 1, W*H*0.25) and a V channel image with the dimension of (N, 1, W*H*0.25); The U channel image with the dimension (N, 1, W*H*0.25) is adjusted to the U channel image with the dimension (N, 1, W*0.5, H*0.5), and the V channel image with the dimension (N, 1, W*H*0.25) is adjusted to the V channel image with the dimension (N, 1, W*0.5, H*0.5).
3. The method according to claim 1, It is characterized in that The U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) are sampled by 2 times respectively to obtain the U channel image with the dimension of (N, 1, W, H) and the V channel image with the dimension of (N, 1, W, H), including: Using the nearest interpolation function, the U channel image with the dimension (N, 1, W*0.5, H*0.5) and the V channel image with the dimension (N, 1, W*0.5, H*0.5) are respectively upsampled by 2 times to obtain the U channel image with the dimension (N, 1, W, H) and the V channel image with the dimension (N, 1, W, H).
4. The method according to claim 1, It is characterized in that The preprocessing of the three-channel RGB image comprises: The three-channel RGB image is preprocessed using a batch normalization function.
5. The method according to claim 4, It is characterized in that The batch normalization function is: Among them, the output represents the pixel value of the image after preprocessing, the input represents the pixel value of the image before preprocessing, the scale represents the scaling factor, the bias represents the bias value, the mean represents the mean, the variance represents the variance, and the epsilon represents the preset division numerical stability coefficient.
6. The method according to claim 1, It is characterized in that After obtaining the three-channel RGB image, the method further includes: Adjusting the size of the three-channel RGB image; The preprocessing of the three-channel RGB image comprises: Preprocess the resized three-channel RGB image.
7. An image processing device, It is characterized in that include: An acquisition module, used for acquiring an image to be processed; A conversion module, used for converting the image to be processed into a three-channel YUV image; An operation module is used to perform a convolution operation on a Y channel image, a U channel image and a V channel image in the three-channel YUV image to generate an R channel image, a G channel image and a B channel image respectively, so as to obtain a three-channel RGB image; A preprocessing module, used for preprocessing the three-channel RGB image; The conversion module comprises: A division unit, used for dividing the image to be processed into a first Y channel image and a UV channel image; the dimension of the first Y channel image is (W*H), and the dimension of the UV channel image is (W*H*0.5); An adjustment unit, used for adjusting the first Y channel image to obtain a Y channel image with a dimension of (N, 1, W, H); A separation unit, used for separating the UV channel image to obtain a U channel image with a dimension of (N, 1, W*0.5, H*0.5) and a V channel image with a dimension of (N, 1, W*0.5, H*0.5); A sampling unit is used to perform 2-fold sampling on the U channel image with the dimension of (N, 1, W*0.5, H*0.5) and the V channel image with the dimension of (N, 1, W*0.5, H*0.5) to obtain a U channel image with the dimension of (N, 1, W, H) and a V channel image with the dimension of (N, 1, W, H); A merging unit, used for merging a Y channel image, a U channel image and a V channel image with dimensions (N, 1, W, H) to obtain a YUV image with dimensions (N, 3, W, H); Wherein, N represents the number of the images to be processed, 1 represents that the Y channel image, the U channel image or the V channel image is 1 channel, 3 represents that the YUV image is 3 channels, W is equal to the width of the image to be processed, and H is equal to the height of the image to be processed; The operation module is specifically used for: Using the first parameter matrix to perform convolution operations with the Y channel image, the U channel image and the V channel image in the three-channel YUV image, respectively, to obtain convolution results corresponding to the Y channel image, the U channel image and the V channel image, respectively; The convolution results corresponding to the Y channel image, the U channel image, and the V channel image are respectively added using the second parameter matrix to obtain an R channel image, a G channel image, and a B channel image.
8. The device according to claim 7, It is characterized in that The separation unit comprises: A first adjustment subunit, used for adjusting the UV channel image into a UV channel image with a dimension of (N, 2, W*H*0.25); A separation subunit is used to separate the UV channel image with a dimension of (N, 2, W*H*0.25) to obtain a U channel image with a dimension of (N, 1, W*H*0.25) and a V channel image with a dimension of (N, 1, W*H*0.25); The second adjustment subunit is used to adjust the U channel image with the dimension of (N, 1, W*H*0.25) to the U channel image with the dimension of (N, 1, W*0.5, H*0.5), and adjust the V channel image with the dimension of (N, 1, W*H*0.25) to the V channel image with the dimension of (N, 1, W*0.5, H*0.5).
9. The device according to claim 7, It is characterized in that The sampling unit is specifically used to: use the nearest interpolation function to perform 2 times nearest neighbor upsampling on the U channel image with the dimension (N, 1, W*0.5, H*0.5) and the V channel image with the dimension (N, 1, W*0.5, H*0.5) to obtain the U channel image with the dimension (N, 1, W, H) and the V channel image with the dimension (N, 1, W, H).
10. The device according to claim 7, It is characterized in that The preprocessing module is specifically used to preprocess the three-channel RGB image using a batch normalization function.
11. An electronic device, It is characterized in that include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 6.
12. A non-transitory computer-readable storage medium storing computer instructions, It is characterized in that The computer instructions are used to cause the computer to execute the method according to any one of claims 1 to 6.
