public void effectLighten(PixelClassRGB a, PixelClassRGB b) { if (b.R <= a.R) { R = a.R; } else { R = b.R; } if (b.G <= a.G) { G = a.G; } else { G = b.G; } if (b.B <= a.B) { B = a.B; } else { B = b.B; } }
public PixelClassRGB hsvToRGB(int h, byte s, byte v) { byte r = 0; byte g = 0; byte b = 0; int Hi = Convert.ToInt32(h / 60); byte Vmin = Convert.ToByte((255 - s) * v / 255); int a = Convert.ToInt32((v - Vmin) * (h % 60) / 60); byte Vinc = Convert.ToByte(Vmin + a); byte Vdec = Convert.ToByte(v - a); switch (Hi) { case 0: { r = v; g = Vinc; b = Vmin; break; } case 1: { r = Vdec; g = v; b = Vmin; break; } case 2: { r = Vmin; g = v; b = Vinc; break; } case 3: { r = Vmin; g = Vdec; b = v; break; } case 4: { r = Vinc; g = Vmin; b = v; break; } case 5: { r = v; g = Vmin; b = Vdec; break; } } PixelClassRGB rgbPix = new PixelClassRGB(r, g, b); return(rgbPix); }
public void readImage(Bitmap bmp) { var watchread = System.Diagnostics.Stopwatch.StartNew(); img = new PixelClassRGB[bmp.Width, bmp.Height]; imgnew = new PixelClassRGB[bmp.Width, bmp.Height]; imghsv = new PixelClassHSV[bmp.Width, bmp.Height]; imghsvnew = new PixelClassHSV[bmp.Width, bmp.Height]; imgcmyk = new PixelClassCMYK[bmp.Width, bmp.Height]; imgyuv = new PixelClassYUV[bmp.Width, bmp.Height]; hist1 = new Histogram(); hist2 = new Histogram(); //nolasām datus no attēla var bmpData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadOnly, bmp.PixelFormat); //nolasām atmiņā datus par attēlu IntPtr ptr = IntPtr.Zero; //mēģinām nolasīt rindu int pixelComponents; //kanālu skaits if (bmpData.PixelFormat == PixelFormat.Format24bppRgb) //ja ir 24 bitu formāts { pixelComponents = 3; //kanālu skaits } else if (bmpData.PixelFormat == PixelFormat.Format32bppRgb) //ja ir 32 bitu formāts { pixelComponents = 4; } else { pixelComponents = 0; } var line = new byte[bmp.Width * pixelComponents]; //the length of row array we scan from image for (int y = 0; y < bmpData.Height; y++) { ptr = bmpData.Scan0 + y * bmpData.Stride; //nolasām no pirmā pixeļa un stride-pixeļu rinas platums Marshal.Copy(ptr, line, 0, line.Length); for (int x = 0; x < bmpData.Width; x++) { img[x, y] = new PixelClassRGB(line[pixelComponents * x + 2], line[pixelComponents * x + 1], line[pixelComponents * x]); //BGR imgnew[x, y] = new PixelClassRGB(line[pixelComponents * x + 2], line[pixelComponents * x + 1], line[pixelComponents * x]); //BGR imghsv[x, y] = new PixelClassHSV(img[x, y].R, img[x, y].G, img[x, y].B); imghsvnew[x, y] = new PixelClassHSV(img[x, y].R, img[x, y].G, img[x, y].B); imgcmyk[x, y] = new PixelClassCMYK(img[x, y].R, img[x, y].G, img[x, y].B); imgyuv[x, y] = new PixelClassYUV(img[x, y].R, img[x, y].G, img[x, y].B); img[x, y].X = x - bmpData.Width / 2; img[x, y].Y = y - bmpData.Height / 2; } } bmp.UnlockBits(bmpData); //nolasīšanas rezultāts hist1.readHistogramHSV(img, imghsv); hist2.readHistogramHSV(imgnew, imghsv); watchread.Stop(); var elapsedMs = watchread.ElapsedMilliseconds; Console.WriteLine("Image Read time: " + elapsedMs); }
public PixelClassRGB cmykToRGB(float c, float m, float y, float k) { byte r, g, b; r = Convert.ToByte(255 * (1 - c) * (1 - k)); g = Convert.ToByte(255 * (1 - m) * (1 - k)); b = Convert.ToByte(255 * (1 - y) * (1 - k)); PixelClassRGB rgbPix = new PixelClassRGB(r, g, b); return(rgbPix); }
public PixelClassRGB yuvToRGB(float Yy, float U, float Vv) { byte r, g, b; r = Convert.ToByte(ClampYUV(Yy + 1.13983f * (Vv - 128f))); g = Convert.ToByte(ClampYUV(Yy - 0.39465f * (U - 128f) - 0.58060f * (Vv - 128f))); b = Convert.ToByte(ClampYUV(Yy + 2.03211f * (U - 128f)));/* * byte R = Convert.ToByte(r); * byte G = Convert.ToByte(g); * byte B = Convert.ToByte(b);*/ PixelClassRGB rgbPix = new PixelClassRGB(r, g, b); return(rgbPix); }
public void effectMultiply(PixelClassRGB a, PixelClassRGB b) { double first = (double)a.R / 255; double second = (double)b.R / 255; R = Convert.ToByte(first * second * 255); first = (double)a.G / 255; second = (double)b.G / 255; G = Convert.ToByte(first * second * 255); first = (double)a.B / 255; second = (double)b.B / 255; B = Convert.ToByte(first * second * 255); }
public void effectScreen(PixelClassRGB a, PixelClassRGB b) { double first = (double)a.R / 255; double second = (double)b.R / 255; R = Convert.ToByte((1 - (1 - first) * (1 - second)) * 255); first = (double)a.G / 255; second = (double)b.G / 255; G = Convert.ToByte((1 - (1 - first) * (1 - second)) * 255); first = (double)a.B / 255; second = (double)b.B / 255; B = Convert.ToByte((1 - (1 - first) * (1 - second)) * 255); }
public void effectSubtract(PixelClassRGB a, PixelClassRGB b) { if (a.R + b.R - 255 > 255) { R = 255; } else if (a.R + b.R - 255 < 0) { R = 0; } else { R = Convert.ToByte(a.R + b.R - 255); } if (a.G + b.G - 255 > 255) { G = 255; } else if (a.G + b.G - 255 < 0) { G = 0; } else { G = Convert.ToByte(a.G + b.G - 255); } if (a.B + b.B - 255 > 255) { B = 255; } else if (a.B + b.B - 255 < 0) { B = 0; } else { B = Convert.ToByte(a.B + b.B - 255); } }
public void effectAddition(PixelClassRGB a, PixelClassRGB b) { if (a.R + b.R > 255) { R = 255; } else if (a.R + b.R < 0) { R = 0; } else { R = Convert.ToByte(a.R + b.R); } if (a.G + b.G > 255) { G = 255; } else if (a.G + b.G < 0) { G = 0; } else { G = Convert.ToByte(a.G + b.G); } if (a.B + b.B > 255) { B = 255; } else if (a.B + b.B < 0) { B = 0; } else { B = Convert.ToByte(a.B + b.B); } }
public void effectSoftLight(PixelClassRGB a, PixelClassRGB b) { double first; double second; first = (double)a.R / 255; second = (double)b.R / 255; if (first <= 0.5) { R = Convert.ToByte(((2 * first - 1) * (second - Math.Pow(second, 2)) + second) * 255); } else { R = Convert.ToByte(((2 * first - 1) * (Math.Sqrt(second) - second) + second) * 255); } first = (double)a.G / 255; second = (double)b.G / 255; if (first <= 0.5) { G = Convert.ToByte(((2 * first - 1) * (second - Math.Pow(second, 2)) + second) * 255); } else { G = Convert.ToByte(((2 * first - 1) * (Math.Sqrt(second) - second) + second) * 255); } first = (double)a.B / 255; second = (double)b.B / 255; if (first <= 0.5) { B = Convert.ToByte(((2 * first - 1) * (second - Math.Pow(second, 2)) + second) * 255); } else { B = Convert.ToByte(((2 * first - 1) * (Math.Sqrt(second) - second) + second) * 255); } }
public void effectHardLight(PixelClassRGB a, PixelClassRGB b) { double first; double second; first = (double)a.R / 255; second = (double)b.R / 255; if (first <= 0.5) { R = Convert.ToByte((2 * first * second) * 255); } else { R = Convert.ToByte((1 - 2 * (1 - first) * (1 - second)) * 255); } first = (double)a.G / 255; second = (double)b.G / 255; if (first <= 0.5) { G = Convert.ToByte((2 * first * second) * 255); } else { G = Convert.ToByte((1 - 2 * (1 - first) * (1 - second)) * 255); } first = (double)a.B / 255; second = (double)b.B / 255; if (first <= 0.5) { B = Convert.ToByte((2 * first * second) * 255); } else { B = Convert.ToByte((1 - 2 * (1 - first) * (1 - second)) * 255); } }
public void effectDifference(PixelClassRGB a, PixelClassRGB b) { R = Convert.ToByte(Math.Abs(a.R - b.R)); G = Convert.ToByte(Math.Abs(a.G - b.G)); B = Convert.ToByte(Math.Abs(a.B - b.B)); }
public void effectOpacity(PixelClassRGB a, PixelClassRGB b, double d) { R = Convert.ToByte(d * a.R + (1 - d) * b.R); G = Convert.ToByte(d * a.G + (1 - d) * b.G); B = Convert.ToByte(d * a.B + (1 - d) * b.B); }