Filtering - AzuxirenLeadGuy/GdiPlusExtension GitHub Wiki

Filtering

The static class GdiPlusExtensions.Filters.Filters defines a static extension method Filter() to apply a filter on that image.

public static void Filter(this Bitmap sourceImage, IFilterType filterType)

This library defines the following IFilterType types which you can use in this method

ConvolutionFilter

struct ConvolutionFilter allows to define a kernel for linearly filtering a Bitmap image.

It already has the following two filters defined

public struct ConvolutionFilter
{
	public static ConvolutionFilter BoxBlur;
	public static ConvolutionFilter GaussianFilter;
}

Given a bitmap object, you can filter your image as follows for these filters:

BoxBlur

Bitmap img1 = ...//Open image "img1"
img1.Filter(ConvolutionFilter.BoxBlur);//see showcase for img1 at the end of this wiki

img1

GaussianFilter

Bitmap img2 = ...//Open Image "img2"
img1.Filter(ConvolutionFilter.GaussianFilter);//see showcase for img2 at the end of this wiki

img2

Median Filter and Bilateral Filter

These filters are defined as separate types and an object is needed to filter the images. These filters can be given parameters via their constructors as shown.

Bitmap img3 = ...//Open image img3
img3.Filter(new MedianFilter(){KernelSize = 7})//see showcase for img3 at the end of this wiki

img3

The bilateral filter needs to be initialized via constructor to set its SigmaSpace and SigmaColor values as non-zero, as shown

Bitmap img4 = ...//Open image img4
img4.Filter(new BilateralFilter() {KernelSize=9, SigmaColor=50, SigmaSpace=40})//see showcase for img4 at the end of this wiki

img4

TintFilter

This filter tints every pixel, i.e uses linear interpolation of every pixel to the given Color ColorToTint field of the Filter, along with the given intensity.

Bitmap img5 = ...//Open image img5
img5.Filter(new TintFilter(Color.Yellow, 80)); // Tint all pixels to Yellow, by a factor of 80/255

img5