News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Color Distance Function

Started by dedndave, March 09, 2015, 11:18:00 AM

Previous topic - Next topic

Siekmanski

Hi Dave,

Don't know if these methods are usefull for you to find the nearest color in your color palette but, you could try it out.

Make 4 look-up tables from your color palette ( one for each method ) then encode your new pixel color according the 4 methods and find the best ( nearest ) match in your color palette.

1) The lightness method:
   Averages the most prominent and least prominent colors: (max(R, G, B) + min(R, G, B)) / 2

2) The average method:
   Averages the values: (R + G + B) / 3

3) Colorimetric method:
   It forms a weighted average to account for human perception.
   Luminosity is: (R * 0.2126) + (G * 0.7152) + (B * 0.0722)

4) Luma coding method:
   This is how we perceive colors from TV's monitors etc.
   Luma is: (R * 0.299) + (G * 0.587) + (B * 0.114)


Creative coders use backward thinking techniques as a strategy.

dedndave

thanks for the hint, Marinus
as it turns out, my little routine is plenty fast for what i'm doing
tables might be better if you were processing an image   :t
although, my routine uses 4 MUL's and an IMUL - i would guess maybe 70-80 clock cycles

rrr314159

This may be ignorant - is that 70 or 80 clock cycles per pixel you're talking about? Do u apply it to each pixel, to match to the palette? If it's something like that, shouldn't you be using SSE?

I found this free image manipulation prog "IrfanView" which seems best of the bunch, does anyone know anything about it? Recommended?
I am NaN ;)

dedndave

if i were using it to match pixels to a palette, i might want a faster solution
in this case, i am using it to find a few colors, only - so the function serves my purposes quite nicely
i was only giving that as an example of "color distance"

IrfanView looks quite interesting, although i have no experience with it
if you want to find others, you might look at

http://filehippo.com/software/photos_images/

Siekmanski

Quote from: dedndave on March 10, 2015, 03:44:51 PM
if i were using it to match pixels to a palette, i might want a faster solution
in this case, i am using it to find a few colors, only - so the function serves my purposes quite nicely
i was only giving that as an example of "color distance"
http://filehippo.com/software/photos_images/

Hi Dave, now I understand your routine.  :t

You gave me some inspiration to do a rotatable 3D color map. ( see attachment )
When I saw it on screen it gave me ideas to make use of it as for example creating 3D plasma effects etc.
Creative coders use backward thinking techniques as a strategy.

Siekmanski

2th color map cube with the colors diagonally connected. ( see attachment )
Creative coders use backward thinking techniques as a strategy.

dedndave

those are cool, Marinus   :t

Siekmanski

Creative coders use backward thinking techniques as a strategy.

dedndave

lol
you make it look so easy   :P

GoneFishing

Nice rotating cube, Marinus  :t
and thanks for the source code . BTW  do you plan to release your complete MASM32 DirectX SDK ?

@Dave:
Quote from: dedndave on March 10, 2015, 05:55:40 AM
...
but, color (chroma) and luminance are not perceived by the human eye in a linear way
so, the box is oddly shaped, not a cube
...
Didn't know it and don't understand now . Could you post a link for reading on this subject ?

Quote from: dedndave on March 11, 2015, 03:24:29 AM
lol
you make it look so easy   :P
Now let's wait for a transparent color map cube with 256x256x256 selectable cells  :biggrin:

Siekmanski

Quote from: vertograd on March 11, 2015, 04:21:09 AM
Nice rotating cube, Marinus  :t
and thanks for the source code . BTW  do you plan to release your complete MASM32 DirectX SDK ?

Do you mean the include files for the d3dx9.lib ?
Creative coders use backward thinking techniques as a strategy.

GoneFishing

Quote from: Siekmanski on March 11, 2015, 05:11:57 AM
Do you mean the include files for the d3dx9.lib ?
I mean your all DX examples + framework

dedndave

the color box Marinus shows you is a nice linear cube

but, the human eye sees different colors in different ways - it's not linear
for example, the eye is much more sensitive to greens than reds or blues
and - a graph of green levels vs how we perceive them would not be a straight line

the fact is, color space is probably not a cube at all
however, our digital input to the video adapter (3 colors, 256 levels each) seems cubical

i imagine something like a diamond shape
but none of the sides are straight or flat, nor are they the same size  :P

the top point could be white and the bottom point could be black
points around the outside would be green, cyan, blue, magenta, red, yellow
the points would be at different heights, too

but, this would be a starting place to describe it

dedndave

a guy named MacAdams made a 2 dimensional representation that is used in the industry
it's a flat graph, but it gives you some idea how oddly shaped things are
it shows chroma, but not luminance

there are thousands of papers to read
just google "color space" or "color map"

Siekmanski

Hi vertograd,

Haven't done much d3d9 coding the last 10 years.
Most of my sources from that era are lost or incomplete....  :(
I don't use the d3dx9.lib anymore ( although it's a great wrapper lib). I just hated the fact you need the right version of redistributables installed before it works.

Now I only use the d3d9.lib wich has all the interfaces we need and is available on all latest windows versions as far as I know.
But you need to write your own math.lib and texture and model loaders etc.
From time to time i worked at it just for the fun, nothing really fancy.

I can put something together. What are you interested in ?
Maybe starting with some old school intro - demo coding for example to start the easy way ?
Creative coders use backward thinking techniques as a strategy.