Image Transformation: Grayscale to Color
|
|
||||||||||||||||
DescriptionTranslated by [email protected] Author:Maxim_Barsuk @ Codeproject Gray = Green * 0.59 + Blue * 0.30 + Red * 0.11;Gray = Green * 0.59 + Blue * 0.30 + Red * 0.11; Each color with structure [Gray, Gray, Gray] has a set of colors: G = [Gray, Gray, Gray] G -> P = {C}, for each C from P: Green * 0.59 + Blue * 0.30 + Red * 0.11 = Gray. First of all, we create a set of control points. Control point is equivalent of "gray" color and "full" color. When we have control points set, we can approximate any "gray" color to "full" color. If "gray" color is located between two control points C1 and C2, then the color approximates as: K = (Gray - C1Gray)/(C2Gray - C1Gray) Red = C1Red + K*(C2Red - C1Red) Green = C1Green + K*(C2Green - C1Green) Blue = C1Blue + K*(C2.Blue - C1Blue) Now we has "full color" equivalent for each "gray" color. Using the Code ControlPoint is a structure for storing data about control points. public struct ControlPoint { private int level; public int Level { get { return level; } set { level = value; } } private Color color; public Color Color { get { return color; } set { color = value; } } public ControlPoint(int level, Color color) { this.color = color; this.level = level; } public override string ToString() { return "Level: " + level.ToString() + "; Color: " + color.ToString(); } } PointsComparer is a class for comparing two control points: public class PointsComparer: IComparer ColorBuilder is a class for building a color diagram. It returns an array of 256 colors - our diagram. public static Color[] GetColorDiagram(List Now we can get the color image: colorBitmap = new Bitmap(sourceBitmap); for (int i = 0; i < sourceBitmap.Width; i++) { for (int j = 0; j < sourceBitmap.Height; j++) { int level = sourceBitmap.GetPixel(i, j).B; colorBitmap.SetPixel(i, j, colors[level]); } } pbxColorImage.Image = colorBitmap; |
Sponsored links
File list
Tips: You can preview the content of files by clicking file names^_^Name | Size | Date |
---|---|---|
ColorTransformApp.sln | 941.00 B | 2009-01-26 08:44 |
ColorTransformApp.suo | 17.00 kB | 2009-01-26 09:11 |
0 | 1.96 kB | |
0 | 1.96 kB | |
0 | 1.96 kB | |
ColorTransformApp.exe | 12.50 kB | 2009-01-26 09:12 |
ColorTransformApp.vshost.exe | 13.99 kB | 2009-01-26 09:13 |
ColorToGrayscle.cs | 1.76 kB | 2009-01-26 09:10 |
ColorTransformApp.csproj | 3.72 kB | 2009-01-26 09:02 |
MainForm.cs | 1.50 kB | 2009-01-26 09:12 |
MainForm.Designer.cs | 9.13 kB | 2009-01-26 09:05 |
MainForm.resx | 6.07 kB | 2009-01-26 09:05 |
Program.cs | 512.00 B | 2009-01-26 08:44 |
0 | 1.96 kB | |
AssemblyInfo.cs | 1.43 kB | 2009-01-26 08:44 |
Resources.Designer.cs | 2.80 kB | 2009-01-26 08:44 |
Resources.resx | 5.48 kB | 2009-01-26 08:44 |
Settings.Designer.cs | 1.08 kB | 2009-01-26 08:44 |
Settings.settings | 249.00 B | 2009-01-26 08:44 |
Sponsored links
Comments
(Add your comment, get 0.1 Point)
Minimum:15 words, Maximum:160 words
- 1
- Page 1
- Total 1