Skip to content

CodeThread386/RGB2Gray

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ Medical Image Processor - RGB to Grayscale Converter

A high-performance web application that converts RGB medical images to grayscale using Ray Framework for distributed computing. Built as a demonstration of parallel processing techniques in computer architecture for medical imaging applications.

Python Ray Flask License

✨ Features

  • πŸš€ Distributed Processing: Leverages Ray framework to parallelize image conversion across multiple CPU cores
  • πŸ“Š Performance Metrics: Real-time processing time comparison between parallel and sequential execution
  • 🎨 Modern UI: Clean, responsive interface with drag-and-drop file upload
  • πŸ‘οΈ Visual Comparison: Side-by-side preview of original and processed images
  • ⬇️ Easy Download: One-click download of processed grayscale images
  • πŸ₯ Medical Imaging Standard: Uses luminosity method (0.299R + 0.587G + 0.114B) for accurate grayscale conversion

🎯 Project Overview

This project demonstrates the practical application of distributed computing frameworks in medical image processing. By splitting image data into chunks and processing them in parallel using Ray workers, we achieve significant performance improvements over traditional sequential processing.

Why Ray Framework?

  • Scalability: Automatically distributes tasks across available CPU cores
  • Performance: Achieves up to 2-4x speedup on large medical images
  • Simplicity: Clean API with minimal code changes from sequential implementation
  • Real-world Application: Same framework used by companies like OpenAI, Uber, and Spotify

πŸ› οΈ Technology Stack

Backend:

  • Python 3.11
  • Ray 2.9.0 (Distributed Computing)
  • Flask 3.0.0 (Web Framework)
  • NumPy (Numerical Processing)
  • Pillow (Image Processing)

Frontend:

  • HTML5
  • CSS3 (Modern Gradient Design)
  • Vanilla JavaScript (No dependencies)

πŸ“‹ Prerequisites

  • Python 3.11 or 3.12 (Ray doesn't support Python 3.13+ yet)
  • pip (Python package manager)
  • Git

πŸš€ Installation & Setup

1. Clone the Repository

git clone https://github.com/CodeThread386/RGB2Gray.git
cd RGB2Gray

2. Create Virtual Environment

# Windows
py -3.11 -m venv ray_env
ray_env\Scripts\activate

# Mac/Linux
python3.11 -m venv ray_env
source ray_env/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Run the Application

# Start the Flask backend
python app.py

The server will start on http://localhost:5000

5. Open the Frontend

Simply open index.html in your web browser, or serve it using:

python -m http.server 8000

Then navigate to http://localhost:8000/index.html

πŸ“– Usage

  1. Upload Image: Click the upload area or drag & drop a medical image (JPG, PNG, BMP)
  2. Processing: The application automatically processes the image using Ray's distributed framework
  3. View Results: See the original and grayscale images side-by-side with processing metrics
  4. Download: Click the download button to save the grayscale image

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Frontend      β”‚
β”‚   (HTML/CSS/JS) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚ HTTP Request
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Flask Backend  β”‚
β”‚   (REST API)    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Ray Framework  β”‚
β”‚  (Distributed   β”‚
β”‚   Processing)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
β”‚ CPU  β”‚ CPU  β”‚ CPU  β”‚ CPU  β”‚
β”‚Core 1β”‚Core 2β”‚Core 3β”‚Core 4β”‚
β””β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”˜

How It Works

  1. Image Upload: User uploads an RGB image through the web interface
  2. Image Splitting: Backend divides the image into N chunks (default: 4)
  3. Parallel Processing: Ray distributes chunks to available CPU cores
  4. Grayscale Conversion: Each worker applies the luminosity formula independently
  5. Result Aggregation: Processed chunks are combined into final grayscale image
  6. Response: Frontend displays results with performance metrics

πŸ”¬ Grayscale Conversion Formula

We use the Luminosity Method, which is the industry standard for medical imaging:

Grayscale = 0.299 Γ— Red + 0.587 Γ— Green + 0.114 Γ— Blue

This method accounts for human perception, where green appears brighter than red, and red appears brighter than blue.

πŸ“Š Performance Analysis

Test Image: 2000x2000 pixels

Method Processing Time Speedup
Sequential 0.0842s 1.00x
Ray (4 cores) 0.0234s 3.60x

Results may vary based on image size and CPU specifications

🌐 Deployment

Render.com (Recommended)

  1. Push your code to GitHub
  2. Connect your repository to Render
  3. Configure:
    • Build Command: pip install -r requirements.txt
    • Start Command: gunicorn app:app
  4. Deploy!

Your app will be live at: https://your-app-name.onrender.com

πŸ“ Project Structure

RGB2Gray/
β”‚
β”œβ”€β”€ app.py                  # Flask backend server
β”œβ”€β”€ index.html              # Frontend interface
β”œβ”€β”€ requirements.txt        # Python dependencies
β”œβ”€β”€ .gitignore             # Git ignore file
└── README.md              # Project documentation

🀝 Contributing

Contributions are welcome! Feel free to:

  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

πŸ“ Future Enhancements

  • Support for batch processing multiple images
  • Additional image filters (blur, sharpen, edge detection)
  • Real-time video stream processing
  • GPU acceleration with Ray
  • Export processing statistics as CSV
  • Support for DICOM medical image format
  • Integration with cloud storage (AWS S3, Google Cloud)

πŸ› Known Issues

  • Ray framework requires Python 3.11 or 3.12 (not compatible with 3.13+)
  • Large images (>10MB) may take longer to upload on slower connections

πŸ“š Learn More

πŸ‘¨β€πŸ’» Author

Sarthak

πŸ“„ License

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

πŸ™ Acknowledgments

  • Ray Framework team for creating an amazing distributed computing library
  • Computer Architecture course for the project inspiration
  • Medical imaging community for standardized grayscale conversion methods

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors