Color Conversion

Does anyone have an algorithm that takes an RGB color and converts it to another
Now while that sounds simple, what I am looking for is not so much.
I need to scan an image (RGBSurface), find all the blue pixels (note they will be all kinds of shades of blue)
and convert them to the same shade/tone of RED…
but its not a simple &c0000ff = &cff0000 as the “blue” pixels may have red/green components as well
pixels that don’t fall in the “blue” scale are left alone

I’d use HSV and look for a range of hues.

Use .Blue to get the Blue value and use that number with .Red to set it ?

Sorry that does not adjust the other values appropriately

You’re right about it not being simple - that’s photoshop stuff. It has a slider that changes the color hues and you can open it up to sliders for a range of tonal values. It works incredibly well but I have no idea how it works.

You would almost have to check the blue value for each pixel for more than a trivial value (what trivial is depends on your needs) and then set that blue value to the value of the red channel and then set the red value to what the blue value was - just reverse the red and blue values. I THINK you should be able to ignore the green but not sure. There have been many books written just about color correction. It’s a complicated subject.

I think that HSV is the best approach here.
Check out this little example for some inspiration.

https://www.dropbox.com/s/axlutlxsqdj0dy2/Hue%20Shift.xojo_binary_project?dl=1

In the paint event, there are definitions for the minHue and maxHue which can be adjusted to fine tune the range of colors that you want to affect.
The slider changes the degree in which the hue is shifted.

In HSV, you can think of hue in degrees, so take the hue value and multiply by 360 to get the value in degrees.
Then you can rotate that value by a set amount of degrees to change the hue and divide by 360 to get back to the double value that the HSV constructor needs.
If you use that new hue, while leaving the original saturation and value unchanged, then you will change the color, but not the saturation or brightness.

This is certainly not nearly as sophisticated as what Photoshop would be doing, but I think that it’s good food for thought while approaching this problem.

Sounds like it might work… but confused (and I’ve always dealt with RGBA not HSV)
your picture shows 0 to 240deg… but “H” is 0 to 1 which means 0 to 360 …
what is the missing 120deg?

if clr.hue>=0.5 and clr.hue<0.67 then // is it in the BLUE RANGE?
 clr.hue=clr.hue-0.5 // shift it to the RED RANGE
 // put the pixel back
end if

but based on what you said (I have not tried this yet)… the above should (maybe) do what I want
no real need to do all the “degree” math from what I can see.

That picture just has a slice of the circle cut out to show the effect that the three values have on a given color (in that case, blue and red).

Here’s another version that is more of a complete circle/cone:

And you’re right, there is no need for the degree math.
It just makes it easier for me to grasp what is actually happening when combined with a visual representation of HSV color.

Ok… that still doesn’t define the missing 120deg.
if red is 0 to 80 and green is 81 to 160 and blue is 160 to 240?
what is 241 to 359

or do the colors in your “pie” not represent reality?

It’s missing the purple range between pure blue and pure red

Red isn’t 0 to 80, it’s more like 330 to 30 (passing through 0).

Top down on the full circle might be a better representation of hue alone:

got it… thanks…

You can also look at rgbSurface.transform as you can use it to remap colours.

[quote=363587:@Jared Feder]It’s missing the purple range between pure blue and pure red

Red isn’t 0 to 80, it’s more like 330 to 30 (passing through 0).

Top down on the full circle might be a better representation of hue alone:
[/quote]
Actually… Red is 0/360, Green is 120 and Blue is 240.

True, that’s where the pure color is.

I was just referring to the range of color (subjective) since Dave was trying to alter a range of blue hues.

[quote=363395:@Dave S]Does anyone have an algorithm that takes an RGB color and converts it to another
Now while that sounds simple, what I am looking for is not so much.
I need to scan an image (RGBSurface), find all the blue pixels (note they will be all kinds of shades of blue)
and convert them to the same shade/tone of RED…
but its not a simple &c0000ff = &cff0000 as the “blue” pixels may have red/green components as well
pixels that don’t fall in the “blue” scale are left alone[/quote]

Dave, It would help to know more about what you’re trying to do.

In the graphics world, it sounds like what you’re doing is “selective color replacement” which can get complicated and when coding would probably involve ICC profiles and some kind of conversion.

But your description sounds a fair amount like a synthetic color change. Something for display graphics or somesuch. If so, you might be able to simply do RGB/HSV - style pixel conversions.