Welcome to the Noising and Denoising of Images repository! This project demonstrates the application of deep learning techniques to add noise to images and then reconstruct the original images by removing the noise using a denoising autoencoder.
The goal of this project is to explore image noising and denoising tasks using a custom PyTorch dataset and a denoising autoencoder. It introduces artificial noise into images and then trains a model to recover the original images, making it a useful application in fields like image restoration, medical imaging, and computer vision preprocessing.
Key Features:
- Custom Dataset class for flexible image loading and noising.
- Noise types supported: Gaussian noise (extendable to others).
- Denoising Autoencoder using convolutional layers for image reconstruction.
A custom PyTorch Dataset
class is used to handle image loading and augmentation:
- Directory-based Loading: Recursively loads images from a given directory (
root_dir
). - Noise Addition: Adds noise to images using the
random_noise
function fromskimage
.
root_dir
: Path to the directory containing images.transform
: Optional PyTorch transforms applied to the images.noise_type
: Type of noise to add (default:gaussian
).noise_amount
: Intensity of the noise (variance for Gaussian noise).
dataset = NoisyImageDataset(
root_dir="data/train",
transform=transform,
noise_type="gaussian",
noise_amount=0.1
)
This project uses a convolutional autoencoder, a deep learning model designed to encode the input to a lower-dimensional representation and then decode it back to the original dimensions.
- Encoder:
- Downsamples the image using convolutional layers.
- Extracts important features for reconstruction.
- Decoder:
- Reconstructs the original image from the encoded features using transposed convolutions.
class DenoisingAutoencoder(nn.Module):
def forward(self, x):
x = self.encoder(x)
x = self.decoder(x)
return x
- Python 3.8+
- PyTorch 1.10+ (with CUDA support for GPU acceleration)
- Additional libraries:
torchvision
,Pillow
,scikit-image
-
Clone the repository:
git clone https://github.com/username/noising-denoising-images.git cd noising-denoising-images
-
Install the dependencies:
pip install -r requirements.txt
-
Organize your dataset such that all images are in a directory (e.g., data/train). Train the model:
python train.py
-
Evaluate the model:
python evaluate.py
The model effectively removes Gaussian noise from images after training. Below is an example of the output:
The image showcases three sections:
- Input (Noisy): The input image with added Gaussian noise.
- Output (Denoised): The reconstructed image after denoising by the model.
- Ground Truth: The original, clean image for comparison.
- Add support for additional noise types (e.g., salt-and-pepper, speckle noise).
- Enhance the architecture using advanced models (e.g., U-Net or residual connections).
- Extend the project to handle video denoising tasks.
- Explore transfer learning for domain-specific denoising tasks.