Artifact 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
- Artifact(int cols, int rows)
- Main constructor
-
Artifact.fromAsciiDefinition(List<
String> template) -
Creates an Artifact from an ASCII representation.
factory
- Artifact.fromAsciiWithNewlines(String input)
-
Creates an Artifact from a multi-line ASCII string representation.
factory
-
Artifact.fromFlatListOfBool(List<
bool> inputList, int width) -
Creates an Artifact from a flat list of boolean values.
factory
-
Artifact.fromJson(Map<
String, dynamic> json) -
Creates an Artifact from JSON data.
factory
- Artifact.fromMatrix(Artifact value)
-
Creates a new Artifact instance from an existing Artifact.
factory
-
Artifact.fromPoints(List<
Point< connectedPoints)int> > -
Creates a new Artifact from a list of connected points.
factory
- Artifact.fromUint8List(Uint8List pixels, int width)
-
Creates an Artifact 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 grid.
getter/setter pair
- enclosures → int
-
Gets the number of enclosed regions in the matrix.
no setter
- font ↔ String
-
Font this 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
- locationAdjusted ↔ IntOffset
-
The adjusted location.
getter/setter pair
- locationFound ↔ IntOffset
-
The location of this artifact in the source image.
getter/setter pair
- matchingCharacter ↔ String
-
The character that this artifact matches.
getter/setter pair
- matchingCharacterDescription → String
-
Returns a human-readable description of the matching character.
no setter
- matchingScore ↔ double
-
The score of the match
getter/setter pair
- matrix → Uint8List
-
The raw grid buffer.
no setter
- needsInspection ↔ bool
-
Tag the artifact as needing more attention during inspection
getter/setter pair
- rectAdjusted → IntRect
-
The rectangle location after adjustment.
no setter
- rectFound → IntRect
-
The rectangle location of this artifact.
no setter
- rows → int
-
The number of rows in the grid.
no setter
- 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
- wasPartOfSplit ↔ bool
-
Indicates whether this artifact was created as part of a splitting operation
getter/setter pair
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.
-
clear(
) → void - Empty the content
-
countOnPixels(
{IntRect? rect}) → int - Counts the number of "on" pixels within an optional rectangle.
-
countVerticalStems(
) → int - Estimates the number of strong vertical stems in a glyph.
-
createNormalizeMatrix(
int desiredWidth, int desiredHeight) → Artifact - Creates a new Artifact with the specified desired width and height, by resizing the current Artifact.
-
debugPrintGrid(
) → void - Prints the grid to the debug console.
-
discardableContent(
) → bool - Determines if this artifact contains content that can be discarded.
-
erodeSoft(
) → Artifact - Creates a softly eroded version of this artifact to reduce stroke thickness.
-
extractSubGrid(
{required IntRect rect}) → Artifact - Extracts a sub-grid from a larger binary image matrix.
-
findSubArtifacts(
) → List< Artifact> - Finds the connected components (artifacts) in a binary image matrix.
-
findSubRegions(
) → List< IntRect> - Identifies distinct regions in a dilated binary image.
-
getContentRect(
) → IntRect - Calculates the bounding rectangle of the content in the matrix.
-
getHistogramHorizontal(
) → List< int> - Returns the horizontal histogram of the matrix.
-
getHistogramVertical(
) → List< int> - Returns the vertical histogram of 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.
-
hasLowerRightStroke(
) → bool - Detects ink density in the lower-right quadrant of the glyph.
-
isConsideredLine(
) → bool - Determines if the current Artifact is considered a line based on its aspect ratio.
-
isPunctuation(
) → bool - smaller (~40%) in height artifacts will be considered punctuation
-
mergeArtifact(
Artifact toMerge) → void - Merges the current artifact with another artifact.
-
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.
-
setBothLocation(
IntOffset location) → void - rect setting helper
-
setGrid(
Uint8List grid, int cols) → void - Sets the grid from a flat Uint8List and column count.
-
setGridFromBools(
List< List< input) → voidbool> > - Sets the grid of the Artifact object from a 2D list of boolean values.
-
toJson(
) → Map< String, dynamic> - Converts the Artifact object to a JSON-serializable Map.
-
toString(
) → String -
Returns a string representation of this artifact.
override
-
toText(
{String onChar = '#', bool forCode = false}) → String - Converts the matrix to a text representation.
-
trim(
) → Artifact - Trims the matrix by removing empty rows and columns from all sides.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
artifactFromImage(
Image image) → Future< Artifact> - Creates a Artifact from a Image.
-
artifactValleysOffsets(
Artifact artifact, {bool allowSoftValleys = true}) → List< int> - Returns a list of column indices where the artifact should be split
-
calculateThreshold(
List< int> histogram) → int - Calculates an appropriate threshold for identifying valleys in a histogram
-
copyArtifactGrid(
Artifact source, Artifact target, int offsetX, int offsetY) → void - Copies the contents of a source Artifact into a target Artifact, with an optional offset.
-
dilateArtifact(
{required Artifact matrixImage, required int kernelSize}) → Artifact - Applies dilation morphological operation to a binary image.
-
floodFill(
Artifact binaryPixels, Artifact visited, int startX, int startY) → List< Point< int> > - Performs a highly optimized flood fill algorithm on a binary image matrix.
-
floodFillToRect(
Artifact binaryPixels, Artifact visited, int startX, int startY) → IntRect - Performs a flood fill algorithm and directly calculates the bounding rectangle without storing all individual points.
-
hammingDistancePercentageOfTwoArtifacts(
Artifact inputGrid, Artifact templateGrid) → double - Calculates the normalized Hamming distance between two matrices.
-
offsetArtifacts(
List< Artifact> matrices, int x, int y) → void - Applies an offset to the location of a list of matrices.
-
sortMatrices(
List< Artifact> list) → void - Sorts a list of Artifact objects based on their vertical and horizontal positions.
-
sortRectangles(
List< IntRect> list, {double threshold = _defaultRectangleSortThreshold}) → void - Sorts a list of IntRect objects based on their vertical and horizontal positions.
-
splitArtifactByColumns(
Artifact artifactToSplit, List< int> offsets) → List<Artifact> - Splits the given artifact into multiple column slices based on the offsets.