Click or drag to resize
Accord.NET (logo)

ImageToMatrix Class

Bitmap to multidimensional matrix converter.
Inheritance Hierarchy
SystemObject
  Accord.Imaging.ConvertersImageToMatrix

Namespace:  Accord.Imaging.Converters
Assembly:  Accord.Imaging (in Accord.Imaging.dll) Version: 3.8.0
Syntax
public class ImageToMatrix : IConverter<Bitmap, double[,]>, 
	IConverter<Bitmap, double[][]>, IConverter<UnmanagedImage, double[,]>, 
	IConverter<UnmanagedImage, double[][]>, IConverter<Bitmap, float[,]>, 
	IConverter<Bitmap, float[][]>, IConverter<UnmanagedImage, float[,]>, 
	IConverter<UnmanagedImage, float[][]>, IConverter<Bitmap, byte[,]>, 
	IConverter<Bitmap, byte[][]>, IConverter<UnmanagedImage, byte[,]>, 
	IConverter<UnmanagedImage, byte[][]>, IConverter<Bitmap, double[,,]>, 
	IConverter<Bitmap, double[][][]>, IConverter<UnmanagedImage, double[,,]>, 
	IConverter<UnmanagedImage, double[][][]>, IConverter<Bitmap, float[,,]>, 
	IConverter<Bitmap, float[][][]>, IConverter<UnmanagedImage, float[,,]>, 
	IConverter<UnmanagedImage, float[][][]>, IConverter<Bitmap, byte[,,]>, 
	IConverter<Bitmap, byte[][][]>, IConverter<UnmanagedImage, byte[,,]>, 
	IConverter<UnmanagedImage, byte[][][]>, IConverter<Bitmap, Color[,]>, 
	IConverter<Bitmap, Color[][]>, IConverter<UnmanagedImage, Color[,]>, 
	IConverter<UnmanagedImage, Color[][]>
Request Example View Source

The ImageToMatrix type exposes the following members.

Constructors
  NameDescription
Public methodImageToMatrix
Initializes a new instance of the ImageToMatrix class.
Public methodImageToMatrix(Double, Double)
Initializes a new instance of the ImageToMatrix class.
Public methodImageToMatrix(Double, Double, Int32)
Initializes a new instance of the ImageToMatrix class.
Top
Properties
  NameDescription
Public propertyChannel
Gets or sets the channel to be extracted.
Public propertyMax
Gets or sets the maximum double value in the double array associated with the brightest color.
Public propertyMin
Gets or sets the minimum double value in the double array associated with the darkest color.
Top
Methods
  NameDescription
Public methodConvert(Bitmap, Byte)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Byte)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Byte)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Byte)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Double)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Double)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Double)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Double)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Color)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Color)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Single)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Single)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Single)
Converts an image from one representation to another.
Public methodConvert(Bitmap, Single)
Converts an image from one representation to another.
Public methodConvert(UnmanagedImage, Byte)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Byte)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Byte)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Byte)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Double)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Double)
Converts an image from one representation to another.
Public methodConvert(UnmanagedImage, Double)
Converts an image from one representation to another.
Public methodConvert(UnmanagedImage, Double)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Color)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Color)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Single)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
Public methodConvert(UnmanagedImage, Single)
Converts an image from one representation to another.
Public methodConvert(UnmanagedImage, Single)
Converts an image from one representation to another.
Public methodConvert(UnmanagedImage, Single)
Converts an image from one representation to another. When converting to byte, the Max and Min are ignored.
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
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
This class converts images to multidimensional matrices of either double-precision or single-precision floating-point values.
Examples

This example converts a 16x16 Bitmap image into a double[,] array with values between 0 and 1.

// Obtain an image
// Bitmap image = ...

// Show on screen
ImageBox.Show(image, PictureBoxSizeMode.Zoom);

// Create the converter to convert the image to a
//  matrix containing only values between 0 and 1 
ImageToMatrix conv = new ImageToMatrix(min: 0, max: 1);

// Convert the image and store it in the matrix
double[,] matrix; conv.Convert(image, out matrix);

// Show the matrix on screen as an image
ImageBox.Show(matrix, PictureBoxSizeMode.Zoom);

The resulting image is shown below.

Additionally, the image can also be shown in alternative representations such as text or data tables.

// Show the matrix on screen as a .NET multidimensional array
MessageBox.Show(matrix.ToString(CSharpMatrixFormatProvider.InvariantCulture));

// Show the matrix on screen as a table
DataGridBox.Show(matrix, nonBlocking: true)
    .SetAutoSizeColumns(DataGridViewAutoSizeColumnsMode.Fill)
    .SetAutoSizeRows(DataGridViewAutoSizeRowsMode.AllCellsExceptHeaders)
    .SetDefaultFontSize(5)
   .WaitForClose();

The resulting images are shown below.

See Also