Interactive web application for medical ultrasound image denoising using ESRGAN
Demo โข Installation โข Usage โข Features
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.
- ๐ผ๏ธ 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
streamlit>=1.28.0
torch>=2.0.0
torchvision>=0.15.0
numpy>=1.24.0
Pillow>=10.0.0
matplotlib>=3.7.0
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)
git clone https://github.com/TechDaDev/esrgan_streamlit.git
cd esrgan_streamlit
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
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.
streamlit run streamlit_esrgan.py
The app will open in your default browser at http://localhost:8501
-
Configure Settings (Left Sidebar)
- Set checkpoint path
- Adjust model parameters (
nf
,nb
) - Enable/disable GPU
- Configure display options
-
Upload Images
- Noisy Image: The ultrasound image to enhance (required)
- Ground Truth: Clean reference image (optional, for metrics)
-
Enhance
- Click "๐ Enhance Image" button
- Wait for processing (GPU: ~0.5s, CPU: ~2-5s for 512x512 images)
-
View Results
- Visual comparison plots
- Quality metrics dashboard
- Histogram analysis (optional)
-
Download
- Enhanced image (PNG)
- Comparison plot (PNG)
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 |
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 |
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
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
This app requires a pre-trained ESRGAN checkpoint. To train your own model:
-
Prepare Dataset
- Paired noisy/clean ultrasound images
- Recommended: 100+ image pairs
- Format: PNG, JPG (grayscale)
-
Training Script
- Use
esrgan_phase1.py
(not included in this repo) - Configuration:
nf=48
,nb=11
,scale=1
- Epochs: 15 pretrain + 60 GAN training
- Use
-
Checkpoint
- Copy final checkpoint:
runs/ckpts/esrgan_final.pt
- Place in
models/
directory
- Copy final checkpoint:
Training code available at: [Your training repository link]
Model Settings:
Checkpoint Path
: Path to.pt
model fileNumber 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 dashboardShow Comparison Plot
: Side-by-side visualizationShow Histogram Analysis
: Pixel distribution plots
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/
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
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
For processing multiple images:
# See examples/batch_process.py (coming soon)
This project is licensed under the MIT License - see the LICENSE file for details.
- ESRGAN Architecture: Original ESRGAN Paper
- Streamlit: For the amazing web framework
- PyTorch: For deep learning infrastructure
Author: TechDaDev
GitHub: @TechDaDev
Repository: esrgan_streamlit
If you find this project useful, please consider giving it a star! โญ
Built with โค๏ธ using Streamlit and PyTorch