Image processing method, electronic device, and readable storage medium
An image processing method, an electronic device, and a readable storage medium are provided. The method includes: obtaining an original image; denoising the original image using an image filtering algorithm to form a preprocessed image S; performing contrast enhancement in the preprocessed image S to form a contrast-enhanced image J; adjusting saturation of the contrast-enhanced image J to form an enhanced display image M; sharpening the enhanced display image M to form a sharpened image N; and performing dynamic range enhancement on the sharpened image N using a dynamic range image enhancement algorithm to form an output image. The image processing method, electronic device, and readable storage medium enable multi-level processing on the original image and improve the display accuracy of the output image.
1 . An image processing method, comprising:
obtaining an original image;
denoising the original image using an image filtering algorithm to form a preprocessed image S;
performing contrast enhancement in the preprocessed image S to form a contrast-enhanced image J;
adjusting saturation of the contrast-enhanced image J to form an enhanced display image M;
sharpening the enhanced display image M to form a sharpened image N; and
performing dynamic range enhancement on the sharpened image N using a dynamic range image enhancement algorithm to form an output image,
wherein the step “sharpening the enhanced display image M to form a sharpened image N” comprises:
step S 51 , extracting three-channel images light c of a brightness layer image for R, G, B three-channel images of the enhanced display image M using a guided filtering algorithm;
step S 52 , obtaining R, G, B three-channel images N c corresponding to the sharpened image N based on the three-channel images light c of the brightness layer image;
N
c
(
i
,
j
)
=
M
c
(
i
,
j
)
+
(
M
c
(
i
,
j
)
-
light
c
(
i
,
j
)
)
*
α
,
wherein, c=[R,G,B], representing one of three channels R, G, B, α is a constant, M c (i,j) represents the value of the pixel at coordinates (i,j) in one of the R, G, B three-channel images corresponding to the enhanced display image M, N c (i,j) represents the value of the pixel at coordinates (i,j) in one of the R, G, B three-channel images corresponding to the sharpened image N, and light c (i,j) represents the value of the pixel at coordinates (i,j) in one of the three-channel images of the brightness layer image;
step S 53 , merging three channels of the R, G, B three-channel images N c to form the sharpened image N;
wherein the method further comprises:
downsampling the enhanced display image M before step S 51 to form a downsampled image;
replacing the enhanced display image M with the downsampled image when performing step S 51 ; and
after step S 51 , upsampling the three-channel images light c formed in step S 51 to form three-channel images light c with the same size as the original image.
2 . The image processing method of claim 1 , wherein the step “denoising the original image using an image filtering algorithm to form a preprocessed image S” comprises:
taking a Gaussian filtering algorithm or a mean filtering algorithm as the image filter algorithm, representing the value of each pixel in the preprocessed image S as S (i,j),
S ( i,j )=blur( I ( i,j ),size( r,r )),
wherein, blur represents filtering function, I(i,j) represents the value of the pixel at coordinates (i,j) in the original image, size (r,r) represents the size of the filtering algorithm, r represents a filtering algorithm parameter, r is a constant, and its numerical value is related to the size of the original image and the noise level of the original image.
3 . The image processing method of claim 1 , wherein the step “performing contrast enhancement in the preprocessed image S to form a contrast-enhanced image J” comprises: performing a gamma transformation on the preprocessed image S to form a gamma image J 1 ; converting the preprocessed image S to a grayscale image S 1 , calculating the mean value of grayscale values of the grayscale image S 1 to form a brightness value m 1 corresponding to the preprocessed image S;
converting the gamma image J 1 to a grayscale image J 2 , obtaining pixels in the grayscale image J 2 with grayscale values greater than a preset first grayscale threshold, calculating the mean value of grayscale values of the obtained pixels to form a brightness value m 2 corresponding to the gamma image J 1 ;
obtaining the contrast-enhanced image J based on the gamma image J 1 , the brightness value m 1 corresponding to the preprocessed image S, and the brightness value m 2 corresponding to the gamma image J 1 ;
J
(
i
,
j
)
=
β
*
J
1
(
i
,
j
)
,
β
=
{
1
,
m
2
≥
m
1
min
(
m
1
,
m
2
+
v
)
m
2
,
m
2
<
m
1
,
wherein v is a constant, J 1 ( i,j ) represents the value of the pixel at coordinates (i,j) in the gamma image J 1 , and J (i,j) represents the value of the pixel at coordinates (i,j) in the contrast-enhanced image J.
4 . The image processing method of claim 1 , wherein the step “adjusting saturation of the contrast-enhanced image J to form an enhanced display image M” comprises:
obtaining R, G, B three-channel images corresponding to the contrast-enhanced image J, and for each pixel in the contrast-enhanced image J, taking the maximum value of the pixel in the R, G, B three-channel images as the grayscale value to form a maximum value image M max , and taking the minimum value of the pixel in the R, G, B three-channel images as the grayscale value to form a minimum value image M min ;
obtaining R, G, B three-channel images M c corresponding to the enhanced display image M based on the maximum value image M max and the minimum value image M min ;
M
c
(
i
,
j
)
=
L
+
(
J
c
(
i
,
j
)
-
L
)
*
(
1
+
K
)
,
L
=
M
(
i
,
j
)
max
+
M
(
i
,
j
)
min
2
;
wherein, c=[R,G,B], representing one of three channels R, G, B, K is a constant, M c (i,j) represents the value of the pixel at coordinates (i, j) in one of the R, G, B three-channel images corresponding to the enhanced display image M, J c (i, j) represents the value of the pixel at coordinates (i, j) in one of the R, G, B three-channel images corresponding to the contrast-enhanced image J, M (i,j) max represents the value of the pixel at coordinates (i, j) in the maximum value image M max , and M(i, j) min represents the value of the pixel at coordinates (i, j) in the minimum value image M min ;
merging three channels of the R, G, B three-channel images M c to form the enhanced display image M.
5 . The image processing method of claim 1 , wherein the step “sharpening the enhanced display image M to form a sharpened image N” comprises:
sharpening the enhanced display image M using a Laplacian pyramid algorithm to form the sharpened image N.
6 . The image processing method of claim 1 , wherein the dynamic range image enhancement algorithm is local histogram enhancement algorithm or Retinex enhancement algorithm.
7 . The image processing method of claim 1 , wherein the step “performing dynamic range enhancement on the sharpened image N using a dynamic range image enhancement algorithm to form an output image” comprises:
step S 61 , obtaining R, G, B three-channel images of the sharpened image N, and for each pixel in the sharpened image N, taking the maximum value corresponding in the R, G, B three-channel images as the grayscale value to form an initial image L 1 ;
step S 62 , performing mean filtering on the initial image L 1 to form a light image L;
step S 63 , calculating the total number of pixels P 1 with grayscale values less than a preset second grayscale threshold in the light image L, wherein
if P 1 ≤P, the sharpened image N is used as the output image E; and
if P 1 >P, performing steps S 64 , S 65 , and S 66 sequentially; wherein P is a preset determination threshold, which is a constant;
step S 64 , calculating a mean grayscale value mean of the pixels with grayscale values less than the preset second grayscale threshold in the light image L; and
obtaining an exposure image G according to the mean grayscale value mean,
G
(
i
,
j
)
=
beta
*
N
(
i
,
j
)
q
,
beta
=
exp
(
(
1
-
q
)
*
b
)
,
q
=
k
a
;
k
=
135
/
mean
,
k
=
max
(
1
,
min
(
k
,
7
)
)
;
wherein, a and b are constants, G (i,j) represents the value of the pixel at coordinates (i,j) in the exposure image G, and N (i,j) represents the value of the pixel at coordinates (i,j) in the sharpened image N;
step S 65 , obtaining R, G, B three-channel images E c corresponding to the output image E based on the exposure image G and the sharpened image N;
E
c
(
i
,
j
)
=
N
c
(
i
,
j
)
*
ω
+
G
c
(
i
,
j
)
*
(
1
-
ω
)
,
ω
=
1
/
L
(
i
,
j
)
f
;
f
=
P
1
w
*
h
;
wherein, c=[R,G,B], representing one of three channels R, G, and B, P 1 is a constant, E c (i,j) represents the value of the pixel at coordinates (i, j) in one of the R, G, B three-channel images corresponding to the output image E, N c (i,j) represents the value of the pixel at coordinates (i, j) in one of the R, G, B three-channel images corresponding to the sharpened image N, G c (i,j) represents the value of the pixel at coordinates (i, j) in one of R, G, B three-channel images corresponding to the exposure image G, L (i,j) represents the value of the pixel at coordinate (i,j) in the light image L; w and h represent the width and height of the sharpened image N, respectively; f is the proportion of the total number of pixels P 1 with grayscale values less than the preset second grayscale threshold in the light image L; ω is a weight coefficient, which is normalized to a value between 0 and 1;
step S 66 , merging three channels of the R, G, B three-channel images E c to form the output image E.
8 . An electronic device, comprising a memory and a processor, wherein the memory stores a computer program that runs on the processor, and the processor executes the program to implement steps of the image processing method, wherein the image processing method comprises:
obtaining an original image;
denoising the original image using an image filtering algorithm to form a preprocessed image S;
performing contrast enhancement in the preprocessed image S to form a contrast-enhanced image J;
adjusting saturation of the contrast-enhanced image J to form an enhanced display image M;
sharpening the enhanced display image M to form a sharpened image N; and
performing dynamic range enhancement on the sharpened image N using a dynamic range image enhancement algorithm to form an output image,
wherein the step “sharpening the enhanced display image M to form a sharpened image N” comprises:
step S 51 , extracting three-channel images light c of a brightness layer image for R, G, B three-channel images of the enhanced display image M using a guided filtering algorithm;
step S 52 , obtaining R, G, B three-channel images N c corresponding to the sharpened image N based on the three-channel images light c of the brightness layer image;
N
c
(
i
,
j
)
=
M
c
(
i
,
j
)
+
(
M
c
(
i
,
j
)
-
light
c
(
i
,
j
)
)
*
α
,
wherein, c=[R,G,B], representing one of three channels R, G, B, α is a constant, M c (i,j) represents the value of the pixel at coordinates (i,j) in one of the R, G, B three-channel images corresponding to the enhanced display image M, N c (i,j) represents the value of the pixel at coordinates (i,j) in one of the R, G, B three-channel images corresponding to the sharpened image N, and light c (i,j) represents the value of the pixel at coordinates (i,j) in one of the three-channel images of the brightness layer image;
step S 53 , merging three channels of the R, G, B three-channel images N c to form the sharpened image N;
wherein the method further comprises:
downsampling the enhanced display image M before step S 51 to form a downsampled image;
replacing the enhanced display image M with the downsampled image when performing step S 51 ; and
after step S 51 , upsampling the three-channel images light c formed in step S 51 to form three-channel images light c with the same size as the original image.