Calculate hex color with transparency based on other colors

26 Views Asked by At

I have the following image:

image example

I want to find the hex color and transparency of the red circle based on the below information :

  • purple background circle is #afb0cc
  • human figure is #ffffff

By using eye-dropper I was able to figure out some additional information:

  • Red Circle over purple background circle is #d75866
  • Red Circle over human figure is #ff7f7f
1

There are 1 best solutions below

0
VC.One On

I want to find the hex color and transparency of the red circle"

The hue (or pure color, without shading, etc) of the pixel is its highest component (with R, G, or B).

Assuming a pixel's RGB has this setup: AA = R, BB = G, CC = B...
And could be presented as #AABBCC or #CCBBAA depending on color model used, etc.

Find hex of Red color:
To find "Red" you want a pixel with a high AA component value when compared to BB and CC components. The level of Red channel defines the type of Red (eg: dark, cherry, rose, etc).

Find transparency of red circle:

Given that AA is the highest component (Red) you then minus from it, the lowest value from either BB or CC.

Opacity_estimate = ( AA - ( Math.min( BB , CC ) ) );  

example:

"Red Circle over purple background circle is #d75866"

The highest is 0xD7 (int: 215) and the lowest is 0x58 (int: 88).

If you do: 215 - 88 then opacity = 127.
(Or at leasr you can ascertain that the Red level is 128, and that number could be due to lightness or could be due to transparency over a white background).