This script removes shadows from images using a pre-trained convolutional neural network model.
To use the shadow remover script, follow these steps:
-
Prepare your image: Make sure your input image is in the same directory or provide the full path to the image.
-
Run the script:
Use the following command to run the script:
python shadow_remover.py -i <input_image_path> -o <output_image_path>
Replace
<input_image_path>
with the path to your input image and<output_image_path>
with the desired path for the output image.
The script consists of the following main components:
-
ShadowModel Class:
- A neural network model to remove shadows from images. The model contains several convolutional layers with ReLU activations.
-
load_image Function:
- Loads an RGBA image and splits it into RGB and alpha channels.
-
save_image Function:
- Combines the processed RGB image with the original alpha channel and saves it as an RGBA image.
-
process_image Function:
- Processes the input image using the ShadowModel and saves the output image.
-
Main Execution:
- The script uses argparse to handle command-line arguments, loads the pre-trained model, and processes the input image.
Before | After | Source |
---|---|---|
SD 3 | ||
Steam Game Screenshots FNAF 9 Ruin | ||
Steam Game Screenshots FNAF 9 Ruin | ||
Steam Game Screenshots FNAF 9 Ruin | ||
Steam Game Screenshots FNAF 9 Ruin | ||
Steam Game Screenshots FNAF 9 Ruin |
Make sure you have the following installed:
- Python 3.x
- PyTorch
- torchvision
- PIL (Python Imaging Library)
- numpy
-
Clone the repository:
git clone <repository_url> cd <repository_name>
-
Install the required packages: You can install the required packages using pip:
pip install torch torchvision pillow numpy
-
Place the model file: Ensure the pre-trained model file
shadowRM2.pth
is located in the same directory as the script.
The pre-trained model shadowRM2.pth
should be located in the same directory as the script. This model is loaded and used to process the input image to remove shadows.