A method for restoring color of an underwater image, wherein comprising steps of:
- S1:
- obtaining 8-bit RGB pixel values of each pixel of an underwater image and converting the 8-bit RGB pixel values to a linear sRGB color space;
- that is, converting a pixel value ri-0 of the red channel, a pixel value gi-0 of the green channel, and a pixel value bi-0 of the blue channel of each pixel in 8-bit RGB, to obtain a pixel value ri-1 of the red channel, a pixel value gi-1 of the green channel, and a pixel value bi-1 of the blue channel of each pixel in a linear sRGB color space;
- S2:
- adjusting the pixel value of each channel of each pixel according to a mean value of the pixel value of each channel obtained in step S1, and obtaining an adjusted pixel value ri-2 of the red channel of each pixel, an adjusted pixel value gi-2 of the green channel, and an adjusted pixel value bi-2 of the blue channel;
- S3:
- calculating a weight value ωi of each pixel according to the adjusted pixel value of each channel of each pixel obtained in step S2;
- S4:
- calculating a gain Rg of the red channel and a gain Bg of the blue channel of the image according to the weight value ωi obtained in step S3;
- and adjusting, according to the gain Rg of the red channel and the gain Bg of the blue channel, the adjusted pixel value of each channel of each pixel obtained in step S2, to obtain an adjusted pixel value ri-3 of the red channel of each pixel, an adjusted pixel value gi-3 of the green channel, and an adjusted pixel value bi-3 of the blue channel;
- S5:
- converting the adjusted pixel values of each pixel in the linear sRGB color space obtained in step S4 to 8-bit RGB pixel values, and obtaining a pixel value ri-4 of the red channel, a pixel value gi-4 of the green channel, and a pixel value bi-4 of the blue channel of each pixel after conversion;
- S6:
- separately ranking the pixel value of each channel of each pixel obtained in step S5, and obtaining a large adjustment value and a small adjustment value of each channel according to a ranking result;
- i.e., a large adjustment value Rmax and a small adjustment value Rmin of the red channel, a large adjustment value Gmax and a small adjustment value Gmin of the green channel, and a large adjustment value Bmax and a small adjustment value Bmin of the blue channel;
- S7:
- adjusting, according to the large adjustment value and the small adjustment value of each channel obtained in step S6, the pixel values of each channel of each pixel obtained in step S5, and obtaining an adjusted pixel value ri-5 of the red channel, an adjusted pixel value gi-5 of the green channel, and an adjusted pixel value bi-5 of the blue channel of each pixel;
- and
- S8:
- fusing, according to the weight value ωi obtained in step S3, the 8-bit RGB pixel values of each pixel obtained in step S1 with the adjusted pixel value of each channel of each pixel obtained in step S7 to obtain a fused pixel value ri-6 of the red channel of each pixel, a fused pixel value gi-6 of the green channel, and a fused pixel value bi-6 of the blue channel;
- and outputting a restored underwater image according to the fused pixel value of each channel of each pixel.