Skip to content

TechDaDev/esrgan_streamlit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ESRGAN Ultrasound Image Denoising - Streamlit App

Python PyTorch Streamlit License

Interactive web application for medical ultrasound image denoising using ESRGAN

Demo โ€ข Installation โ€ข Usage โ€ข Features


๐ŸŽฏ Overview

This Streamlit application provides an interactive interface for enhancing noisy ultrasound images using a trained ESRGAN (Enhanced Super-Resolution Generative Adversarial Network) model. The app includes comprehensive quality metrics and visualization tools for evaluating denoising performance.

Key Features

  • ๐Ÿ–ผ๏ธ Interactive Image Enhancement - Upload and denoise ultrasound images in real-time
  • ๐Ÿ“Š Comprehensive Metrics - PSNR, SSIM, SNR, Variance, Edge Strength, Entropy, Contrast
  • ๐Ÿ” Visual Comparison - Side-by-side comparison of noisy, enhanced, and ground truth images
  • ๐Ÿ“ˆ Histogram Analysis - Pixel intensity distribution visualization
  • ๐Ÿ’พ Export Results - Download enhanced images and comparison plots
  • ๐Ÿš€ GPU Acceleration - Optional CUDA support for faster processing
  • โš™๏ธ Flexible Configuration - Adjustable model parameters and inference settings

๐Ÿ“‹ Requirements

Python Dependencies

streamlit>=1.28.0
torch>=2.0.0
torchvision>=0.15.0
numpy>=1.24.0
Pillow>=10.0.0
matplotlib>=3.7.0

Model Checkpoint

You'll need a trained ESRGAN model checkpoint (.pt file). The app expects:

  • Default path: models/esrgan_final.pt
  • Model configuration: nf=48, nb=11 (adjustable in sidebar)

๐Ÿš€ Installation

1. Clone the Repository

git clone https://github.com/TechDaDev/esrgan_streamlit.git
cd esrgan_streamlit

2. Create Virtual Environment (Recommended)

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

4. Add Model Checkpoint

Place your trained ESRGAN checkpoint in the models/ directory:

mkdir -p models
# Copy your checkpoint file
cp /path/to/your/esrgan_final.pt models/

Don't have a trained model? See Training Your Own Model section.


๐ŸŽฎ Usage

Launch the App

streamlit run streamlit_esrgan.py

The app will open in your default browser at http://localhost:8501

Using the Interface

  1. Configure Settings (Left Sidebar)

    • Set checkpoint path
    • Adjust model parameters (nf, nb)
    • Enable/disable GPU
    • Configure display options
  2. Upload Images

    • Noisy Image: The ultrasound image to enhance (required)
    • Ground Truth: Clean reference image (optional, for metrics)
  3. Enhance

    • Click "๐Ÿš€ Enhance Image" button
    • Wait for processing (GPU: ~0.5s, CPU: ~2-5s for 512x512 images)
  4. View Results

    • Visual comparison plots
    • Quality metrics dashboard
    • Histogram analysis (optional)
  5. Download

    • Enhanced image (PNG)
    • Comparison plot (PNG)

๐Ÿ“Š Quality Metrics Explained

Reference-Based Metrics (require ground truth)

Metric Description Good Range
PSNR Peak Signal-to-Noise Ratio >30 dB
SSIM Structural Similarity Index >0.90 (0-1 scale)
SNR Signal-to-Noise Ratio >25 dB

No-Reference Metrics

Metric Description Interpretation
Variance Detail preservation Too low = over-smoothing
Edge Strength Sharpness measure Higher = sharper
Entropy Information content Higher = more detail
Contrast Dynamic range Higher = better contrast
Noise Reduction Variance decrease Positive = noise removed

๐Ÿ—๏ธ Architecture

ESRGAN Model Structure

Input (1-channel grayscale)
    โ†“
Conv (3ร—3) โ†’ nf filters
    โ†“
[RRDB Block ร— nb]  โ† Residual-in-Residual Dense Blocks
    โ†“
Trunk Conv (3ร—3)
    โ†“
Upsampling (if scale > 1)
    โ†“
HR Conv + Output Conv
    โ†“
Output (1-channel, Tanh activation)

Default Configuration:

  • Number of filters (nf): 48
  • Number of RRDB blocks (nb): 11
  • Scale: 1 (denoising mode, no upsampling)
  • Parameters: ~6.2M

๐Ÿ–ผ๏ธ Demo

Example Enhancement

Noisy Input โ†’ ESRGAN Enhanced โ†’ Ground Truth

Input PSNR: 22.45 dB  โ†’  Enhanced PSNR: 30.96 dB  โ†’  Improvement: +8.51 dB
Input SSIM: 0.742     โ†’  Enhanced SSIM: 0.816     โ†’  Improvement: +0.074

๐ŸŽ“ Training Your Own Model

This app requires a pre-trained ESRGAN checkpoint. To train your own model:

  1. Prepare Dataset

    • Paired noisy/clean ultrasound images
    • Recommended: 100+ image pairs
    • Format: PNG, JPG (grayscale)
  2. Training Script

    • Use esrgan_phase1.py (not included in this repo)
    • Configuration: nf=48, nb=11, scale=1
    • Epochs: 15 pretrain + 60 GAN training
  3. Checkpoint

    • Copy final checkpoint: runs/ckpts/esrgan_final.pt
    • Place in models/ directory

Training code available at: [Your training repository link]


โš™๏ธ Configuration Options

Sidebar Settings

Model Settings:

  • Checkpoint Path: Path to .pt model file
  • Number of Filters (nf): Must match training (default: 48)
  • Number of RRDB Blocks (nb): Must match training (default: 11)
  • Use GPU: Enable CUDA acceleration

Inference Settings:

  • Max Image Dimension: Downscale limit (default: 1024)
    • Prevents OOM errors with large images
    • Images auto-scaled preserving aspect ratio

Evaluation Settings:

  • Show Quality Metrics: Display metric dashboard
  • Show Comparison Plot: Side-by-side visualization
  • Show Histogram Analysis: Pixel distribution plots

๐Ÿšจ Troubleshooting

Common Issues

1. GPU Out of Memory (OOM)

Solution: Reduce "Max Image Dimension" or disable GPU

2. Model Loading Error

Solution: Verify nf/nb match your checkpoint's training config

3. Import Error: No module named 'streamlit'

Solution: pip install -r requirements.txt

4. Checkpoint Not Found

Solution: Update checkpoint path in sidebar or add model to models/

๐Ÿ“ Repository Structure

esrgan_streamlit/
โ”œโ”€โ”€ streamlit_esrgan.py      # Main application
โ”œโ”€โ”€ requirements.txt          # Python dependencies
โ”œโ”€โ”€ README.md                 # This file
โ”œโ”€โ”€ LICENSE                   # MIT License
โ”œโ”€โ”€ .gitignore               # Git ignore rules
โ”œโ”€โ”€ models/                  # Model checkpoints (create this)
โ”‚   โ””โ”€โ”€ esrgan_final.pt     # Trained model (29MB)
โ””โ”€โ”€ examples/                # Example images (optional)
    โ”œโ”€โ”€ noisy_sample.png
    โ””โ”€โ”€ clean_sample.png

๐Ÿ”ง Advanced Usage

Custom Model Configuration

If your model uses different parameters:

# In sidebar, adjust:
nf = 64  # Your model's number of filters
nb = 23  # Your model's number of blocks

Batch Processing

For processing multiple images:

# See examples/batch_process.py (coming soon)

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ™ Acknowledgments

  • ESRGAN Architecture: Original ESRGAN Paper
  • Streamlit: For the amazing web framework
  • PyTorch: For deep learning infrastructure

๐Ÿ“ง Contact

Author: TechDaDev
GitHub: @TechDaDev
Repository: esrgan_streamlit


๐ŸŒŸ Star History

If you find this project useful, please consider giving it a star! โญ


Built with โค๏ธ using Streamlit and PyTorch

Back to Top

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages