Retinal Vessel Segmentation
A clean, reproducible U-Net pipeline for segmenting blood vessels in fundus images.
Pairs fundus images with vessel masks, trains a U-Net in PyTorch and visualizes predicted vessel maps. Accurate vessel segmentation supports early diagnosis of diabetic retinopathy and related conditions.
README · rendered from GitHub
Retina Vessel Segmentation using U-Net
Project goal is to automatically segment blood vessels from retinal images using a convolutional encoder decoder architecture. Accurate vessel segmentation helps in early diagnosis of diseases such as diabetic retinopathy, glaucoma, hypertension, and cardiovascular disorders. This project focuses on segmenting retinal blood vessels from fundus images using a U Net based deep learning model. The goal is to build a simple, clear, and reproducible pipeline that loads the dataset, pairs images with their masks, trains a U Net, evaluates the model, and visualizes the predicted segmentation maps. The notebook includes complete data preprocessing, model architecture, training loop, loss calculation, visualization of results, and basic performance checks. This is a self driven side project created to improve understanding of image segmentation, medical imaging workflows, and deep learning experiment design. Everything is kept straightforward so the project can be extended later for other datasets or accelerated hardware platforms.
Features
- Complete preprocessing of fundus images and corresponding vessel masks
- Automatic pairing of images and labels using file basename
- U Net architecture implemented in PyTorch
- Training and validation loops with loss tracking
- Visualization of predictions and ground truth masks
- Lightweight and easy to run on GPU or CPU
- Notebook focused workflow for learning and experiments
Dataset
The project uses retinal fundus images along with manually annotated vessel masks. Files are paired by matching the same basename.
https://www.kaggle.com/datasets/abdallahwagih/retina-blood-vessel
Details:
- Contains 40 high resolution fundus images
- Includes manually annotated vessel masks
- Standard train–test split provided
- Image and mask filenames match by basename
- Mask represents pixel level blood vessel boundaries
Folder format expected:
images/
image_01.png
image_02.png
masks/
image_01.png
image_02.png
Why U Net
- Works well for pixel level segmentation
- Performs well on small medical datasets
- Preserves spatial details using skip connections
- Handles thin structures like blood vessels
- Efficient and easy to train
Model Information
Architecture: U Net Key components:
- Encoder: series of convolutions that reduce spatial size
- Decoder: upsampling layers that recover resolution
- Skip connections: pass encoder features to decoder for detail recovery
- Output: binary mask of vessel and non vessel pixels
Activation used for mask: Sigmoid Loss function (typical): Binary Cross Entropy Possible improvements: Dice loss or BCE + Dice hybrid
Visualizations Included
Notebook contains:
- Random sample image and mask preview
- Predicted vessel maps
- Training loss curve
- Side by side comparisons
Workflow Overview
- Load image and mask paths
- Pair images and masks by matching filenames
- Preprocess both (resize, normalize, convert to tensor)
- Create PyTorch Dataset and DataLoader
- Build U Net model
- Train the model for fixed epochs
- Track training and validation loss
- Generate sample predictions
- Visualize predicted mask vs ground truth
- Save results
Results Summary
- The U Net model successfully identifies major and minor retinal vessels
- Thin vessel structures are captured but can improve with augmentation
- Output masks align well with ground truth when trained properly
- Performance depends strongly on preprocessing and loss function
Limitations
- Dataset is small (only 40 images)
- Thin vessels are hard to detect
- No augmentation currently reduces generalization
- Model can overfit without validation monitoring
Tools Used
- Python
- PyTorch
- NumPy
- Matplotlib
- Jupyter Notebook
- DRIVE dataset
Future Improvements
- Use larger retinal datasets like STARE or CHASE DB1
- Optimize model for edge devices or real time use
- Replace base U-Net with Attention U Net or Residual U-Net
More in Vision
Related projects
Vision2025Real-Time Fabric Defect Detection
Six classical detectors fused by IoU, running live on a Jetson Nano.
- Python
- OpenCV
- NumPy
- SciPy
Vision2025Lightweight U-Net for Driving Scenes
A U-Net compressed from 8.7M to 0.53M parameters without losing the skip connections.
- Python
- PyTorch
- TensorFlow
- OpenCV
Vision2025Stereo Depth Estimation
Disparity and depth maps from a calibrated stereo pair, with classical vision only.
- Python
- OpenCV
- NumPy