Corrects underwater images by bringing out reds and bringing down blues and greens
Underwater Photo Correction in Python (Windows)
Mark Lundine
Rationale: Underwater photos become enriched in blues and greens while losing most of their red color.
Solution: Shift the pixels around to heighten the reds and bring down the blues and greens. Make this automated instead of using expensive and time-intensive software like Photoshop.
Credits: The basis of this algorithm was adapted into Python from some Javascript code available at https://github.com/nikolajbech/underwater-image-color-correction
How-To-Use (with GUI):
Download this github repo to your computer and unzip it into your C-Drive, with the first folder named Image_Correction_App.
Only Read this section if you are using a mac, also if you have a mac try these steps and let me know if this works
The repo here will work with Windows, but it can be made to work with Macs by first downloading ffmpeg from: https://ffmpeg.zeranoe.com/builds/
You would want the top version, macOS 64-bit, static. Replace the ffmpeg folder residing in /Image_Correction_App with this folder. Make sure it is unzipped and named ffmpeg, without all of the extra characters it puts in the name when downloaded.
You also need to build a static version of the main.py script. To do so, open up terminal.
Type these commands, hitting enter after each one:
pip install PIL
pip install numpy
pip install sk-video
pip install pyqt5
pip install scipy
pip install pyinstaller
pip install opencv-python
Wait for that to finish, then type this command, filling in the blank line with the directory you saved the github repo to:
cd _____/Image_Correction_App
The final command you must type is the following:
pyinstaller --onefile main.py
This should make an application folder that contains the app file. Move it into /Image_Correction_App. Double click on it to run.
How-To-Use Continued
Download the exe at https://github.com/mlundine/Image_Correction_App/releases
Place this exe, UnderwaterImageApp.exe, in the Image_Correction_App folder.
Double click it to run the GUI.
This will bring up the GUI.
There are four parameters that can be changed:
MIN_AVG_RED, MAX_HUE_SHIFT, BLUE_MAGIC_VALUE, SHARPEN
Base values:
MIN_AVG_RED = 60
MAX_HUE_SHIFT = 120
BLUE_MAGIC_VALUE = 1.2
SHARPEN = 1
Each option will save the result in a new folder called 'correction_results', which can be found in /Image_Correction_App/dist, the folder that main.exe resides in.
To select an image, you just hit 'Single Image' and navigate to the image you want to run the algorithm on. When an image is selected, it will display in the GUI. Then you hit the 'Run' button, and it will run the algorithm, save the image as a jpeg with 'cc' at the end, and then a timestamp (YYYMMDDHHHHSS) and then display the result in the GUI.
To select a folder of images, hit 'Batch of Images' and then navigate to the folder. This will display the filepaths of all of the images seen in the selected folder. If there are more than 30 images, it will just say Working on: 'your/folder/name'. Hit 'Run' and it will run the algorithm on every image in that folder. You will know it's done once the 'Run' button is no longer highlighted.
To select a single video, hit 'Single Video', navigate to the video (only mp4s work), and then hit 'Run'. This will take a long time, particularly for videos longer than a few minutes. This will display the file path to that video. It is finished once the 'Run' button is no longer highlighted.
There are some sample images to play with in /Image_Correction_App/test_images.