public EnergyAnalyzer(Bitmap _Image) { matrixR = new MatrixInt32(_Image.Width, _Image.Height); matrixB = new MatrixInt32(_Image.Width, _Image.Height); matrixG = new MatrixInt32(_Image.Width, _Image.Height); for (int x = 0; x < _Image.Width; ++x) { for (int y = 0; y < _Image.Height; ++y) { var color = _Image.GetPixel(x, y); matrixR.Data[x, y] = color.R; matrixB.Data[x, y] = color.B; matrixG.Data[x, y] = color.G; } } }
public void PreReAnalyze(List <Tuple <int, int> > removeList, bool isHorizontalRoute, bool Smoothing = true) { if (isHorizontalRoute) { var matrixRM = new MatrixInt32(matrixR.Row, matrixR.Col - 1); var matrixBM = new MatrixInt32(matrixR.Row, matrixR.Col - 1); var matrixGM = new MatrixInt32(matrixR.Row, matrixR.Col - 1); for (int r = 0; r < matrixRM.Row; ++r) { for (int c = 0; c < matrixRM.Col; ++c) { if (!Smoothing) { matrixRM.Data[r, c] = c < removeList[r].Item2 ? matrixR.Data[r, c] : matrixR.Data[r, c + 1]; matrixBM.Data[r, c] = c < removeList[r].Item2 ? matrixB.Data[r, c] : matrixB.Data[r, c + 1]; matrixGM.Data[r, c] = c < removeList[r].Item2 ? matrixG.Data[r, c] : matrixG.Data[r, c + 1]; } else { if (c < removeList[r].Item2 - 1) { matrixRM.Data[r, c] = matrixR.Data[r, c]; matrixBM.Data[r, c] = matrixB.Data[r, c]; matrixGM.Data[r, c] = matrixG.Data[r, c]; } else if (c == removeList[r].Item2 - 1) { matrixRM.Data[r, c] = (2 * matrixR.Data[r, c] + matrixR.Data[r, c + 1]) / 3; matrixBM.Data[r, c] = (2 * matrixB.Data[r, c] + matrixB.Data[r, c + 1]) / 3; matrixGM.Data[r, c] = (2 * matrixG.Data[r, c] + matrixG.Data[r, c + 1]) / 3; } else if (c == removeList[r].Item2) { matrixRM.Data[r, c] = (matrixR.Data[r, c] + 2 * matrixR.Data[r, c + 1]) / 3; matrixBM.Data[r, c] = (matrixB.Data[r, c] + 2 * matrixB.Data[r, c + 1]) / 3; matrixGM.Data[r, c] = (matrixG.Data[r, c] + 2 * matrixG.Data[r, c + 1]) / 3; } else { matrixRM.Data[r, c] = matrixR.Data[r, c + 1]; matrixBM.Data[r, c] = matrixB.Data[r, c + 1]; matrixGM.Data[r, c] = matrixG.Data[r, c + 1]; } } } } matrixR = matrixRM; matrixB = matrixBM; matrixG = matrixGM; } else { var matrixRM = new MatrixInt32(matrixR.Row - 1, matrixR.Col); var matrixBM = new MatrixInt32(matrixR.Row - 1, matrixR.Col); var matrixGM = new MatrixInt32(matrixR.Row - 1, matrixR.Col); for (int c = 0; c < matrixRM.Col; ++c) { for (int r = 0; r < matrixRM.Row; ++r) { if (!Smoothing) { matrixRM.Data[r, c] = r < removeList[c].Item1 ? matrixR.Data[r, c] : matrixR.Data[r + 1, c]; matrixBM.Data[r, c] = r < removeList[c].Item1 ? matrixB.Data[r, c] : matrixB.Data[r + 1, c]; matrixGM.Data[r, c] = r < removeList[c].Item1 ? matrixG.Data[r, c] : matrixG.Data[r + 1, c]; } else { if (r < removeList[c].Item1 - 1) { matrixRM.Data[r, c] = matrixR.Data[r, c]; matrixBM.Data[r, c] = matrixB.Data[r, c]; matrixGM.Data[r, c] = matrixG.Data[r, c]; } else if (r == removeList[c].Item1 - 1) { matrixRM.Data[r, c] = (matrixR.Data[r + 1, c] + 2 * matrixR.Data[r, c]) / 3; matrixBM.Data[r, c] = (matrixB.Data[r + 1, c] + 2 * matrixB.Data[r, c]) / 3; matrixGM.Data[r, c] = (matrixG.Data[r + 1, c] + 2 * matrixG.Data[r, c]) / 3; } else if (r == removeList[c].Item1) { matrixRM.Data[r, c] = (2 * matrixR.Data[r + 1, c] + matrixR.Data[r, c]) / 3; matrixBM.Data[r, c] = (2 * matrixB.Data[r + 1, c] + matrixB.Data[r, c]) / 3; matrixGM.Data[r, c] = (2 * matrixG.Data[r + 1, c] + matrixG.Data[r, c]) / 3; } else { matrixRM.Data[r, c] = matrixR.Data[r + 1, c]; matrixBM.Data[r, c] = matrixB.Data[r + 1, c]; matrixGM.Data[r, c] = matrixG.Data[r + 1, c]; } } } } matrixR = matrixRM; matrixB = matrixBM; matrixG = matrixGM; } }