GIMP style dynamic colorizing

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

GIMP style dynamic colorizing

Post by CaptainMaelstrom »

Hello all,

I'm trying to colorize images dynamically, during run-time.
For example, I have some mostly gray images that I want to color blue (like what's shown inside the black rectangle).
colorize_example.png
colorize_example.png (3.83 KiB) Viewed 3156 times
I'd love to do this with setColor and setBlendMode or similar. But I think I may have to use shaders. So I wrote one to try and achieve the desired effect.

It first converts the set color and the texel to HSV space. The output color will have same hue of set color. I've set the saturation to be the luminance of the image, but I'm not sure what to do about the value part. Copying directly from the image texel seems to result a colorized image that is too dark. So I've multiplied and clamped the value but it's still not quite right..

Anyone have any ideas? See shader code attached (I'm specifically referring to shaders.colorify2).
Attachments
shaders.lua
(1.48 KiB) Downloaded 114 times
User avatar
zorg
Party member
Posts: 3441
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: GIMP style dynamic colorizing

Post by zorg »

H should be static since you want blue; S should also be static since you want the graphics to be saturated to some degree, i.e. you want color;
the only thing you want to adjust is the last remaining parameter, which could be V, which, in the case of the HSL model, would be luminance, but here, it's value, which is kinda similar, but not quite.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
raidho36
Party member
Posts: 2063
Joined: Mon Jun 17, 2013 12:00 pm

Re: GIMP style dynamic colorizing

Post by raidho36 »

I use RGB colored image for this, and so I could use up to 3 different colors. The shader would compute saturation and value of every pixel, and generate a new color from a selectable hue and existing saturation and value. Basically it allows you to recolor solid green, solid red and solid blue to any 3 colors respectively while keeping saturation and value.
User avatar
CaptainMaelstrom
Party member
Posts: 161
Joined: Sat Jan 05, 2013 10:38 pm

Re: GIMP style dynamic colorizing

Post by CaptainMaelstrom »

zorg: That was what I thought at first too. But after trying that, my colorize function still doesn't behave like Gimp's. For instance, white pixels don't stay white.

raidho36: Mind sharing the shader? Does it also colorize grayscale images?

So far, my efforts have gotten me this far:
https://love2d.org/imgmirrur/gjZaxYQ.png

As you can see, still not producing intended results. My shader code is here:
https://gist.github.com/anonymous/aacbe ... 3bacbb8a0f

The source code for the Gimp Colorize function is here (so far as I can tell):
https://github.com/GNOME/gimp/blob/mast ... colorize.c

My shader works well for when the input saturation is 100%, but I'm still trying to find formulas that will work for any inputs (H, S and, V [0, 1]).
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 28 guests