Click or drag to resize
Accord.NET (logo)

ColorErrorDiffusionToAdjacentNeighbors Class

Base class for error diffusion color dithering, where error is diffused to adjacent neighbor pixels.
Inheritance Hierarchy

Namespace:  Accord.Imaging.ColorReduction
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
public class ColorErrorDiffusionToAdjacentNeighbors : ErrorDiffusionColorDithering
Request Example View Source

The ColorErrorDiffusionToAdjacentNeighbors type exposes the following members.

Constructors
  NameDescription
Public methodColorErrorDiffusionToAdjacentNeighbors
Initializes a new instance of the ColorErrorDiffusionToAdjacentNeighbors class.
Top
Properties
  NameDescription
Public propertyCoefficients
Diffusion coefficients.
Public propertyColorTable
Color table to use for image dithering. Must contain 2-256 colors.
(Inherited from ErrorDiffusionColorDithering.)
Public propertyUseCaching
Use color caching during color dithering or not.
(Inherited from ErrorDiffusionColorDithering.)
Top
Methods
  NameDescription
Public methodApply(Bitmap)
Perform color dithering for the specified image.
(Inherited from ErrorDiffusionColorDithering.)
Public methodApply(UnmanagedImage)
Perform color dithering for the specified image.
(Inherited from ErrorDiffusionColorDithering.)
Protected methodDiffuse
Do error diffusion.
(Overrides ErrorDiffusionColorDitheringDiffuse(Int32, Int32, Int32, Byte*).)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Fields
  NameDescription
Protected fieldheight
Processing image's height.
(Inherited from ErrorDiffusionColorDithering.)
Protected fieldpixelSize
Processing image's pixel size in bytes.
(Inherited from ErrorDiffusionColorDithering.)
Protected fieldstride
Processing image's stride (line size).
(Inherited from ErrorDiffusionColorDithering.)
Protected fieldwidth
Processing image's width.
(Inherited from ErrorDiffusionColorDithering.)
Protected fieldx
Current processing X coordinate.
(Inherited from ErrorDiffusionColorDithering.)
Protected fieldy
Current processing Y coordinate.
(Inherited from ErrorDiffusionColorDithering.)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

The class does error diffusion to adjacent neighbor pixels using specified set of coefficients. These coefficients are represented by 2 dimensional jugged array, where first array of coefficients is for right-standing pixels, but the rest of arrays are for bottom-standing pixels. All arrays except the first one should have odd number of coefficients.

Suppose that error diffusion coefficients are represented by the next jugged array:

int[][] coefficients = new int[2][] {
    new int[1] { 7 },
    new int[3] { 3, 5, 1 }
};

The above coefficients are used to diffuse error over the next neighbor pixels (* marks current pixel, coefficients are placed to corresponding neighbor pixels):

    | * | 7 |
| 3 | 5 | 1 |

/ 16

The image processing routine accepts 24/32 bpp color images for processing.

Sample usage:

// create dithering routine
ColorErrorDiffusionToAdjacentNeighbors dithering = new ColorErrorDiffusionToAdjacentNeighbors(
    new int[3][] {
        new int[2] { 5, 3 },
        new int[5] { 2, 4, 5, 4, 2 },
        new int[3] { 2, 3, 2 }
    } );
// apply the dithering routine
Bitmap newImage = dithering.Apply( image );
See Also