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.
Make sure you have the following libraries installed in your Python environment:
- PIL (
pip install Pillow
) - NumPy (
pip install numpy
) - Matplotlib (
pip install matplotlib
)
- Import the necessary libraries in your Python script:
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
- Load the image using PIL:
image = Image.open("path_to_image")
- Convert the PIL image object 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()
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()
- Make sure to replace
"path_to_image"
with the actual path to your image file.
This project is licensed under the MIT License.
Contributions to this project are welcome! To contribute, please follow these steps:
- Fork this repository.
- Create a new branch:
git checkout -b my-feature-branch
. - Make your changes and commit them:
git commit -m "Add new feature"
. - Push to the branch:
git push origin my-feature-branch
. - Submit a pull request.
If you encounter any issues or have suggestions for improvement, please submit them in the issue tracker.
If you need any assistance or have any questions, feel free to contact the project maintainers at [email protected] Enjoy image processing with Python!