public static IntegerMatrix GetRedMatrix(IntegerMatrix scanDataMatrix)
        {
            IntegerMatrix resMatrix = new IntegerMatrix(scanDataMatrix.RowCount, scanDataMatrix.ColumnCount);

            for (int row = 0; row < scanDataMatrix.RowCount; row++)
            {
                for (int column = 0; column < scanDataMatrix.ColumnCount; column++)
                {
                    ComponentEnum component = BayerMatrixHelper.GetComponent(row, column);
                    if (component == ComponentEnum.Red)
                    {
                        resMatrix[row, column] = scanDataMatrix[row, column];
                    }
                    if (component == ComponentEnum.Green1)
                    {
                        ComponentLocationEnum[] locations = new ComponentLocationEnum[]
                        {
                            ComponentLocationEnum.West,
                            ComponentLocationEnum.East
                        };
                        resMatrix[row, column] = InterpolateValue(scanDataMatrix, row, column, locations);
                    }
                    if (component == ComponentEnum.Green2)
                    {
                        ComponentLocationEnum[] locations = new ComponentLocationEnum[]
                        {
                            ComponentLocationEnum.Nord,
                            ComponentLocationEnum.South
                        };
                        resMatrix[row, column] = InterpolateValue(scanDataMatrix, row, column, locations);
                    }
                    if (component == ComponentEnum.Blue)
                    {
                        ComponentLocationEnum[] locations = new ComponentLocationEnum[]
                        {
                            ComponentLocationEnum.NordWest,
                            ComponentLocationEnum.NordEast,
                            ComponentLocationEnum.SouthWest,
                            ComponentLocationEnum.SouthEast
                        };
                        resMatrix[row, column] = InterpolateValue(scanDataMatrix, row, column, locations);
                    }
                }
            }

            return(resMatrix);
        }
Ejemplo n.º 2
0
        public static int?GetComponentValue(

            IntegerMatrix matrix,
            int rowIndex, int columnIndex,
            ComponentLocationEnum componentLocation
            )
        {
            int targetRow    = 0;
            int targetColumn = 0;

            int? resValue  = null;
            bool isCorrect = true;

            switch (componentLocation)
            {
            case ComponentLocationEnum.Nord:
            {
                targetRow    = rowIndex - 1;
                targetColumn = columnIndex;
                isCorrect    = targetRow >= 0;
                break;
            }

            case ComponentLocationEnum.East:
            {
                targetRow    = rowIndex;
                targetColumn = columnIndex + 1;
                isCorrect    = targetColumn < matrix.ColumnCount;
                break;
            }

            case ComponentLocationEnum.South:
            {
                targetRow    = rowIndex + 1;
                targetColumn = columnIndex;
                isCorrect    = targetRow < matrix.RowCount;
                break;
            }

            case ComponentLocationEnum.West:
            {
                targetRow    = rowIndex;
                targetColumn = columnIndex - 1;
                isCorrect    = targetColumn >= 0;
                break;
            }

            case ComponentLocationEnum.NordWest:
            {
                targetRow    = rowIndex - 1;
                targetColumn = columnIndex - 1;
                isCorrect    = targetRow >= 0 && targetColumn >= 0;
                break;
            }

            case ComponentLocationEnum.NordEast:
            {
                targetRow    = rowIndex - 1;
                targetColumn = columnIndex + 1;
                isCorrect    = targetRow >= 0 && targetColumn < matrix.ColumnCount;
                break;
            }

            case ComponentLocationEnum.SouthEast:
            {
                targetRow    = rowIndex + 1;
                targetColumn = columnIndex + 1;
                isCorrect    = targetRow < matrix.RowCount && targetColumn < matrix.ColumnCount;
                break;
            }

            case ComponentLocationEnum.SouthWest:
            {
                targetRow    = rowIndex + 1;
                targetColumn = columnIndex - 1;
                isCorrect    = targetRow < matrix.RowCount && targetColumn >= 0;
                break;
            }
            }

            if (isCorrect)
            {
                resValue = matrix[targetRow, targetColumn];
            }
            else
            {
                resValue = null;
            }

            return(resValue);
        }