//
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
//
namespace ImageProcessorCore
{
using Processors;
///
/// Extension methods for the type.
///
public static partial class ImageExtensions
{
///
/// Detects any edges within the image. Uses the filter
/// operating in Grayscale mode.
///
/// The pixel format.
/// The packed format. uint, long, float.
/// The image this method extends.
/// The .
public static Image DetectEdges(this Image source)
where TColor : IPackedVector
where TPacked : struct
{
return DetectEdges(source, source.Bounds, new SobelProcessor { Grayscale = true });
}
///
/// Detects any edges within the image. Uses the filter
/// operating in Grayscale mode.
///
/// The pixel format.
/// The packed format. uint, long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// The .
public static Image DetectEdges(this Image source, Rectangle rectangle)
where TColor : IPackedVector
where TPacked : struct
{
return DetectEdges(source, rectangle, new SobelProcessor { Grayscale = true });
}
///
/// Detects any edges within the image.
///
/// The pixel format.
/// The packed format. uint, long, float.
/// The image this method extends.
/// The filter for detecting edges.
/// Whether to convert the image to Grayscale first. Defaults to true.
/// The .
public static Image DetectEdges(this Image source, EdgeDetection filter, bool grayscale = true)
where TColor : IPackedVector
where TPacked : struct
{
return DetectEdges(source, filter, source.Bounds, grayscale);
}
///
/// Detects any edges within the image.
///
/// The pixel format.
/// The packed format. uint, long, float.
/// The image this method extends.
/// The filter for detecting edges.
///
/// The structure that specifies the portion of the image object to alter.
///
/// Whether to convert the image to Grayscale first. Defaults to true.
/// The .
public static Image DetectEdges(this Image source, EdgeDetection filter, Rectangle rectangle, bool grayscale = true)
where TColor : IPackedVector
where TPacked : struct
{
IEdgeDetectorFilter processor;
switch (filter)
{
case EdgeDetection.Kayyali:
processor = new KayyaliProcessor { Grayscale = grayscale };
break;
case EdgeDetection.Kirsch:
processor = new KirschProcessor { Grayscale = grayscale };
break;
case EdgeDetection.Lapacian3X3:
processor = new Laplacian3X3Processor { Grayscale = grayscale };
break;
case EdgeDetection.Lapacian5X5:
processor = new Laplacian5X5Processor { Grayscale = grayscale };
break;
case EdgeDetection.LaplacianOfGaussian:
processor = new LaplacianOfGaussianProcessor { Grayscale = grayscale };
break;
case EdgeDetection.Prewitt:
processor = new PrewittProcessor { Grayscale = grayscale };
break;
case EdgeDetection.RobertsCross:
processor = new RobertsCrossProcessor { Grayscale = grayscale };
break;
case EdgeDetection.Robinson:
processor = new RobinsonProcessor { Grayscale = grayscale };
break;
case EdgeDetection.Scharr:
processor = new ScharrProcessor { Grayscale = grayscale };
break;
default:
processor = new SobelProcessor { Grayscale = grayscale };
break;
}
return DetectEdges(source, rectangle, processor);
}
///
/// Detects any edges within the image.
///
/// The pixel format.
/// The packed format. uint, long, float.
/// The image this method extends.
/// The filter for detecting edges.
/// The .
public static Image DetectEdges(this Image source, IEdgeDetectorFilter filter)
where TColor : IPackedVector
where TPacked : struct
{
return DetectEdges(source, source.Bounds, filter);
}
///
/// Detects any edges within the image.
///
/// The pixel format.
/// The packed format. uint, long, float.
/// The image this method extends.
///
/// The structure that specifies the portion of the image object to alter.
///
/// The filter for detecting edges.
/// The .
public static Image DetectEdges(this Image source, Rectangle rectangle, IEdgeDetectorFilter filter)
where TColor : IPackedVector
where TPacked : struct
{
return source.Process(rectangle, filter);
}
}
}