Android Question SQL lite and square function

bluedude

Well-Known Member
Licensed User
Longtime User
Hi,

Does anyone know if this is possible in SQL Lite?

order by (square(c.ColorRed - " & strR & ") + square(c.ColorGreen - " & strG & ") + square(c.ColorBlue - " & strB & "))"
I need a way to lookup matching RGB colors from a table. Something similar to euclidean distance rgb
 

DPaul

Active Member
Licensed User
Longtime User
There are 16.5 million RGB combinations.
Are you looking for the "closest" match or an "exact" match ?
Exact match would probably have 100 pôssible solutions, eg. "add them up = concatenate" .
(0,0,0) is black, that becomes r & g & b = "000" and look if black "000" is in the table.
depending on the sqlite/ordering possibilities, you might want to add leading zeroes "000000000"
White string = "255255255"
If you want the closest match, that is a matter of color theory :)
Paul
 
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
Closest match, I already have a color table that I use. Not sure what you try to explain. Looking for an SQL Lite sample statement.

Attached is my color table. I will probably add some color groups to it because I want to be able to search products on color groups. I'm working on a app. to scan a room for a color palette and provide matching products based on that.
 

Attachments

  • colors.txt
    18.2 KB · Views: 249
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
OK, I happen to be a digital photographer that also teaches about the inner structure of jpg files and the like.
You seem to have a table with rgb colors for use in websites.
What i was trying to find out, is what your definition (in words) of "closest match" is, the code follows from that.
You could go for standard deviation on the rgb series?

Edit: sorry i see now what you mean by "euclidian distance".
The RGB model is a 3D cube, and each color has 3 coordinates.
You now come with an "unknown color", which is also a point in the cube.
You want to find out what the closest "known" point is".
Is that it ?
 
Last edited:
Upvote 0

bluedude

Well-Known Member
Licensed User
Longtime User
I have an RGB color table indeed. The camera scans a room for RGB colors (palette) and based on that I want to show people which colors are in the picture. But, these colors need to be translated to a color name and color group so I can find products with a color match.

It does not need to be very sophisticated. Tested the palette and it's good enough to give people an impression of the colors available in a shot taken by a camera. However, RGB values don't say much and it needs a name and group (Lightblue,Darkblue etc.)

In a normal SQL database I would use square to find closest.

Cheers.
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
There may be 2 to 300 colors that have a (microsoft) name for website standardisation. (Steelblue, cornyellow etc.) Like your table.
This as opposed to 14.5 million possible combinations = colors
Groups of colors , i am not familiar with, as defined in true coordinates. (little cubes inside the big cube?)
Well, let me think about that. :)
 
Upvote 0

DPaul

Active Member
Licensed User
Longtime User
OK, still not sure if the shortest distance will yield the best color match, but if you tested it.
(because 2 very different colors may have the same distance to your unknown)
Your question boils down to the fact if an order clause in sql can have a formula inside it.
I have not seen that, but maybe somebody has.
The obvious method is to iterate through your colors, and just pick up on the smallest number you encounter.
Can't miss !
Paul
 
Upvote 0
Top