if we have 3 green identical balls and 5 red identical balls
The probability of green ball is 3C1/8C1.
But according to combinatrics the num of ways to select one ball out of 8 balls is 2,either green or red.
And to choose one green ball out of green ball is 1.
But in probability we treat indentical balls as they are distinct.
Related
I want to make a shader that replace a color to be applied to a plain color character, but I can't just replace the color because the image contains pixels that are an average of two border colors.
For example the image looks like this:
Assuming that I want to change the color of the shirt, I want to replace the red color for a green one, but at the edges there are pixels that are not red:
Any ideas how to calculate the resultant color of one of those pixels?
Do you know which are the major colours in advance?
If not then a simple solution for finding them is to generate a histogram — scan the entire image and for each pixel that is the same as all four of its neighbours, add one to a count for the colour it contains. At the end, keep only those colours that fill at least a non-negligible portion of the display, e.g. at least 5% of those pixels that are not transparent.
Dealing with black borders is easy: use a luminance/chrominance colour space, and always leave luminance alone, remapping only chrominance. Factoring out brightness has a bonus: it collapses colour substitution from a 3d problem to a 2d problem.
If this weren't GLSL then a solid solution might be for each pixel that is not one of the selected major colours might be (i) find the nearest pixel that is a major colour; (ii) then find the nearest pixel that is a major colour but not the one found in (i). Use normal linear algebra to figure out the distance of that pixel on the 2d line from the one colour to the other. Substitute the colours, reinterpolate and output.
Being that it is GLSL, so "find the nearest" isn't especially realistic, assuming the number of major colours is small then just do it as distance from those lines. E.g. suppose you have five colours. Then that's 10 potential colour transitions in total — from each of the five colours there are four other options, suggesting twenty transitions, but half of them are exactly the same as the other half because they're just e.g. red to blue instead of blue to red. So ten.
Load those up as uniforms and just figure out which transition gradient the colour is closest to. Substitute the basis colours. Output.
So, in net:
transform (R, G, B) to (Y, x, y) — whether YUV or YIQ or Y doesn't matter, just pick one;
perform distance from a line for (x, y) and the colour transition gradients identified for this image;
having found the transition this pixel is closest to and its distance along that transition, substitute the end points, remap;
recombine with the original Y, convert back to RGB and output.
That's two dot products per colour transition gradient to establish closest, then a single mix to generate the output (x, y)/
Let Rx, Gx, Bx = Pixel values of color X (Red in your case) to be removed/replaced.
Let Ry, Gy, By = Pixel values of color Y (Green in your case) to be used as new color.
Then you will iterate over all pixels and using clever condition (below), identify the pixel that needs to be processed.
If Rc is current value of the selected pixel color (does not matter what combination of red and yellow is), then final values of the pixel are:
Rf = Rc - Rx + Ry
Gf = Gc - Gx + Gy
Bf = Bc - Bx + By
Of course, this processing should NOT happy for all pixels. Clever condition to identify only relevant pixels could be : If pixel color is Red or least one adjacent pixel is Red/Yellow.
UPDATE: Another clever condition using current pixel only:
This involves removing border colors YELLOW or BLACK color from the current color and checking if it is RED.
Rc - R(yellow) == R(RED) AND
Gc - G(yellow) == G(RED) AND
Bc - B(yellow) == B(RED)
OR
Rc - R(black) == R(RED) AND
Gc - G(black) == G(RED) AND
Bc - B(black) == B(RED)
In OpenGL, I made a sphere and gave every Fragment the Color of its normalized position. The sphere is right at the origin so the sphere should be covered with smooth color gradients between red, green, and blue, while on every axis, the color is pure(x - red, y - green, z - blue).
but not like I expected i see this shape when i look down the Z/Blue Axis
I played around a little and compared the gradients between the different colors
(looking down the x axis with zero red color)
In this image, it looks like the Green color is somehow more dominant than the blue, as if it was sprayed on top of it. Also the Blue seems to be deminished by the black.
(looking down the y axis with zero green color)
In this image there seems to be a smoother gradient but i´d still say there is more red than blue in the image but this might be my individual perception and the picture is not perfectly symmetrical aswell.
(looking down the z axis with zero blue color)
To me it looks like Green and Red are more dominant than blue for some reason.
But what originally brought up this question is the weird hard gradient i got (first image). I dont think it is a bug in my shaders, because i never treat any color individually.
What could cause this behaviour?
PS: I have not implemented alpha yet and i am not using alpha anywhere in my shader (where i use a vec4 for color, the 4th component is always 1.0)
I am using ncurses with c++ on a xterm-256 display and I would like to print my text in shades of red, but I'm having trouble finding a simple way to do this.
Using this chart I can see that 0x009 is red and that 0x255 - 0x232 will be various shades of black. How can I go about using this information to form a mast for my colors?
I would basically like to form a map such that 10 means white and 20 means red, such that 15 would be pink and so on. I would then create color pairs with
init_pair(10, ???, COLOR_BLACK);
init_pair(11, ???, COLOR_BLACK);
...
init_pair(20, ???, COLOR_BLACK);
so that I could use these colors later to shade from white to red.
It depends on what assumptions you want to make. The layout of the xterm 256color feature is a given, with three parts:
colors 0-15 are ANSI colors and bright versions of those.
colors 16-231 are a 6x6x6 color cube
colors 232-255 are a grayscale ramp, intentionally leaving out black and white
See for example 256color.pl (widely copied from xterm sources). The numbers make more sense than the chart when you see the picture:
You could simply refer to those color numbers in init_pair. Bright red as you have noticed is 9 (COLOR_RED + 8).
On the other hand, the color palette can be modified. You could use init_color (giving your own red/green/blue triple) to define a color by number, and use that in init_pair.
Suppose the polygon is a hexagon.
To fill it gradiently, assume there are many smaller hexagons inside.
The smaller the hexagon, the pixel on that hexagon has a brighter color.
However, after I finish it, I find that there are spurious star edges between the center and the corners, like in the attached image (ignore the two discs inside).
How should I design an algorithm to make the filling more smoothly?
So I have no idea how I should be doing what I want do so I'll explain as best as I can.
http://i.stack.imgur.com/j65H8.jpg
So imagine that entire image is a 2d square 128x128 and each color I want to apply a texture to that part of the 2d square. Also I want it to stretch as well so Red, Aqua, Green and Purple never stretch in any direction but Pink stretches all directions and then Grey, Yellow, Black and Orange stretch in the longest direction (grey/orange = width expands, yellow/black = height expands). When stretched it should look like this:
http://i.stack.imgur.com/wJiKv.jpg
Also I am using C++.