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.
- 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.
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
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
-
Import the Module: Start by importing the necessary functions from the module.
from image_processing import convert_to_grayscale, convert_to_binary, save_image
-
Load an Image: Use PIL to load an image file.
from PIL import Image image = Image.open('path_to_your_image.jpg')
-
Convert to Grayscale:
grayscale_image = convert_to_grayscale(image)
-
Convert to Binary:
binary_image = convert_to_binary(grayscale_image, threshold=128)
-
Save the Processed Images:
save_image(grayscale_image, 'grayscale_image.png') save_image(binary_image, 'binary_image.png')
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.
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.
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.
Here are some examples of how to use the functions provided in this repository.
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')
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')
image-dimensionality-reduction/
β
βββ image_processing.py
βββ input_image.jpg
βββ README.md
βββ requirements.txt
- 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.
We welcome contributions to improve this project. If you would like to contribute, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make your changes.
- Submit a pull request with a clear description of your changes.
This project is licensed under the MIT License. See the LICENSE file for details.
For the latest updates and releases, visit the Releases section. Download the latest version and execute the provided scripts to start processing your images.
- Thanks to the contributors who have helped improve this project.
- Special thanks to the developers of NumPy and PIL for their excellent libraries.
For questions or suggestions, please reach out via the GitHub Issues page or contact the repository owner directly.
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.