1

I'm interested in equalizing a color image. What I'm doing is to start with an RGB image and convert it to YIQ values according to this article. After that I can obtain a greyscale version of the image by considering luminance levels given by Y. Applying an algorithm to that greyscale image, I can get a more or less equalized version of the greyscale version of the original image. I'd like to produce a new RGB image that preserves the colors of the original one and corrects the luminance values, to get a luminance-equalized RGB version of the original image.

First, I tried to convert the YIQ values back to RGB but considering for Y the modified values after equalization. With this approach I got RGB values out of [0,1].

Because that first approach did not work, I tried to do the following with a relative level of success. For each pixel, if Y' is the luminance level after equalizating and Y the original luminance value, I consider the new RGB values given by R' = (Y'/Y) R, G' = (Y'/Y) G and B' = (Y'/Y) B. That is, I escalated the luminance level preserving proportionality in the distribution of RGB components.

Even though the second approach worked, I have the problem that some of the colors in the original image look different after the equalization. This effect is more or less percievable depending on the original image. My question is, what is a good, color-preserving approach for transforming the original RGB image into a new one with the luminance values corrected?

Note that in the second method(btw, the only one that worked), I have to replace the (Y'/Y) in the formulas by the minumum between (Y'/Y) and the maximum of (1/R), (1/G) and (1/B), so I don't get above 1 in any component. Of course, this is another drawback because for some pixels I can't get the luminance level calculated in the greyscale equalization step.

Community
  • 1
  • 1
ORerwannabe
  • 111
  • 3
  • I didn't fully understand why the first method didn't work? The equalized Y values are between [0,1] and after you use the new Y with the old I and Q you get values of RGB grater than 1? – Amitay Nachmani Aug 20 '16 at 17:43
  • @AmitayNachmani Yes, or lower than zero. But if you think about it, it does make sense. The three values RGB are used to calculate each one of the YIQ values. If you modify Y to get Y', you'll be able to go back to valid RGB coordinates as long as this new value Y' is such that Y'IQ could have been generated by some valid RGB coordinates. – ORerwannabe Aug 20 '16 at 21:51
  • Yes you are right my bad. – Amitay Nachmani Aug 21 '16 at 04:55

2 Answers2

0

You don't metion your OS, your software environment nor provide any images, so I'll suggest an option using ImageMagick just at the command-line. It is installed on most Linux distros and available for OSX and Windows with Python, PHP, Perl, Java, C/C++ bindings too.

So, I think you want something like this:

convert input.jpg -colorspace YIQ -channel R -equalize +channel -colorspace RGB result.jpg

That says... "Convert image input.jpg to YIQ colourspace, then only operating on the first channel (R channel which is Y here), equalize that channel. Now revert to using all 3 channels and go back to RGB colourspace and save as result.jpg".

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • I'm using Python with SciPy, on Fedora. I really appreciate your answer and, in fact, I'm going to use it to compare against the results obtained by my algorithm. BUT, I have to do it by myself, understanding what's going on in the conversions. I just need some clever way to go back while keeping the same relative levels of rgb or something like that. – ORerwannabe Aug 20 '16 at 22:00
0

You can do a linear transform from the current range to the [0,1] range. Lets say now your green channel after the conversion back from Y'IQ is [gMin,gMax] then map all the values back to [0,1] range using the following linear mapping (based on this answer answer):

NewValue = ((OldValue - gMin) / (gMax - gMin))

Do this for the all the channels R,G,B.

Community
  • 1
  • 1
Amitay Nachmani
  • 3,259
  • 1
  • 18
  • 21