Color Conversion

  1. last week

    Dave S

    Dec 6 San Diego, California USA

    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

  2. Thom M

    Dec 6 Pre-Release Testers Greater Hartford Area, CT

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

  3. Emile S

    Dec 7 Europe (France, Strasbourg)

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

  4. Dave S

    Dec 7 San Diego, California USA

    @Emile S 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

  5. Bill

    Dec 7 Pre-Release Testers, Xojo Pro Longview Texas

    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.

  6. Jared F

    Dec 7 Pre-Release Testers, Xojo Pro Milwaukee, WI

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

    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.

    -image-

    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.

  7. Dave S

    Dec 7 San Diego, California USA

    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.

  8. Jared F

    Dec 7 Pre-Release Testers, Xojo Pro Milwaukee, WI
    Edited last week

    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:
    -image-

    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.

  9. Dave S

    Dec 7 San Diego, California USA

    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?

  10. Jared F

    Dec 7 Pre-Release Testers, Xojo Pro Milwaukee, WI

    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:
    -image-

  11. Dave S

    Dec 7 San Diego, California USA

    got it.... thanks...

  12. Sam R

    Dec 7 Pre-Release Testers, Xojo Pro Hengchun, Pingtung, Taiwan

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

  13. 6 days ago

    Greg O

    Dec 8 Xojo Inc Somewhere near Raleigh, NC

    @Jared F 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:
    -image-

    Actually... Red is 0/360, Green is 120 and Blue is 240.

  14. 4 days ago

    Jared F

    Dec 11 Pre-Release Testers, Xojo Pro Milwaukee, WI

    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.

  15. 3 days ago

    Steve U

    Dec 12 Pre-Release Testers, Xojo Pro Seattle, WA

    @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

    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.

or Sign Up to reply!