Skip to content

Repository files navigation

UltraDiffusion: Advanced Ultrasound Image Denoising with Diffusion Models

A Final Year Project (FYP) focusing on enhancing ultrasound imaging quality through state-of-the-art Denoising Diffusion Probabilistic Models (DDPMs). This project combines cutting-edge deep learning techniques with medical imaging to improve diagnostic precision and image clarity.

Project Banner Tech Stack Status

🎯 Project Overview

UltraDiffusion addresses the critical challenge of noise in ultrasound imaging, particularly speckle noise and low contrast issues that affect diagnostic accuracy. By leveraging fine-tuned Stable Diffusion models with specialized architectures, this project delivers real-time image enhancement suitable for clinical applications.

Key Features

  • 🧠 AI-Powered Denoising: Fine-tuned Stable Diffusion with UNet2DCondition architecture
  • ⚑ Real-time Processing: Optimized with mixed-precision training (FP16) and Hugging Face Accelerate
  • πŸ“Š Comprehensive Metrics: PSNR, SSIM, and LPIPS evaluation metrics
  • πŸ”§ Classical Filters: Gaussian, Median, and Non-Local Means filters for comparison
  • 🌐 Interactive Web Interface: Modern React-based frontend for easy image processing
  • πŸ“± Responsive Design: Works seamlessly across desktop and mobile devices

πŸ—οΈ Architecture

Frontend (React + TypeScript)

  • Framework: React 18 with TypeScript
  • Routing: React Router DOM for navigation
  • Styling: Tailwind CSS for modern UI design
  • Icons: Lucide React for consistent iconography
  • Build Tool: Vite for fast development and optimized builds

Backend (Python + PyTorch)

  • Deep Learning: PyTorch with Diffusers library
  • Model Architecture: Stable Diffusion v1.5 with custom fine-tuning
  • API Framework: Flask with CORS support
  • Image Processing: PIL, scikit-image, OpenCV
  • Metrics: LPIPS, PSNR, SSIM for quantitative evaluation

Model Components

  • UNet2DConditionModel: Core denoising architecture
  • AutoencoderKL: Latent space compression
  • CLIPTextModel & Tokenizer: Text conditioning (if applicable)
  • DDPMScheduler: Diffusion process scheduling

πŸš€ Getting Started

Prerequisites

  • Node.js (v16 or higher)
  • Python (v3.8 or higher)
  • CUDA-compatible GPU (recommended for optimal performance)
  • Git for version control

Frontend Setup

  1. Clone the repository

    git clone https://github.com/AselInukeHidallearachchi/FYP-IIT-UltraDiffusion.git
    cd UltraDiffusionFE(V2)
  2. Install dependencies

    npm install
  3. Start development server

    npm run dev
  4. Build for production

    npm run build

Backend Setup

  1. Navigate to the API directory

    cd api
  2. Install Python dependencies

    pip install flask flask-cors diffusers transformers torch pillow pyngrok py7zr lpips scikit-image scipy
  3. Download the trained model

    • The notebook includes automatic model download from MediaFire
    • Alternatively, manually download and extract the model files to ./models/trainedModel/
  4. Run the Jupyter notebook

    jupyter notebook "difapi-version-4-0 (1).ipynb"

πŸ“– Usage

Web Interface

  1. Home Page: Overview of the project and technology features
  2. Denoise Images: Upload ultrasound images for AI-powered denoising
  3. Filters: Apply classical denoising filters (Gaussian, Median, Non-Local Means)
  4. About: Learn more about the project objectives and methodology

API Endpoints

  • POST /denoiser/: Upload image for diffusion-based denoising

    • Parameters: image, strength (0.1-1.0), steps (50-200)
    • Returns: Enhanced image with evaluation metrics
  • POST /filters/: Apply classical filters to uploaded image

    • Parameters: image
    • Returns: Filtered images (Gaussian, Median, NLM)

Evaluation Metrics

  • PSNR (Peak Signal-to-Noise Ratio): Higher values indicate better quality
  • SSIM (Structural Similarity Index): Values closer to 1 indicate better similarity
  • LPIPS (Learned Perceptual Image Patch Similarity): Lower values indicate better perceptual similarity

πŸ§ͺ Testing

Frontend Testing

# Run all tests
npm test

# Run tests with coverage
npm run test:coverage

# Run tests in watch mode
npm run test:watch

Test Structure

  • Unit Tests: Component-level testing with Jest and React Testing Library
  • Integration Tests: Full application flow testing
  • Coverage Reports: Generated in /coverage directory

πŸ”§ Configuration

Frontend Configuration

  • Vite Config: vite.config.ts - Build and development settings
  • TypeScript: tsconfig.json - Type checking configuration
  • Tailwind CSS: tailwind.config.js - Styling framework setup
  • ESLint: eslint.config.js - Code linting rules

API Configuration

  • Model Settings: Adjustable strength and diffusion steps
  • Device Selection: Automatic CUDA/CPU detection
  • CORS Settings: Configured for cross-origin requests

πŸ“ Project Structure

UltraDiffusionFE(V2)/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ components/           # Reusable React components
β”‚   β”‚   β”œβ”€β”€ ImageUpload.tsx   # File upload component
β”‚   β”‚   β”œβ”€β”€ Layout.tsx        # Main layout wrapper
β”‚   β”‚   └── MetricsLoader.tsx # Loading state for metrics
β”‚   β”œβ”€β”€ pages/                # Page components
β”‚   β”‚   β”œβ”€β”€ Home.tsx          # Landing page
β”‚   β”‚   β”œβ”€β”€ Denoise.tsx       # AI denoising interface
β”‚   β”‚   β”œβ”€β”€ Filters.tsx       # Classical filters interface
β”‚   β”‚   └── About.tsx         # Project information
β”‚   β”œβ”€β”€ __tests__/            # Test files
β”‚   β”œβ”€β”€ App.tsx               # Main application component
β”‚   β”œβ”€β”€ main.tsx              # Application entry point
β”‚   └── config.ts             # API configuration
β”œβ”€β”€ api/
β”‚   └── difapi-version-4-0 (1).ipynb  # Backend API notebook
β”œβ”€β”€ notebook/
β”‚   └── Denoicer V5.1 (6).ipynb       # Model training notebook
β”œβ”€β”€ coverage/                 # Test coverage reports
β”œβ”€β”€ package.json              # Node.js dependencies
β”œβ”€β”€ vite.config.ts            # Vite configuration
β”œβ”€β”€ tailwind.config.js        # Tailwind CSS configuration
└── README.md                 # Project documentation

πŸ”¬ Research & Methodology

Dataset

  • Ultrasound images with realistic noise patterns
  • Speckle noise augmentation for robust training
  • Validation on clinical-quality imaging data

Model Training

  • Base Model: Stable Diffusion v1.5
  • Fine-tuning: Custom UNet2D architecture
  • Loss Functions: LPIPS perceptual loss + L2 reconstruction
  • Optimization: Mixed-precision training with gradient scaling

Evaluation Metrics

  • Quantitative: PSNR, SSIM scores
  • Perceptual: LPIPS distance measurements
  • Clinical: Visual quality assessment by domain experts

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ™ Acknowledgments

  • Hugging Face for the Diffusers library
  • OpenAI for Stable Diffusion methodology
  • Medical imaging community for dataset insights
  • Academic supervisors and mentors

get new link to ARCHIVE_DOWNLOAD_URL copy api to API_BASE_URL (only to .app) npm run dev

Note: This project is for academic and research purposes. For clinical applications, please ensure proper validation and regulatory compliance.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages