How to Change Hue Level of an Image in Qt

Posted on Posted in Qt Tutorials, Tutorials

Qt offers convenient classes for basic image processing and pixel manipulation. In this article I am going to describe how you can change the hue level of a whole image using QImage class in Qt.

It’s quite simple as long as you know what hue is. So to start, let’s look at the following images:

All of these images have the same components in the HSV Color Space except their Hue value.

Below is how you can modify the Hue element of a whole image (QImage) in Qt:

for(int i=0; i<image.width(); i++)
for(int j=0; j<image.height(); j++)
QColor color = image.pixelColor(i,j);

int hue = color.hue();

// modify hue as you’d like and write back to the image
color.setHsv(hue, color.saturation(), color.value(), color.alpha());
image.setPixelColor(i, j, color);

Leave a Reply

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