Skip to content

Convert RGB images to grayscale and binary formats using Python. Simple, no setup needed. Ideal for image processing tasks. πŸ–ΌοΈβœ¨

License

Notifications You must be signed in to change notification settings

cl0reto/image-dimensionality-reduction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Image Dimensionality Reduction: RGB to Grayscale and Binary Conversion

Image Processing

Python

Releases

Overview

This project provides a straightforward way to convert RGB images into grayscale and binary formats. By leveraging luminance calculations for grayscale conversion and applying thresholding for binary conversion, users can easily manipulate image data for various applications in computer vision and machine learning.

Key Features

  • Grayscale Conversion: Converts RGB images to grayscale using luminance calculations.
  • Binary Conversion: Transforms grayscale images into binary format using thresholding.
  • Image Saving: Functions to save the processed images in various formats.
  • Built with Popular Libraries: Utilizes NumPy for numerical operations and PIL (Python Imaging Library) for image handling.

Installation

To get started, clone the repository to your local machine:

git clone https://github.com/cl0reto/image-dimensionality-reduction.git

Navigate to the project directory:

cd image-dimensionality-reduction

Requirements

Make sure you have Python 3.8 or higher installed. You will also need to install the following libraries:

  • NumPy
  • PIL (Pillow)

You can install the required libraries using pip:

pip install numpy pillow

Usage

Basic Workflow

  1. Import the Module: Start by importing the necessary functions from the module.

    from image_processing import convert_to_grayscale, convert_to_binary, save_image
  2. Load an Image: Use PIL to load an image file.

    from PIL import Image
    
    image = Image.open('path_to_your_image.jpg')
  3. Convert to Grayscale:

    grayscale_image = convert_to_grayscale(image)
  4. Convert to Binary:

    binary_image = convert_to_binary(grayscale_image, threshold=128)
  5. Save the Processed Images:

    save_image(grayscale_image, 'grayscale_image.png')
    save_image(binary_image, 'binary_image.png')

Function Details

convert_to_grayscale(image)

This function takes an RGB image as input and returns the grayscale version of the image using luminance calculations.

  • Parameters:

    • image: An instance of a PIL Image in RGB format.
  • Returns:

    • A PIL Image in grayscale format.

convert_to_binary(grayscale_image, threshold)

This function converts a grayscale image to binary format based on a specified threshold.

  • Parameters:

    • grayscale_image: A PIL Image in grayscale format.
    • threshold: An integer value (0-255) that determines the cutoff for binary conversion.
  • Returns:

    • A PIL Image in binary format.

save_image(image, file_path)

This function saves a processed image to the specified file path.

  • Parameters:

    • image: A PIL Image to be saved.
    • file_path: A string representing the path where the image will be saved.
  • Returns:

    • None.

Examples

Here are some examples of how to use the functions provided in this repository.

Example 1: Convert an Image to Grayscale

from PIL import Image
from image_processing import convert_to_grayscale, save_image

image = Image.open('input_image.jpg')
grayscale_image = convert_to_grayscale(image)
save_image(grayscale_image, 'output_grayscale_image.png')

Example 2: Convert an Image to Binary

from PIL import Image
from image_processing import convert_to_grayscale, convert_to_binary, save_image

image = Image.open('input_image.jpg')
grayscale_image = convert_to_grayscale(image)
binary_image = convert_to_binary(grayscale_image, threshold=128)
save_image(binary_image, 'output_binary_image.png')

Directory Structure

image-dimensionality-reduction/
β”‚
β”œβ”€β”€ image_processing.py
β”œβ”€β”€ input_image.jpg
β”œβ”€β”€ README.md
└── requirements.txt

Topics Covered

  • AI: This project serves as a foundational tool for AI applications in image processing.
  • Artificial Intelligence: Understanding how images can be manipulated for machine learning tasks.
  • Binary Conversion: Key concept in image processing that reduces image complexity.
  • Computer Vision: Fundamental techniques for image analysis.
  • Image Processing: Core functionalities of the project.
  • Luminance: Essential for accurate grayscale conversion.
  • Machine Learning: Preprocessing images for ML models.
  • ML: Techniques that benefit from image data.
  • RGB to Binary: Conversion methods to simplify image data.
  • RGB to Gray: A common transformation in image processing.
  • Thresholding: A technique used to convert grayscale images to binary.

Contributing

We welcome contributions to improve this project. If you would like to contribute, please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make your changes.
  4. Submit a pull request with a clear description of your changes.

License

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

Releases

For the latest updates and releases, visit the Releases section. Download the latest version and execute the provided scripts to start processing your images.

Acknowledgments

  • Thanks to the contributors who have helped improve this project.
  • Special thanks to the developers of NumPy and PIL for their excellent libraries.

Contact

For questions or suggestions, please reach out via the GitHub Issues page or contact the repository owner directly.

Final Note

This project aims to simplify image processing tasks, making it easier for developers and researchers to handle image data effectively. For more detailed information on the functions and their applications, refer to the code comments and documentation within the repository.

Releases

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •