Skip to content

Latest commit

 

History

History
108 lines (72 loc) · 2.45 KB

File metadata and controls

108 lines (72 loc) · 2.45 KB

Image Processing Into Black and White

This repository contains a Python script that uses the PIL (Python Imaging Library) and NumPy libraries to convert a colorful photo into black and white. Please note that the front end is still under development.

Preview

Untitled

Prerequisites

Make sure you have the following libraries installed in your Python environment:

  • PIL (pip install Pillow)
  • NumPy (pip install numpy)
  • Matplotlib (pip install matplotlib)

Usage

  1. Import the necessary libraries in your Python script:
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
  1. Load the image using PIL:
image = Image.open("path_to_image")
  1. Convert the PIL image object to a NumPy array:
arr = np.array(image)
  1. Display the original image:
plt.imshow(arr)
plt.show()
  1. Convert the image to grayscale:
grey = arr.mean(axis=2)
  1. Display the grayscale image:
plt.imshow(grey, cmap="gray")
plt.show()

Example

Here's an example of how to use the provided code:

from PIL import Image
import numpy as np
import matplotlib.pyplot as plt

# Load the image
image = Image.open("path_to_image")

# Convert the image to a NumPy array
arr = np.array(image)

# Display the original image
plt.imshow(arr)
plt.show()

# Convert the image to grayscale
grey = arr.mean(axis=2)

# Display the grayscale image
plt.imshow(grey, cmap="gray")
plt.show()

Note

  • Make sure to replace "path_to_image" with the actual path to your image file.

License

This project is licensed under the MIT License.

Contributions

Contributions to this project are welcome! To contribute, please follow these steps:

  1. Fork this repository.
  2. Create a new branch: git checkout -b my-feature-branch.
  3. Make your changes and commit them: git commit -m "Add new feature".
  4. Push to the branch: git push origin my-feature-branch.
  5. Submit a pull request.

If you encounter any issues or have suggestions for improvement, please submit them in the issue tracker.

Support

If you need any assistance or have any questions, feel free to contact the project maintainers at [email protected] Enjoy image processing with Python!