 |
|
|
 |
|
 |
The things one does. Where does it lead.
I'd bet you'd never guess... My problem is with Citrix and client PC color depth.
The Citrix clients run at 8-bit color versus my development laptop at 32-bit color.
The problem is that it is almost impossible to find a back color for a control that doesn't appear 'hashed' (making the text almost unreadable) under 8-bit screen color on a Citrix client.
I am hoping that the list of web colors will reflect the actual colors that work in 8-bit depth on the Citrix client.
I'll let you know.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
If I may make two suggestions which could speed up your code just a little.
1. If you ever encounter a distance of "0", you can break the loop and return that very color - you won't get any closer than that...
2. You don't need to calculate the square root. It is of course the mathematically correct way for distances, but you are merely finding a minimum value, i.e. you are comparing only those numbers among each other and not to a specific reference distance. Additionally - but I am not 100% sure - you could try replacing the "Math.Pow" by a simple "Math.Abs".
Seven days without coffee makes one weak.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi!
Thank you for your suggestions. I will implement the first one soon. The second one ... well I will think about it. I love Euclidean geometry and so it is quite hard to make a decision...

Thanks!
************************* Do, ut des.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi Willi,
about suggestion 2, the sum of the squared color component ((r1-r2)^2+(g1-g2)^2+(b1-b2)^2) distances is a better measure for the color distance between to colors than the sum of the absolute values. When you use the Math.Abs method a pair of colors ((r,g,b),(r+4,g+4,b+4)) has the same color distance as ((r,g,b),(r+12,g,b)) while the first pair of colors is intuitively closer. Using Math.Pow solves this.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
You are right, Theo. Using Math.Abs is not a good idea (I still think you don't need the final Sqrt here).
How about replacing "Math.Pow(x, 2.0)" with "x * x"? I remember that in C++ this is a huge difference in speed. I have never tested this in C#. An y insight?
Seven days without coffee makes one weak.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
Hi Wili,
"Seven days without coffee makes one weak." I can assure you that seven days with too much coffee have the same effect.
I would argue that x*x is faster then Math.Pow(x,2.0). (Because x*x saves you the trouble of converting your integers to doubles and then calling the Pow function.) But I just found out it has been tested as well An Objective Analysis of Language Performance - 1) Math Functions[^] and Yes if you have multiple calculations to do it's a huge performance gain to use x*x instead of Math.Pow. (555ms vs 2144ms per calculation in .Net 3.5)
The final square root can indeed be skipped. Then you're no longer calculating "proper" Euclidean distances (but the squares of those) but as long as you're calculating color distances consistently with this method you have a good metric to make comparisons between color distances or find exact matches of colors.
BTW do you happen to know how much distance color values must have before a human starts to notice?
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Colors are a very complicated field and I may know a bit (as much as required for my profession), but I'm no expert. Short answer to your question is no, I don't know the value before humans start noticing differences.
However, if you look at color and the way its stored, there are many ways to describe a color. Here, we have RGB, which is actually not very intuitive to the human, but it comes in handy for computers and monitors and such, because they happen to have light sources for each, red, green and blue. A better way for humans might be the HSL color space (hue, saturation, luminance). We know this from advanced color pickers for example in photo shop. The hue is represented by a circle, starting at red, changing to yellow, green, cyan, blue, magenta and then red again. The radius of the circle then either represents the saturation (strong color, or rather grey'ish, or it represents the lightness. Here, the human perception is escpecially sensitive to the lightness part (probably that's why gray images are still attractive and kind of "real".) The less important components are saturation and hue. JPG for example takes advantage of that, splitting an image into those three parts and then compressing the hue and saturation part with information loss and the grey part more carefully. You can try it yourself, take an image, save it as JPG with medium quality. It should still look ok overall. But now extract the hue channel and look at that one separately. Looks terrible! Aerial images (e.g. seen in Google Maps/Earth) also take advantage of this by taking low resolution color images, blowing them up and then combining them with high resolution gray images - known as pan-sharpening.
And to make matters more complicated, it also depends on the image that you are looking at. If the image is busy/noisy to begin with you will be able to get away with a larger threshold than if you had smooth color ramps (cloudless blue sky) where even small changes are more prominent.
Back to your question, in RGB space, I would be surprised if there was a globally valid threshold value. If you go into HSL space, then it depends on the channel, H, S or L. I don't have an example right now, but I am very confident that you will find a color which is "further away" than another in RGB space, but has a greater resemblance in human perception.
Seven days without coffee makes one weak.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
 |
A couple of years ago LAB was the favorite methods for most of the market, today there are better standars,
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
Thank you for your comment.
Well - this is my first attempt to contribute some minor/usefull code to the community. I think this approach is usefull - particularly for "fun programmers". Of course - there are a lot of algorithms able to handle this problem. Maybe I will post a more sophisticated solution. 
Do, ut des.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |