Converting RGB <--> HSV

Blitz3D Forums/Blitz3D Programming/Converting RGB <--> HSV

John Pickford(Posted 2006) [#1]
I've been tinkering with using HSV to manipulate bitmap images. I don't really know a whole lot about this stuff but I thought it might be interesting to mess with.

I found some code online to do the conversion and ported it to Blitz.

The original code can be found at:

http://www.cs.rit.edu/~ncs/color/t_convert.html

In my version I've created a type for each pixel which contains the R,G,B and H,S,V values. They are kept as floating point in the 0-1 range apart from hue which is 0-6 (It's 0-360 in the original code).

I found you can immediately improve an image by normalising the V channel - improving contrast and bringing out detail. Normalising the other channels seems to improve the image too - not entirely sure why.

Anyway, here's my code if you are interested. It's not fast (or meant to be) - this stuff isn't great for realtime work.

www.zee-3.com/video/HSV.zip

If you remove the drawimage command you get a random image made of coloured circles.



The top row of images shows the effects of normalising the channels V,S,H. The other rows I'm tinkering with enhancing\decreasing stuff like saturation. Tinting the image by shifting the H channel and even blurring the various channels.

If this evolves into anything useful I'll post it in the code archive.


sswift(Posted 2006) [#2]
What do you mean by "normalize"? Do you mean finding the max and min pixel values over the whole image, and then scaling all the pixel values so that they expand to fill the max range? Ie, if an image was 50% gray static, it would expand to have black pixels and white pixels?

Photoshop has an auto color and auto contrast feature, which I think do this. It works on some images, but not most. On most it oversaturates everything or makes the image too harsh.


John Pickford(Posted 2006) [#3]
Yeah that's exactly what I mean by normalise.


Ross C(Posted 2006) [#4]
Looks good :o)