Skip to main content

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.

EDIT:EDIT: Where lum is the luminance of the input pixel:

out_s = clamp( (1 - pix_v) * 2, 0, 1)

out_v = clamp( pix_v * 2, 0, 1)

out_s = clamp( (1 - pix_v) * 2, 0, 1)

out_v = clamp( pix_v * 2, 0, 1)

seems to produce good results when colorize inputs S=1 ([0, 1]) and V=.5 ([0, 1]). I'm still struggling to generalize these formulas for when S!=1 and V!=.5.

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.

EDIT: Where lum is the luminance of the input pixel:

out_s = clamp( (1 - pix_v) * 2, 0, 1)

out_v = clamp( pix_v * 2, 0, 1)

seems to produce good results when colorize inputs S=1 ([0, 1]) and V=.5 ([0, 1]). I'm still struggling to generalize these formulas for when S!=1 and V!=.5.

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.

EDIT: Where lum is the luminance of the input pixel:

out_s = clamp( (1 - pix_v) * 2, 0, 1)

out_v = clamp( pix_v * 2, 0, 1)

seems to produce good results when colorize inputs S=1 ([0, 1]) and V=.5 ([0, 1]). I'm still struggling to generalize these formulas for when S!=1 and V!=.5.

added 294 characters in body
Source Link
carlr
  • 21
  • 2

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.

EDIT: Where lum is the luminance of the input pixel:

out_s = clamp( (1 - pix_v) * 2, 0, 1)

out_v = clamp( pix_v * 2, 0, 1)

seems to produce good results when colorize inputs S=1 ([0, 1]) and V=.5 ([0, 1]). I'm still struggling to generalize these formulas for when S!=1 and V!=.5.

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.

EDIT: Where lum is the luminance of the input pixel:

out_s = clamp( (1 - pix_v) * 2, 0, 1)

out_v = clamp( pix_v * 2, 0, 1)

seems to produce good results when colorize inputs S=1 ([0, 1]) and V=.5 ([0, 1]). I'm still struggling to generalize these formulas for when S!=1 and V!=.5.

Source Link
carlr
  • 21
  • 2

How can I implement GIMP's "Colorize" function?

I have an RGB pixel that I'd like to colorize in my program (I'm using GLSL) very similar to how the GIMP "Colors > Colorize" function works.

GIMP's Colorize

In my program, I can easily convert between RGB and HSV. I can therefore get:

pix_h, pix_s, pix_v

And I also define the inputs of the colorize function as:

col_h, col_s, col_v

What calculations can I perform to determine the output pixel hsv?

I think I can get:

out_h = col_h

But I'm a little lost on how to calculate output saturation and value.