Write a function to convert the image attached on the top of this page to grayscale.
时间: 2024-05-01 20:18:45 浏览: 102
uas.rar_SCSI uas_The Mass_USB Attached SCSI_uas_usb SCSI
5星 · 资源好评率100%
Sure, here's a code snippet in Python to convert an image to grayscale:
```python
from PIL import Image
def convert_to_grayscale(image_path):
# Open the image
image = Image.open(image_path)
# Convert to grayscale
grayscale_image = image.convert('L')
# Save the grayscale image
grayscale_image.save('grayscale_' + image_path)
```
You can call this function with the path to your image file as the argument. This will convert the image to grayscale and save the result as a new image file with "grayscale_" prefix.
阅读全文