Have you ever wanted to animate the hue of an image? We did recently but we didn’t quite know how so we developed an application using python to help us do just that.

Before we get started, though, let’s take a moment to learn what exactly is hue?

Hue, in the context of color theory, refers to the attribute of a color that enables us to classify it as red, blue, green, or any other color in the spectrum. It represents the pure spectrum colors found on the color wheel, which range from red through to violet, plus magenta.

A hue spectrum that startes at 0 degrees and ends at 360 degrees.

So to shift the hue is to change it’s color to a different one corresponding to a 360 degree color wheel/spectrum.

Red, green, and blue are often placed at 120-degree intervals on the wheel (0° for red, 120° for green, 240° for blue). Colors like cyan, magenta, and yellow are located at the halfway points between the primary colors. For example, cyan is at 180°, halfway between green (120°) and blue (240°).

Animating Hue in a still image

So to recap, we knew if we could achieve this, it would look great, to say the least. And that was good enough for us to get started.

To demonstrate our progress we first used DALL-E to generate a colorful image, with jungles, and dinosaurs, and the Python logo because we would be using the Python coding language to generate the animation:

A graphical image with the python logo in the center that is surrounded by jungle and dinosaurs, both land creatures and flying creatures. Bright colors. It will look very good animated.
We’ve used Dalle to generate colorful image with dinosaurs and the python logo.

Now that we’ve chosen a very colorful base image to begin with, we run it through code base with an instruction to animate from -180 to 180 degrees over 30 frames and a few minutes later we have generated this mp4:

We also generated the animation as a gif. The MP4, though, is under 2mb and loads nearly instantly on this blog post where we have set it to autoplay and loop (autoplay may not work on mobile).

The gif, however, being 30 frames, at the size of 1024 x 1024, comes out to be a whopping 18mb.

Py Animate Hue – How to Download and Features

Py Animate Hue has been released as open source software and is available on GitHub to download.

https://github.com/gbti-labs/py-animate-hue

In addition to Hue, we coded in the ability to animate Brightness as well as Contrast.

In the future we may add more support for different animation features, but for now, please feel free to star our repository, fork it if you like, and join our discord and socials to follow more open source opportunities.

Thanks for reading!

If you like our content, please consider following us! If you like our free open source assets, please give them a github star. We’re also happy to have lurkers on our Discord community where we manage our syndication network and curate together.

We are also on Dev.to, Daily.dev, Hashnode.

Leave a Reply

Your email address will not be published. Required fields are marked *