diff --git a/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs b/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs index 5db8316db..b6c20ea72 100644 --- a/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs +++ b/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs @@ -83,21 +83,19 @@ namespace ImageProcessor.Imaging.EdgeDetection try { double[,] horizontalFilter = this.edgeFilter.HorizontalGradientOperator; - double[,] verticallFilter = this.edgeFilter.VerticalGradientOperator; + double[,] verticalFilter = this.edgeFilter.VerticalGradientOperator; - int filterXOffset = (horizontalFilter.GetLength(1) - 1) / 2; - int filterYOffset = (horizontalFilter.GetLength(0) - 1) / 2; - int maxWidth = width - filterXOffset; - int maxHeight = height - filterYOffset; + int kernelLength = horizontalFilter.GetLength(0); + int radius = kernelLength >> 1; using (FastBitmap sourceBitmap = new FastBitmap(input)) { using (FastBitmap destinationBitmap = new FastBitmap(destination)) { // Loop through the pixels. - for (int y = filterYOffset; y < maxHeight; y++) + for (int y = 0; y < height; y++) { - for (int x = filterXOffset; x < maxWidth; x++) + for (int x = 0; x < width; x++) { double rX = 0; double rY = 0; @@ -107,23 +105,50 @@ namespace ImageProcessor.Imaging.EdgeDetection double bY = 0; // Apply each matrix multiplier to the color components for each pixel. - for (int fy = -1; fy < filterYOffset; fy++) + for (int fy = 0; fy < kernelLength; fy++) { - for (int fx = -1; fx < filterXOffset; fx++) - { - Color currentColor = sourceBitmap.GetPixel(x + fx, y + fy); - double r = currentColor.R; - double g = currentColor.G; - double b = currentColor.B; + int fyr = fy - radius; + int offsetY = y + fyr; - rX += horizontalFilter[fy + 1, fx + 1] * r; - rY += verticallFilter[fy + 1, fx + 1] * r; + // Skip the current row + if (offsetY < 0) + { + continue; + } - gX += horizontalFilter[fy + 1, fx + 1] * g; - gY += verticallFilter[fy + 1, fx + 1] * g; + // Outwith the current bounds so break. + if (offsetY >= height) + { + break; + } - bX += horizontalFilter[fy + 1, fx + 1] * b; - bY += verticallFilter[fy + 1, fx + 1] * b; + for (int fx = 0; fx < kernelLength; fx++) + { + int fxr = fx - radius; + int offsetX = x + fxr; + + // Skip the column + if (offsetX < 0) + { + continue; + } + + if (offsetX < width) + { + Color currentColor = sourceBitmap.GetPixel(offsetX, offsetY); + double r = currentColor.R; + double g = currentColor.G; + double b = currentColor.B; + + rX += horizontalFilter[fy, fx] * r; + rY += verticalFilter[fy, fx] * r; + + gX += horizontalFilter[fy, fx] * g; + gY += verticalFilter[fy, fx] * g; + + bX += horizontalFilter[fy, fx] * b; + bY += verticalFilter[fy, fx] * b; + } } } diff --git a/src/ImageProcessor/Imaging/EdgeDetection/CostellaEdgeFilter.cs b/src/ImageProcessor/Imaging/EdgeDetection/CostellaEdgeFilter.cs index 96f8034ef..fe0cb4c9a 100644 --- a/src/ImageProcessor/Imaging/EdgeDetection/CostellaEdgeFilter.cs +++ b/src/ImageProcessor/Imaging/EdgeDetection/CostellaEdgeFilter.cs @@ -24,12 +24,12 @@ namespace ImageProcessor.Imaging.EdgeDetection { get { - return new double[,] - { { -1, -1, -1, -1, -1, }, - { -1, -1, -1, -1, -1, }, - { -1, -1, 24, -1, -1, }, - { -1, -1, -1, -1, -1, }, - { -1, -1, -1, -1, -1 }, }; + //return new double[,] + //{ { -1, -1, -1, -1, -1, }, + // { -1, -1, -1, -1, -1, }, + // { -1, -1, 24, -1, -1, }, + // { -1, -1, -1, -1, -1, }, + // { -1, -1, -1, -1, -1 }, }; return new double[,] { { -1, -3, 0, 3, 1 }, @@ -48,12 +48,12 @@ namespace ImageProcessor.Imaging.EdgeDetection { get { - return new double[,] - { { -1, -1, -1, -1, -1, }, - { -1, -1, -1, -1, -1, }, - { -1, -1, 24, -1, -1, }, - { -1, -1, -1, -1, -1, }, - { -1, -1, -1, -1, -1 }, }; + //return new double[,] + //{ { -1, -1, -1, -1, -1, }, + // { -1, -1, -1, -1, -1, }, + // { -1, -1, 24, -1, -1, }, + // { -1, -1, -1, -1, -1, }, + // { -1, -1, -1, -1, -1 }, }; return new double[,] { { 1, 1, 1, 1, 1 }, diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs index 16a821272..ddfbdd383 100644 --- a/src/ImageProcessorConsole/Program.cs +++ b/src/ImageProcessorConsole/Program.cs @@ -77,7 +77,7 @@ namespace ImageProcessorConsole //.Constrain(size) //.ReplaceColor(Color.FromArgb(255, 1, 107, 165), Color.FromArgb(255, 1, 165, 13), 80) .Resize(layer) - .DetectEdges(new CostellaEdgeFilter(), false) + .DetectEdges(new PrewittEdgeFilter(), false) //.Filter(MatrixFilters.Comic) //.Filter(MatrixFilters.HiSatch) //.Pixelate(8) diff --git a/src/ImageProcessorConsole/images/output/Bikesgray.png b/src/ImageProcessorConsole/images/output/Bikesgray.png deleted file mode 100644 index 42aec6349..000000000 Binary files a/src/ImageProcessorConsole/images/output/Bikesgray.png and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/Valve_original_(1).PNG b/src/ImageProcessorConsole/images/output/Valve_original_(1).PNG deleted file mode 100644 index d6d313733..000000000 Binary files a/src/ImageProcessorConsole/images/output/Valve_original_(1).PNG and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/circle.png b/src/ImageProcessorConsole/images/output/circle.png deleted file mode 100644 index 663c6cfb1..000000000 Binary files a/src/ImageProcessorConsole/images/output/circle.png and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/circle2.png b/src/ImageProcessorConsole/images/output/circle2.png deleted file mode 100644 index 653a78cba..000000000 Binary files a/src/ImageProcessorConsole/images/output/circle2.png and /dev/null differ diff --git a/src/ImageProcessorConsole/images/output/monster.png.REMOVED.git-id b/src/ImageProcessorConsole/images/output/monster.png.REMOVED.git-id deleted file mode 100644 index 91da330d3..000000000 --- a/src/ImageProcessorConsole/images/output/monster.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -ef1fdff21802713450cf2f81321c0605962ec6f5 \ No newline at end of file diff --git a/src/ImageProcessorConsole/images/output/night-bridge.png.REMOVED.git-id b/src/ImageProcessorConsole/images/output/night-bridge.png.REMOVED.git-id deleted file mode 100644 index 60d52025b..000000000 --- a/src/ImageProcessorConsole/images/output/night-bridge.png.REMOVED.git-id +++ /dev/null @@ -1 +0,0 @@ -fad7e5225f13c9d35d9e877c93e2bb44da7404c0 \ No newline at end of file