//L a b in double values (as after convert XYZ2lab; not in range [0 1]) //L a b arrays in In the following order L-a-b public static List <ArraysListInt> Lab1976toRGB(double[,] l, double[,] a, double[,] b) { l = l.ArrayDivByConst(2.57); List <ArraysListInt> rgbResult = Lab2RGB(l, a, b); return(rgbResult); }
private static List <ArraysListInt> YCbCr2RGBCount(double[,] y, double[,] cb, double[,] cr) { int width = y.GetLength(1); int height = y.GetLength(0); List <ArraysListInt> rgbResult = new List <ArraysListInt>(); y = y.ArrayDivByConst(255); cb = cb.ArrayDivByConst(255); cr = cr.ArrayDivByConst(255); double[,] R = new double[height, width]; double[,] G = new double[height, width]; double[,] B = new double[height, width]; double[] Ycon = new double[3] { 298.082, 0, 408.583 }; double[] Cbcon = new double[3] { 298.082, -100.291, -208.12 }; double[] Crcon = new double[3] { 298.082, 516.412, 0 }; double[] Coef = new double[3] { -222.921, 135.576, -276.836 }; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { double[] temp = new double[3] { y[i, j], cb[i, j], cr[i, j] }; R[i, j] = Coef[0] + Ycon.MultVectors(temp).Sum(); G[i, j] = Coef[1] + Cbcon.MultVectors(temp).Sum(); B[i, j] = Coef[2] + Crcon.MultVectors(temp).Sum(); } } rgbResult.Add(new ArraysListInt() { Color = R.ArrayToUint8() }); rgbResult.Add(new ArraysListInt() { Color = G.ArrayToUint8() }); rgbResult.Add(new ArraysListInt() { Color = B.ArrayToUint8() }); return(rgbResult); }
//L values - double, not in [0 1] range; a & b - same, but have negative values private static List <ArraysListDouble> XYZ2LabCount(double[,] x, double[,] y, double[,] z) { int width = x.GetLength(1); int height = x.GetLength(0); List <ArraysListDouble> labResult = new List <ArraysListDouble>(); const double X_D65 = 95.047; const double Y_D65 = 100; const double Z_D65 = 108.883; x = x.ArrayDivByConst(X_D65); y = y.ArrayDivByConst(Y_D65); z = z.ArrayDivByConst(Z_D65); double[,] X_temp = new double[height, width]; double[,] Y_temp = new double[height, width]; double[,] Z_temp = new double[height, width]; double[,] L = new double[height, width]; //lightness double[,] a = new double[height, width]; //color opponent green–red double[,] b = new double[height, width]; //color opponent and blue–yellow for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (x[i, j] > 0.008856) { X_temp[i, j] = Math.Pow(x[i, j], (1d / 3d)); } else { X_temp[i, j] = (7.787 * x[i, j]) + (16d / 116d); } if (y[i, j] > 0.008856) { Y_temp[i, j] = Math.Pow(y[i, j], (1d / 3d)); } else { Y_temp[i, j] = (7.787 * y[i, j]) + (16d / 116d); } if (z[i, j] > 0.008856) { Z_temp[i, j] = Math.Pow(z[i, j], (1d / 3d)); } else { Z_temp[i, j] = (7.787 * z[i, j]) + (16d / 116d); } L[i, j] = (116 * Y_temp[i, j]) - 16; a[i, j] = 500 * (X_temp[i, j] - Y_temp[i, j]); b[i, j] = 200 * (Y_temp[i, j] - Z_temp[i, j]); } } labResult.Add(new ArraysListDouble() { Color = L }); labResult.Add(new ArraysListDouble() { Color = a }); labResult.Add(new ArraysListDouble() { Color = b }); return(labResult); }
public static double[,] Filter_double(int[,] arr, double[,] filter, double fdiv) { return(Filter_double(arr.ArrayToDouble(), filter.ArrayDivByConst(fdiv), PadType.replicate)); }
//H in degrees; S and V in divided by 100% values private static List <ArraysListInt> HSV2RGBCount(double[,] h, double[,] s, double[,] v) { int width = h.GetLength(1); int height = h.GetLength(0); const double HSVang = 60; List <ArraysListInt> rgbResult = new List <ArraysListInt>(); //back result [0 .. 255] int[,] R = new int[height, width]; int[,] G = new int[height, width]; int[,] B = new int[height, width]; var C = v.ArrayMultElements(s); var X = h.ArrayDivByConst(HSVang).ModArrayElements(2).ArraySubWithConst(1).AbsArrayElements(); X = X.ConstSubArrayElements(1).ArrayMultElements(C); var m = v.SubArrays(C); //R G B count for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { if (h[i, j] >= 0 & h[i, j] < 60) { R[i, j] = (int)((C[i, j] + m[i, j]) * 255); G[i, j] = (int)((X[i, j] + m[i, j]) * 255); B[i, j] = (int)(m[i, j] * 255); } else if (h[i, j] >= 00 & h[i, j] < 120) { R[i, j] = (int)((X[i, j] + m[i, j]) * 255); G[i, j] = (int)((C[i, j] + m[i, j]) * 255); B[i, j] = (int)(m[i, j] * 255); } else if (h[i, j] >= 120 & h[i, j] < 180) { R[i, j] = (int)(m[i, j] * 255); G[i, j] = (int)((C[i, j] + m[i, j]) * 255); B[i, j] = (int)((X[i, j] + m[i, j]) * 255); } else if (h[i, j] >= 180 & h[i, j] < 240) { R[i, j] = (int)(m[i, j] * 255); G[i, j] = (int)((X[i, j] + m[i, j]) * 255); B[i, j] = (int)((C[i, j] + m[i, j]) * 255); } else if (h[i, j] >= 240 & h[i, j] < 300) { R[i, j] = (int)((X[i, j] + m[i, j]) * 255); G[i, j] = (int)(m[i, j] * 255); B[i, j] = (int)((C[i, j] + m[i, j]) * 255); } else if (h[i, j] >= 300 & h[i, j] < 360) { R[i, j] = (int)((C[i, j] + m[i, j]) * 255); G[i, j] = (int)(m[i, j] * 255); B[i, j] = (int)((X[i, j] + m[i, j]) * 255); } } } rgbResult.Add(new ArraysListInt() { Color = R }); rgbResult.Add(new ArraysListInt() { Color = G }); rgbResult.Add(new ArraysListInt() { Color = B }); return(rgbResult); }