Visual Studio 2010 custom color picker - asp.net

On the right end, there is a vertical slider, which I think is meant for you to choose the "intensity" of the color, eg darker red or paler red. Is this correct?
The second question, as a layman to colors, I'd thought a dark red and a pale red has the same RGB proportion? But apparently this is not the case. Are darker color and paler color of the same color actually to non-related colors?

On question 1 yes, in laymans term it increases the intensity. But what really happens is this
double R;
double G;
double B;
double Luminosity = Math.Sqrt(.0241 * (Math.Pow(R, 2)) + 0.691 * (Math.Pow(G, 2)) + 0.068 * (Math.Pow(B, 2)));
Which is a formula for Luminosity based on RGB

Related

rect.hclust integer vector for "border" parameter

Clearly one can use an integer vector for the border parameter of rect.hclustL
x <- rect.hclust(foo, k=ncuts, which = c(2,7), border = 3:4)
So imagine I have ncuts and wish to have "pseudo"-unique coloring of each border cut:
x <- rect.hclust(foo, k=ncuts, which = c(2,7), border = 1:ncuts)
Clearly the border color list that is being selected is finite - but what are the actual colors?
I started looking through documentation and no leads there, I moved on to a cursory view of the source code - and nothing there either.
By observation I noticed the colors appear to be (limited to):
Black
Red
Green
Violet
Light Blue
Magenta
Yellow
White
But how are they defined - and more importantly say that I wanted to associate the cuts with the appropriate color later on - could I do it?
UPDATE:
The coloring of dendrogram borders when defined by a numerical color lists occurs strictly from Left to Right (Black, Red, Green3, Blue, Cyan, Magenta, Yellow Grey, Black, Red ...). The question then becomes - how can I associate / locate a cut's position within the dendrogram.

Equation behind the pixels grayscale

I have an image in grayscale and colored form,and
I want to know the pixel grayscale equation?
so I trace the same pixels on both images
red=119 green=198 blue=122
red=169 green=169 blue=169
red=0 green=133 blue=184
red=119 green=119 blue=119
red=119 green=74 blue=180
red=94 green=94 blue=94
what is the equation?
The following equation brings the same results (round to the nearest integer) :
gray = 0.1313*r + 0.6781*g + 0.1566*b;
(used this site for solving the 3 unknown equation as suggested in Nikita's comment)
"Grayscale: Converting color to grayscale"
Note that the 0.299, 0.587 and 0.114 are absolutes for each colors weight as they all have different luminance. In simple terms, green is lighter than red and blue where blue is the darkest of three.
More info can be found here.

How to combine two QColor objects with alpha channel?

I have objects where the border color has already been determined.
Now I want the user to be able to set at least the opacity of the fill pattern. E.g., the border is blue. The user sets the opacity to 128, so the fill pattern is also drawn in blue, but half-transparent.
The next step would be to allow the user to also slightly adjust the color of the pattern. E.g.: "Use the border color, but make it half-transparent (alpha=128) and a little bit yellow-ish.".
Is there a (useful) way to combine two colors where one does not have an alpha value set? Or would it make more sense to set an alpha value on the original color and combine it with an "overlay color" that also has an alpha value set?
And is there a function (or otherwise, can someone give a short code snippet) to combine the two QColor objects?
I would look at existing color pickers that are out there (Gimp, Photoshop, Paint, wwWidgets). Most of them deal with a few different ways of picking your color:
Saturation, Hue, Value, Brightness, Contrast, RGB, CMYK, HSV, Alpha/Opacity.
Qt handles a bunch of these right out of the box:
QColor
In order to combine two colors, I would probably average their different components together:
// Rough pseudocode
Color1 RGBA, Color 2 RGBA, Color 3 = combination
Color3.R = (Color1.R + Color2.R)/2
Color3.G = (Color1.G + Color2.G)/2
Color3.B = (Color1.B + Color2.B)/2
Color3.A = (Color1.A + Color2.A)/2
I hope that helps.
PS: Understanding Color Space can be helpful, too.

Color similarity/distance in RGBA color space

How to compute similarity between two colors in RGBA color space? (where the background color is unknown of course)
I need to remap an RGBA image to a palette of RGBA colors by finding the best palette entry for each pixel in the image*.
In the RGB color space the most similar color can be assumed to be the one with the smallest euclidean distance. However, this approach doesn't work in RGBA, e.g., Euclidean distance from rgba(0,0,0,0) to rgba(0,0,0,50%) is smaller than to rgba(100%,100%,100%,1%), but the latter looks much better.
I'm using premultiplied RGBA color space:
r = r×a
g = g×a
b = b×a
and I've tried this formula (edit: See the answer below for better formula):
Δr² + Δg² + Δb² + 3 × Δa²
but it doesn't look optimal — in images with semitransparent gradients it finds wrong colors that cause discontinuities/sharp edges. Linear proportions between opaque colors and alpha seem fishy.
What's the optimal formula?
*) for simplicity of this question I'm ignoring error diffusion, gamma and psychovisual color spaces.
Slightly related: if you want to find nearest color in this non-Euclidean RGBA space, vp-trees are the best.
Finally, I've found it! After thorough testing and experimentation my conclusions are:
The correct way is to calculate maximum possible difference between the two colors.
Formulas with any kind of estimated average/typical difference had room for discontinuities.
I was unable to find a working formula that calculates the distance without blending RGBA colors with some backgrounds.
There is no need to take every possible background color into account. It can be simplified down to blending maximum and minimum separately for each of R/G/B channels:
blend the channel in both colors with channel=0 as the background, measure squared difference
blend the channel in both colors with channel=max as the background, measure squared difference
take higher of the two.
Fortunately blending with "white" and "black" is trivial when you use premultiplied alpha.
The complete formula for premultiplied alpha color space is:
rgb *= a // colors must be premultiplied
max((r₁-r₂)², (r₁-r₂ - a₁+a₂)²) +
max((g₁-g₂)², (g₁-g₂ - a₁+a₂)²) +
max((b₁-b₂)², (b₁-b₂ - a₁+a₂)²)
C Source including SSE2 implementation.
Several principles:
When two colors have same alpha, rgbaDistance = rgbDistance * ( alpha / 255). Compatible with RGB color distance algorithm when both alpha are 255.
All Colors with very low alpha are similar.
The rgbaDistance between two colors with same RGB is linearly dependent on delta Alpha.
double DistanceSquared(Color a, Color b)
{
int deltaR = a.R - b.R;
int deltaG = a.G - b.G;
int deltaB = a.B - b.B;
int deltaAlpha = a.A - b.A;
double rgbDistanceSquared = (deltaR * deltaR + deltaG * deltaG + deltaB * deltaB) / 3.0;
return deltaAlpha * deltaAlpha / 2.0 + rgbDistanceSquared * a.A * b.A / (255 * 255);
}
My idea is integrating once over all possible background colors and averaging the square error.
i.e. for each component calculate(using red channel as example here)
Integral from 0 to 1 ((r1*a1+rB*(1-a1))-(r2*a2+rB*(1-a2)))^2*drB
which if I calculated correctly evaluates to:
dA=a1-a2
dRA=r1*a1-r2*a2
errorR=dRA^2+dA*dRA+dA^2/3
And then sum these over R, G and B.
First of all, a very interesting problem :)
I don't have a full solution (at least not yet), but there are 2 obvious extreme cases we should consider:
When Δa==0 the problem is similiar to RGB space
When Δa==1 the problem is only on the alpha 1-dim space
So the formula (which is very similar to the one you stated) that would satisfy that is:
(Δr² + Δg² + Δb²) × (1-(1-Δa)²) + Δa² or (Δr² + Δg² + Δb²) × (1-Δa²) + Δa²
In any case, it would probably be something like (Δr² + Δg² + Δb²) × f(Δa) + Δa²
If I were you, I would try to simulate it with various RGBA pairs and various background colors to find the best f(Δa) function. Not very mathematic, but will give you a close enough answer
I've never done it, but theory and practice say that converting the RGB values in the image and the palette to luminance–chrominance will help you find the best matches. I'd leave the alpha channel alone, as transparency should have little to nothing to do with the 'looking better' part.
This xmass I made some photomosaics for presents using open-source software that matches fragments of the original image to a collection of images. That seems like a harder problem than the one you're trying to solve. One of them programs was metapixel.
Lastly, the best option should be to use an existing library to convert the image to a format, like PNG, in which you can control the palette.

Linearly increasing color darkness algorithm

I want to write a function in ruby that given a number between 1 and 500 will output a 6 digit hex color code that gets linearly darker for higher numbers. This doesn't seem that hard but I'm not sure where to begin. How can I implement this?
edit
Hue seems like a more reliable way to go. I'd like to give a reference color, say a shade of green, and then darken or lighten it based on the input number.
input: 10
output: color code (in rgb or HSV) that is a light shade of the reference color
input: 400
output: color code (in rgb or HSV) that is a fairly dark shade of the reference color
edit 2
The only reason I need to use between 1 and 500 is because that's the input I have to work with. It's alright if some numbers that are close together map to the same color.
The 6 digit hex color code is in RGB.
What you want is to work in HSV: pick a Hue and Saturation, and gradually decrease the Value.
Convert from HSV to RGB to output the color.
See here for an example.
Basic linear interpolation?
// Pseudocode
function fade_colour(source, factor)
const max = 500
const min = 1
foreach component in source
output[component] = round(source[component] * (max - value) / (max - min))
endforeach
return output
endfunction
Why not just return a gray level then, #ffffff to #000000? 500 levels of darkness aren't really distinguishable anyway, and grays give you 256 levels.
If you only want to darken your reference color, it's easy. Given an R,G,B color that is the brightest you want to go, multiply each of the 3 values by (500-input) and divide by 499. Convert each of the values to 2 hex digits and append them with a # at the front.

Resources