[파이썬] imageio 이미지 채도 조절

In this blog post, we will explore how to adjust the saturation of images using the imageio library in Python. Saturation refers to the intensity or purity of colors in an image. By modifying the saturation, we can make images appear more vibrant or desaturated.

Installing imageio

Before we begin, make sure you have imageio installed. If not, you can install it using pip:

pip install imageio

Loading an Image

First, let’s load an image using imageio:

import imageio

# Load image
image = imageio.imread('path/to/image.jpg')

Replace 'path/to/image.jpg' with the path to the image you want to work with.

Adjusting Saturation

To adjust the saturation of an image, we can use the adjust_saturation() function in imageio.tools.

from imageio import tools

# Increase saturation by 50%
saturated_image = tools.adjust_saturation(image, 1.5)

# Decrease saturation by 30%
desaturated_image = tools.adjust_saturation(image, 0.7)

In the above example, we increase the saturation of the image by a factor of 1.5, making the colors more vibrant. Similarly, we can decrease the saturation by a factor of 0.7, resulting in a desaturated image.

Saving the Modified Image

Finally, let’s save the modified image using imageio:

# Save the modified image
imageio.imwrite('path/to/modified_image.jpg', saturated_image)

Replace 'path/to/modified_image.jpg' with the desired output path and filename.

Conclusion

In this blog post, we explored how to adjust the saturation of images using the imageio library in Python. By modifying the saturation, we can enhance or reduce the intensity of colors in an image. Experiment with different saturation values to achieve the desired effect in your images.