diff --git a/build/Build.ImageProcessor.Plugins.Cair.proj b/build/Build.ImageProcessor.Plugins.Cair.proj
deleted file mode 100644
index d4668467da..0000000000
--- a/build/Build.ImageProcessor.Plugins.Cair.proj
+++ /dev/null
@@ -1,54 +0,0 @@
-
-
- .\
-
-
-
-
-
-
-
- Release
- _BuildOutput\
- False
- $(MSBuildProjectDirectory)\$(BuildFolder)
- $(BuildFolderAbsolutePath)ImageProcessor.Plugins.Cair\lib\net45
- ..\src\Plugins\ImageProcessor\ImageProcessor.Plugins.Cair\
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs
index 89ec3b951c..e57e0f9135 100644
--- a/src/ImageProcessor.Web/Properties/AssemblyInfo.cs
+++ b/src/ImageProcessor.Web/Properties/AssemblyInfo.cs
@@ -1,4 +1,4 @@
-// --------------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
@@ -19,7 +19,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("James South")]
[assembly: AssemblyCompany("James South")]
[assembly: AssemblyProduct("ImageProcessor.Web")]
-[assembly: AssemblyCopyright("Copyright © James South")]
+[assembly: AssemblyCopyright("Copyright © James South")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/src/ImageProcessor/ImageFactory.cs b/src/ImageProcessor/ImageFactory.cs
index 9e88c09448..b21f6f9867 100644
--- a/src/ImageProcessor/ImageFactory.cs
+++ b/src/ImageProcessor/ImageFactory.cs
@@ -20,6 +20,7 @@ namespace ImageProcessor
using ImageProcessor.Common.Exceptions;
using ImageProcessor.Imaging;
+ using ImageProcessor.Imaging.EdgeDetection;
using ImageProcessor.Imaging.Filters;
using ImageProcessor.Imaging.Formats;
using ImageProcessor.Processors;
@@ -440,6 +441,17 @@ namespace ImageProcessor
return this;
}
+ public ImageFactory DetectEdges(IEdgeFilter filter)
+ {
+ if (this.ShouldProcess)
+ {
+ DetectEdges detectEdges = new DetectEdges { DynamicParameter = filter };
+ this.CurrentImageFormat.ApplyProcessor(detectEdges.ProcessImage, this);
+ }
+
+ return this;
+ }
+
///
/// Applies a filter to the current image. Use the class to
/// assign the correct filter.
diff --git a/src/ImageProcessor/ImageProcessor.csproj b/src/ImageProcessor/ImageProcessor.csproj
index 4a44398abf..faa73bd1b9 100644
--- a/src/ImageProcessor/ImageProcessor.csproj
+++ b/src/ImageProcessor/ImageProcessor.csproj
@@ -37,6 +37,7 @@
4
bin\Release\ImageProcessor.XML
false
+ true
true
@@ -51,6 +52,7 @@
4
false
false
+ true
@@ -74,6 +76,9 @@
+
+
+
Code
@@ -121,6 +126,7 @@
+
diff --git a/src/ImageProcessor/Imaging/Convolution.cs b/src/ImageProcessor/Imaging/Convolution.cs
index c44d055c02..22d66bad8b 100644
--- a/src/ImageProcessor/Imaging/Convolution.cs
+++ b/src/ImageProcessor/Imaging/Convolution.cs
@@ -12,8 +12,6 @@ namespace ImageProcessor.Imaging
{
using System;
using System.Drawing;
- using System.Drawing.Imaging;
- using System.Runtime.InteropServices;
using ImageProcessor.Common.Extensions;
diff --git a/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs b/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs
new file mode 100644
index 0000000000..2307df3358
--- /dev/null
+++ b/src/ImageProcessor/Imaging/EdgeDetection/ConvolutionFilter.cs
@@ -0,0 +1,66 @@
+
+namespace ImageProcessor.Imaging.EdgeDetection
+{
+ using System;
+ using System.Drawing;
+ using System.Drawing.Imaging;
+
+ using ImageProcessor.Common.Extensions;
+
+ ///
+ /// http://pastebin.com/xHHD3pXi
+ ///
+ public class ConvolutionFilter
+ {
+ private readonly IEdgeFilter edgeFilter;
+
+ public ConvolutionFilter(IEdgeFilter edgeFilter)
+ {
+ this.edgeFilter = edgeFilter;
+ }
+
+ public Bitmap ProcessFilter(Bitmap source)
+ {
+ double[,] horizontalFilter = this.edgeFilter.HorizontalMatrix;
+ double[,] verticallFilter = this.edgeFilter.VerticalMatrix;
+
+ int width = source.Width;
+ int height = source.Height;
+ int maxWidth = width - 1;
+ int maxHeight = height - 1;
+
+ Bitmap destination = new Bitmap(width, height, PixelFormat.Format32bppArgb);
+ using (FastBitmap sourceBitmap = new FastBitmap(source))
+ {
+ using (FastBitmap destinationBitmap = new FastBitmap(destination))
+ {
+ for (int y = 1; y < maxHeight; y++)
+ {
+ for (int x = 1; x < maxWidth; x++)
+ {
+ double newX = 0;
+ double newY = 0;
+
+ for (int hw = -1; hw < 2; hw++)
+ {
+ for (int wi = -1; wi < 2; wi++)
+ {
+ double component = sourceBitmap.GetPixel(x + wi, y + hw).B;
+ newX += horizontalFilter[hw + 1, wi + 1] * component;
+ newY += verticallFilter[hw + 1, wi + 1] * component;
+ }
+ }
+
+ byte value = Math.Sqrt((newX * newX) + (newY * newY)).ToByte();
+ Color tempcolor = Color.FromArgb(value, value, value);
+ destinationBitmap.SetPixel(x, y, tempcolor);
+ }
+ }
+ }
+ }
+
+ return destination;
+
+ }
+ }
+}
diff --git a/src/ImageProcessor/Imaging/EdgeDetection/IEdgeFilter.cs b/src/ImageProcessor/Imaging/EdgeDetection/IEdgeFilter.cs
new file mode 100644
index 0000000000..bf30c7cf98
--- /dev/null
+++ b/src/ImageProcessor/Imaging/EdgeDetection/IEdgeFilter.cs
@@ -0,0 +1,9 @@
+namespace ImageProcessor.Imaging.EdgeDetection
+{
+ public interface IEdgeFilter
+ {
+ double[,] HorizontalMatrix { get; }
+
+ double[,] VerticalMatrix { get; }
+ }
+}
diff --git a/src/ImageProcessor/Imaging/EdgeDetection/SobelEdgeFilter.cs b/src/ImageProcessor/Imaging/EdgeDetection/SobelEdgeFilter.cs
new file mode 100644
index 0000000000..ac71d1caaa
--- /dev/null
+++ b/src/ImageProcessor/Imaging/EdgeDetection/SobelEdgeFilter.cs
@@ -0,0 +1,27 @@
+namespace ImageProcessor.Imaging.EdgeDetection
+{
+ public class SobelEdgeFilter : IEdgeFilter
+ {
+ public double[,] HorizontalMatrix
+ {
+ get
+ {
+ return new double[,]
+ { { -1, 0, 1, },
+ { -2, 0, 2, },
+ { -1, 0, 1, }, };
+ }
+ }
+
+ public double[,] VerticalMatrix
+ {
+ get
+ {
+ return new double[,]
+ { { 1, 2, 1, },
+ { 0, 0, 0, },
+ { -1, -2, -1, }, };
+ }
+ }
+ }
+}
diff --git a/src/ImageProcessor/Processors/DetectEdges.cs b/src/ImageProcessor/Processors/DetectEdges.cs
new file mode 100644
index 0000000000..a368d6f9a9
--- /dev/null
+++ b/src/ImageProcessor/Processors/DetectEdges.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ImageProcessor.Processors
+{
+ using System.Drawing;
+
+ using ImageProcessor.Common.Exceptions;
+ using ImageProcessor.Imaging.EdgeDetection;
+
+ public class DetectEdges : IGraphicsProcessor
+ {
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public DetectEdges()
+ {
+ this.Settings = new Dictionary();
+ }
+
+ ///
+ /// Gets or sets the dynamic parameter.
+ ///
+ public dynamic DynamicParameter
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Gets or sets any additional settings required by the processor.
+ ///
+ public Dictionary Settings
+ {
+ get;
+ set;
+ }
+
+ ///
+ /// Processes the image.
+ ///
+ ///
+ /// The current instance of the class containing
+ /// the image to process.
+ ///
+ ///
+ /// The processed image from the current instance of the class.
+ ///
+ public Image ProcessImage(ImageFactory factory)
+ {
+ Bitmap newImage = null;
+ Image image = factory.Image;
+ IEdgeFilter filter = this.DynamicParameter;
+ try
+ {
+ ConvolutionFilter convolutionFilter = new ConvolutionFilter(filter);
+ newImage = convolutionFilter.ProcessFilter((Bitmap)image);
+
+ image.Dispose();
+ image = newImage;
+ }
+ catch (Exception ex)
+ {
+ if (newImage != null)
+ {
+ newImage.Dispose();
+ }
+
+ throw new ImageProcessingException("Error processing image with " + this.GetType().Name, ex);
+ }
+
+ return image;
+ }
+ }
+}
diff --git a/src/ImageProcessor/Properties/AssemblyInfo.cs b/src/ImageProcessor/Properties/AssemblyInfo.cs
index 66b52a80c6..db15f39401 100644
--- a/src/ImageProcessor/Properties/AssemblyInfo.cs
+++ b/src/ImageProcessor/Properties/AssemblyInfo.cs
@@ -1,4 +1,4 @@
-// --------------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) James South.
// Licensed under the Apache License, Version 2.0.
@@ -19,7 +19,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("James South")]
[assembly: AssemblyProduct("ImageProcessor")]
-[assembly: AssemblyCopyright("Copyright © James South")]
+[assembly: AssemblyCopyright("Copyright © James South")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
diff --git a/src/ImageProcessorConsole/Program.cs b/src/ImageProcessorConsole/Program.cs
index beb1d1df7b..4adeb1238d 100644
--- a/src/ImageProcessorConsole/Program.cs
+++ b/src/ImageProcessorConsole/Program.cs
@@ -18,6 +18,7 @@ namespace ImageProcessorConsole
using System.Linq;
using ImageProcessor;
using ImageProcessor.Imaging;
+ using ImageProcessor.Imaging.EdgeDetection;
using ImageProcessor.Imaging.Filters;
using ImageProcessor.Plugins.Cair;
using ImageProcessor.Plugins.Cair.Imaging;
@@ -45,8 +46,8 @@ namespace ImageProcessorConsole
di.Create();
}
- //IEnumerable files = GetFilesByExtensions(di, ".jpg");
- IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png", ".tif");
+ IEnumerable files = GetFilesByExtensions(di, ".jpg");
+ //IEnumerable files = GetFilesByExtensions(di, ".gif", ".webp", ".bmp", ".jpg", ".png", ".tif");
foreach (FileInfo fileInfo in files)
{
@@ -76,6 +77,7 @@ namespace ImageProcessorConsole
//.Constrain(size)
//.ReplaceColor(Color.FromArgb(255, 1, 107, 165), Color.FromArgb(255, 1, 165, 13), 80)
.Resize(layer)
+ .DetectEdges(new SobelEdgeFilter())
//.Filter(MatrixFilters.Comic)
//.Filter(MatrixFilters.HiSatch)
//.Pixelate(8)
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Properties/AssemblyInfo.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Properties/AssemblyInfo.cs
index 2926ca75dd..632353784e 100644
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Properties/AssemblyInfo.cs
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.Cair/Properties/AssemblyInfo.cs
@@ -1,4 +1,4 @@
-using System.Reflection;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ImageProcessor.Plugins.Cair")]
-[assembly: AssemblyCopyright("Copyright James South © 2014")]
+[assembly: AssemblyCopyright("Copyright James South © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
+// [assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
diff --git a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.WebP/Properties/AssemblyInfo.cs b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.WebP/Properties/AssemblyInfo.cs
index 0f4b2367bc..bc53f212e2 100644
--- a/src/Plugins/ImageProcessor/ImageProcessor.Plugins.WebP/Properties/AssemblyInfo.cs
+++ b/src/Plugins/ImageProcessor/ImageProcessor.Plugins.WebP/Properties/AssemblyInfo.cs
@@ -1,4 +1,4 @@
-using System.Reflection;
+using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
@@ -10,7 +10,7 @@ using System.Runtime.InteropServices;
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("James South")]
[assembly: AssemblyProduct("ImageProcessor.Plugins.WebP")]
-[assembly: AssemblyCopyright("Copyright © James South")]
+[assembly: AssemblyCopyright("Copyright © James South")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
@@ -31,6 +31,6 @@ using System.Runtime.InteropServices;
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
-// [assembly: AssemblyVersion("1.0.*")]
+// [assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]