Browse Source

Add Lanczos2 resampler

Former-commit-id: 7190b01b85ed5933e0f5dd276b3eb718a8d78e30
Former-commit-id: 56df11ca6ffb6d0075115dc3b2c714317a379ab8
Former-commit-id: becd320711a19b21267790300429105e071fc5de
af/merge-core
James Jackson-South 10 years ago
parent
commit
250fc599e1
  1. 33
      README.md
  2. 34
      src/ImageProcessorCore/Samplers/Resamplers/Lanczos2Resampler.cs

33
README.md

@ -1,3 +1,4 @@
# ImageProcessorCore
<img src="build/icons/imageprocessor-logo-512.png" width="128" height="128"/>
@ -74,6 +75,7 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- Resampling algorithms. (Optional gamma correction, resize modes, Performance improvements?)
- [x] Box
- [x] Bicubic
- [x] Lanczos2
- [x] Lanczos3
- [x] Lanczos5
- [x] Lanczos8
@ -81,7 +83,6 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] Nearest Neighbour
- [x] Robidoux
- [x] Robidoux Sharp
- [x] Robidoux Soft
- [x] Spline
- [x] Triangle
- [x] Welch
@ -100,8 +101,8 @@ git clone https://github.com/JimBobSquarePants/ImageProcessor
- [x] Skew by x/y angles and center point.
- ColorMatrix operations (Uses Matrix4x4)
- [x] BlackWhite
- [x] Greyscale BT709
- [x] Greyscale BT601
- [x] Grayscale BT709
- [x] Grayscale BT601
- [x] Hue
- [x] Saturation
- [x] Lomograph
@ -160,7 +161,7 @@ With this version the API will change dramatically. Without the constraints of `
Image methods are also fluent which allow chaining much like the `ImageFactory` class in the Framework version.
Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their greyscale equivalent using the BT709 standard matrix.
Here's an example of the code required to resize an image using the default Bicubic resampler then turn the colors into their grayscale equivalent using the BT709 standard matrix.
```csharp
using (FileStream stream = File.OpenRead("foo.jpg"))
@ -168,32 +169,12 @@ using (FileStream output = File.OpenWrite("bar.jpg"))
{
Image image = new Image(stream);
image.Resize(image.Width / 2, image.Height / 2)
.Greyscale()
.Grayscale()
.Save(output);
}
```
It will also be possible to pass collections of processors as params to manipulate images. For example here I am applying a Gaussian blur with a sigma of 5 to an image, then detecting the edges using a Sobel operator working in greyscale mode.
```csharp
using (FileStream stream = File.OpenRead("foo.jpg"))
using (FileStream output = File.OpenWrite("bar.jpg"))
{
Image image = new Image(stream);
List<IImageProcessor> processors = new List<IImageProcessor>()
{
new GuassianBlur(5),
new Sobel { Greyscale = true }
};
foreach (IImageProcessor processor in processors){
image.Process(processor)
.Save(output);
}
}
```
Individual processors can be initialised and apply processing against images. This allows nesting which will allow the powerful combination of processing methods:
Individual processors can be initialised and apply processing against images. This allows nesting which brings the potential for powerful combinations of processing methods:
```csharp
new Brightness(50).Apply(sourceImage, targetImage, sourceImage.Bounds);

34
src/ImageProcessorCore/Samplers/Resamplers/Lanczos2Resampler.cs

@ -0,0 +1,34 @@
// <copyright file="Lanczos2Resampler.cs" company="James Jackson-South">
// Copyright (c) James Jackson-South and contributors.
// Licensed under the Apache License, Version 2.0.
// </copyright>
namespace ImageProcessorCore
{
/// <summary>
/// The function implements the Lanczos kernel algorithm as described on
/// <see href="https://en.wikipedia.org/wiki/Lanczos_resampling#Algorithm">Wikipedia</see>
/// with a radius of 2 pixels.
/// </summary>
public class Lanczos2Resampler : IResampler
{
/// <inheritdoc/>
public float Radius => 2;
/// <inheritdoc/>
public float GetValue(float x)
{
if (x < 0F)
{
x = -x;
}
if (x < 2F)
{
return ImageMaths.SinC(x) * ImageMaths.SinC(x / 2F);
}
return 0F;
}
}
}
Loading…
Cancel
Save