Changing Hue

Introduction

Hue modification is a fundamental aspect of image processing. It involves altering the color properties of an image to achieve desired aesthetic or analytical outcomes. In this context, we introduce the change_hue function from the visumorph package, designed to adjust the hue of an image efficiently and effectively.

The change_hue function serves to blend a given image with a specified color layer, altering its hue. This function gets three parameters - image, color and delta_hue and returns a visumorph Image object.

This function finds applications in areas such as artistic image transformation, data visualization, and preprocessing in machine learning pipelines where color normalization or adjustment is required.

Importing libraries

Here we import change hue and visumorph: For handling image-specific data structures and functions. Utilizing the Python Imaging Library (PIL), imported as PImage to avoid conflicts, we enable robust image manipulation capabilities. The display function from IPython is employed to showcase the transformations within the Jupyter notebook environment, providing a clear, interactive illustration of how change_hue can be applied to achieve desired visual outcomes in image processing tasks.

from visumorph import change_hue, load_image, Image
from PIL import Image as PImage
from IPython.display import display

Loading Input Image

This code demonstrates loading an image using load_image function. The image file should be in a format compatible with the library (JPG or PNG). Then, we use fromarray function of PIL to convert the image to PImage object so that we can display the image here.

img = load_image("../tests/img/raw/meme.jpg")
meme = PImage.fromarray(img.image)
display(meme)
_images/ec3137c8308ebefcfd5472e1a81fea434bfc903076aec94287e9ab660ac9cfaa.png

Output Image

Utilizing the change_hue function from the visumorph package, we have the capability to modify the hue of an image to adjust its overall color balance. In this specific instance, by setting the color parameter to red and the delta_hue to 0.4, we are directing the function to infuse the image with a reddish tint. This precise manipulation adds a subtle yet distinct red overlay, effectively altering the image’s original color scheme and enhancing it with a warmer tone. The delta_hue parameter controls the intensity of the hue shift, allowing for fine-tuning of the effect to achieve the desired visual outcome.

img_hue_1 = change_hue(img, color="red", delta_hue=0.4)
meme_hue_1 = PImage.fromarray(img_hue_1.image)
display(meme_hue_1)
_images/23180632b4217fb293eac55fcf7ac91c6f1f6dc6d71dd6a70c74cec0e1d59121.png

To illustrate the change_hue function’s capability, we adjust the delta_hue parameter to 1, effectively saturating the image with a single hue. By specifying the color parameter as blue and delta_hue to 1, the result is an image that retains the original structure and contours but is now uniformly shaded in a solid blue color.

img_hue_2 = change_hue(img, color="blue", delta_hue=1)
meme_hue_2 = PImage.fromarray(img_hue_2.image)
display(meme_hue_2)
_images/ce9931ef4133c0569f237f3148bd734a7622f1e0eef9e2b35dcd80110dd0f791.png