Matrix class

Represents a 2D grid of boolean values, primarily used for image processing and pattern recognition tasks.

This class provides various ways to create, manipulate, and analyze boolean matrices, including methods for resizing, comparing, and extracting information from the grid.

Constructors

Matrix([num width = 0, num height = 0, bool value = false])
Creates a new Matrix with the specified dimensions, filled with the given value.
Matrix.fromAsciiDefinition(List<String> template)
Creates a Matrix from an ASCII representation.
factory
Matrix.fromBoolMatrix(List<List<bool>> input)
Creates a Matrix from an existing 2D boolean list.
factory
Matrix.fromFlatListOfBool(List<bool> inputList, int width)
Creates a Matrix from a flat list of boolean values.
factory
Matrix.fromJson(Map<String, dynamic> json)
Creates a Matrix from JSON data.
factory
Matrix.fromMatrix(Matrix value)
Creates a new Matrix instance from an existing Matrix.
factory
Matrix.fromUint8List(Uint8List pixels, int width)
Creates a Matrix from a Uint8List, typically used for image data.
factory

Properties

area int
Area size of the matrix
no setter
cols int
The number of columns in the matrix.
getter/setter pair
data List<List<bool>>
Getter for data
no setter
enclosures int
Gets the number of enclosed regions in the matrix.
no setter
font String
Font this matrix template is based on
getter/setter pair
hashCode int
The hash code for this object.
no setterinherited
isEmpty bool
The grid contains one or more True values
no setter
isNotEmpty bool
All entries in the grid are false
no setter
rectangle Rect
the rectangle location of this matrix.
getter/setter pair
rows int
The number of rows in the matrix.
getter/setter pair
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
verticalLineLeft bool
Determines if there's a vertical line on the left side of the matrix.
no setter
verticalLineRight bool
Determines if there's a vertical line on the right side of the matrix.
no setter

Methods

aspectRatioOfContent() double
Calculates the aspect ratio of the content within the matrix.
cellGet(int x, int y) bool
Retrieves the value of a cell at the specified coordinates.
cellSet(int x, int y, bool value) → void
Sets the value of a cell at the specified coordinates.
createNormalizeMatrix(int desiredWidth, int desiredHeight) Matrix
Creates a new Matrix with the specified desired width and height, by resizing the current Matrix.
getContentRect() Rect
Calculates the bounding rectangle of the content in the matrix.
gridToString({bool forCode = false, String onChar = '#', String offChar = '.'}) String
Converts the matrix to a string representation.
gridToStrings({String onChar = '#', String offChar = '.'}) List<String>
Converts the matrix to a list of strings.
isConsideredLine() bool
Determines if the current Matrix is considered a line based on its aspect ratio.
isPunctuation() bool
smaller (~30%) in height artifacts will be considered punctuation
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
padTopBottom({required int paddingTop, required int paddingBottom}) → void
Adds padding to the top and bottom of the matrix.
setGrid(List<List<bool>> grid) → void
Sets the grid of the Matrix object.
toJson() Map<String, dynamic>
Converts the Matrix object to a JSON-serializable Map.
toString() String
Returns: A string representation ths Matrix.
override
trim() Matrix
Trims the matrix by removing empty rows and columns from all sides.

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

copyGrid(Matrix source, Matrix target, int offsetX, int offsetY) → void
Copies the contents of a source Matrix into a target Matrix, with an optional offset.
extractSubGrid({required Matrix binaryImage, required Rect rect}) Matrix
Extracts a sub-grid from a larger binary image matrix.
fromImage(Image image) Future<Matrix>
Creates a Matrix from a ui.Image.
getStringListOfOverlappedGrids(Matrix grid1, Matrix grid2) List<String>
Creates a string representation of two overlaid matrices.
hammingDistancePercentage(Matrix inputGrid, Matrix templateGrid) double
Calculates the normalized Hamming distance between two matrices.
matrixEquals(Matrix a, Matrix b) bool
Custom comparison method for matrices