HomeUniDoc
...

Package bitmap

Overview ▾

Package bitmap contains the bitmap data container for the binary images used when decoding the jbig2 encoded images. This package contains also multiple binary image operational functions that classifies them, does the morphology changes, does raster operations and combines multiple instances into single image.

Index ▾

func Blit(src *Bitmap, dst *Bitmap, x, y int, op CombinationOperator) error
func ClipBoxToRectangle(box *image.Rectangle, wi, hi int) (out *image.Rectangle, err error)
func CombineBytes(oldByte, newByte byte, op CombinationOperator) byte
func CorrelationScore(bm1, bm2 *Bitmap, area1, area2 int, delX, delY float32, maxDiffW, maxDiffH int, tab []int) (score float64, err error)
func CorrelationScoreSimple(bm1, bm2 *Bitmap, area1, area2 int, delX, delY float32, maxDiffW, maxDiffH int, tab []int) (score float64, err error)
func CorrelationScoreThresholded(bm1, bm2 *Bitmap, area1, area2 int, delX, delY float32, maxDiffW, maxDiffH int, tab, downcount []int, scoreThreshold float32) (bool, error)
func HausTest(p1, p2, p3, p4 *Bitmap, delX, delY float32, maxDiffW, maxDiffH int) (bool, error)
func MakePixelCentroidTab8() []int
func MakePixelSumTab8() []int
func RankHausTest(p1, p2, p3, p4 *Bitmap, delX, delY float32, maxDiffW, maxDiffH, area1, area3 int, rank float32, tab8 []int) (match bool, err error)
func RasterOperation(dest *Bitmap, dx, dy, dw, dh int, op RasterOperator, src *Bitmap, sx, sy int) error
func Rect(x, y, w, h int) (*image.Rectangle, error)
func TstAddSymbol(t *testing.T, bms *Bitmaps, sym *Bitmap, x *int, y int, space int)
func TstFrameBitmapData() []byte
func TstImageBitmapData() []byte
func TstImageBitmapInverseData() []byte
func TstWriteSymbols(t *testing.T, bms *Bitmaps, src *Bitmap)
type Bitmap
    func Copy(d, s *Bitmap) (*Bitmap, error)
    func Dilate(d *Bitmap, s *Bitmap, sel *Selection) (*Bitmap, error)
    func DilateBrick(d, s *Bitmap, hSize, vSize int) (*Bitmap, error)
    func Extract(roi image.Rectangle, src *Bitmap) (*Bitmap, error)
    func MorphSequence(src *Bitmap, sequence ...MorphProcess) (*Bitmap, error)
    func New(width, height int) *Bitmap
    func NewWithData(width, height int, data []byte) (*Bitmap, error)
    func NewWithUnpaddedData(width, height int, data []byte) (*Bitmap, error)
    func TstASymbol(t *testing.T) *Bitmap
    func TstCSymbol(t *testing.T) *Bitmap
    func TstDSymbol(t *testing.T, scale ...int) *Bitmap
    func TstESymbol(t *testing.T, scale ...int) *Bitmap
    func TstFrameBitmap() *Bitmap
    func TstGetScaledSymbol(t *testing.T, sm *Bitmap, scale ...int) *Bitmap
    func TstISymbol(t *testing.T, scale ...int) *Bitmap
    func TstImageBitmap() *Bitmap
    func TstNSymbol(t *testing.T, scale ...int) *Bitmap
    func TstOSymbol(t *testing.T, scale ...int) *Bitmap
    func TstPSymbol(t *testing.T) *Bitmap
    func TstRSymbol(t *testing.T, scale ...int) *Bitmap
    func TstTSymbol(t *testing.T, scale ...int) *Bitmap
    func TstVSymbol(t *testing.T, scale ...int) *Bitmap
    func TstWSymbol(t *testing.T, scale ...int) *Bitmap
    func TstWordBitmap(t *testing.T, scale ...int) *Bitmap
    func TstWordBitmapWithSpaces(t *testing.T, scale ...int) *Bitmap
    func (b *Bitmap) AddBorder(borderSize, val int) (*Bitmap, error)
    func (b *Bitmap) AddBorderGeneral(left, right, top, bot int, val int) (*Bitmap, error)
    func (b *Bitmap) And(s *Bitmap) (d *Bitmap, err error)
    func (b *Bitmap) ClipRectangle(box *image.Rectangle) (d *Bitmap, boxC *image.Rectangle, err error)
    func (b *Bitmap) ConnComponents(bms *Bitmaps, connectivity int) (boxa *Boxes, err error)
    func (b *Bitmap) Copy() *Bitmap
    func (b *Bitmap) CountPixels() int
    func (b *Bitmap) CreateTemplate() *Bitmap
    func (b *Bitmap) Equals(s *Bitmap) bool
    func (b *Bitmap) Equivalent(s *Bitmap) bool
    func (b *Bitmap) GetBitOffset(x int) int
    func (b *Bitmap) GetByte(index int) (byte, error)
    func (b *Bitmap) GetByteIndex(x, y int) int
    func (b *Bitmap) GetChocolateData() []byte
    func (b *Bitmap) GetComponents(components Component, maxWidth, maxHeight int) (bitmaps *Bitmaps, boxes *Boxes, err error)
    func (b *Bitmap) GetPixel(x, y int) bool
    func (b *Bitmap) GetUnpaddedData() ([]byte, error)
    func (b *Bitmap) GetVanillaData() []byte
    func (b *Bitmap) InverseData()
    func (b *Bitmap) RasterOperation(dx, dy, dw, dh int, op RasterOperator, src *Bitmap, sx, sy int) error
    func (b *Bitmap) RemoveBorder(borderSize int) (*Bitmap, error)
    func (b *Bitmap) RemoveBorderGeneral(left, right, top, bot int) (*Bitmap, error)
    func (b *Bitmap) SetByte(index int, v byte) error
    func (b *Bitmap) SetDefaultPixel()
    func (b *Bitmap) SetPadBits(value int)
    func (b *Bitmap) SetPixel(x, y int, pixel byte) error
    func (b *Bitmap) SizesEqual(s *Bitmap) bool
    func (b *Bitmap) String() string
    func (b *Bitmap) ThresholdPixelSum(thresh int, tab8 []int) (above bool, err error)
    func (b *Bitmap) ToImage() image.Image
    func (b *Bitmap) Zero() bool
type Bitmaps
    func (b *Bitmaps) AddBitmap(bm *Bitmap)
    func (b *Bitmaps) AddBox(box *image.Rectangle)
    func (b *Bitmaps) ClipToBitmap(s *Bitmap) (*Bitmaps, error)
    func (b *Bitmaps) CountPixels() *basic.NumSlice
    func (b *Bitmaps) GetBitmap(i int) (*Bitmap, error)
    func (b *Bitmaps) GetBox(i int) (*image.Rectangle, error)
    func (b *Bitmaps) GroupByHeight() (*BitmapsArray, error)
    func (b *Bitmaps) GroupByWidth() (*BitmapsArray, error)
    func (b *Bitmaps) HeightSorter() func(i, j int) bool
    func (b *Bitmaps) SelectByIndexes(idx []int) (*Bitmaps, error)
    func (b *Bitmaps) SelectBySize(width, height int, tp LocationFilter, relation SizeComparison) (d *Bitmaps, err error)
    func (b *Bitmaps) Size() int
    func (b *Bitmaps) SortByHeight()
    func (b *Bitmaps) SortByWidth()
    func (b *Bitmaps) String() string
    func (b *Bitmaps) WidthSorter() func(i, j int) bool
type BitmapsArray
    func (b *BitmapsArray) AddBitmaps(bm *Bitmaps)
    func (b *BitmapsArray) AddBox(box *image.Rectangle)
    func (b *BitmapsArray) GetBitmaps(i int) (*Bitmaps, error)
    func (b *BitmapsArray) GetBox(i int) (*image.Rectangle, error)
type BoundaryCondition
type Boxes
    func (b *Boxes) Add(box *image.Rectangle) error
    func (b *Boxes) Get(i int) (*image.Rectangle, error)
    func (b *Boxes) SelectBySize(width, height int, tp LocationFilter, relation SizeComparison) (result *Boxes, err error)
type ClassedPoints
    func NewClassedPoints(points *Points, classes basic.IntSlice) (*ClassedPoints, error)
    func (c *ClassedPoints) GetIntXByClass(i int) (int, error)
    func (c *ClassedPoints) GetIntYByClass(i int) (int, error)
    func (c *ClassedPoints) GroupByY() ([]*ClassedPoints, error)
    func (c *ClassedPoints) Len() int
    func (c *ClassedPoints) Less(i, j int) bool
    func (c *ClassedPoints) SortByX()
    func (c *ClassedPoints) SortByY()
    func (c *ClassedPoints) Swap(i, j int)
    func (c *ClassedPoints) XAtIndex(i int) float32
    func (c *ClassedPoints) YAtIndex(i int) float32
type Color
type CombinationOperator
    func (c CombinationOperator) String() string
type Component
type Getter
type LocationFilter
type MorphOperation
type MorphProcess
type Point
    func Centroid(bm *Bitmap, centTab, sumTab []int) (Point, error)
type Points
    func Centroids(bms []*Bitmap) (*Points, error)
    func (p *Points) Add(pt *Points) error
    func (p *Points) AddPoint(x, y float32)
    func (p Points) Get(i int) (Point, error)
    func (p Points) GetGeometry(i int) (x, y float32, err error)
    func (p Points) GetIntX(i int) (int, error)
    func (p Points) GetIntY(i int) (int, error)
    func (p Points) Size() int
    func (p Points) XSorter() func(i, j int) bool
    func (p Points) YSorter() func(i, j int) bool
type RasterOperator
type Selection
    func SelCreateBrick(h, w int, cy, cx int, tp SelectionValue) *Selection
type SelectionValue
type SizeComparison
type SizeSelection

Package files

bin-expand.go bin-reduce.go bitmap.go blit.go boxes.go color.go combine.go components.go correlation.go doc.go interfaces.go location.go morph.go operators.go points.go raster.go seed-fill.go selection.go slices.go testhelpers.go

func Blit

func Blit(src *Bitmap, dst *Bitmap, x, y int, op CombinationOperator) error

Blit blits the source Bitmap 'src' into Destination bitmap: 'dst' on the provided 'x' and 'y' coordinates with respect to the combination operator 'op'.

func ClipBoxToRectangle

func ClipBoxToRectangle(box *image.Rectangle, wi, hi int) (out *image.Rectangle, err error)

ClipBoxToRectangle clips the image.Rectangle 'box' for the provided wi, hi which are rectangle representing image. The UL corner of the 'box' is assumed to be at (0,0) and LR at ('wi' - 1, 'hi' - 1)

func CombineBytes

func CombineBytes(oldByte, newByte byte, op CombinationOperator) byte

CombineBytes combines the provided bytes with respect to the CombinationOperator.

func CorrelationScore

func CorrelationScore(bm1, bm2 *Bitmap, area1, area2 int, delX, delY float32, maxDiffW, maxDiffH int, tab []int) (score float64, err error)

CorrelationScore computes the correlation score between the bitmaps: 'bm1' and 'bm2'. The correlation score is the ratio of the square of the number of pixels AND of the two bitmaps to the product of the number of ON pixels in each.

func CorrelationScoreSimple

func CorrelationScoreSimple(bm1, bm2 *Bitmap, area1, area2 int, delX, delY float32, maxDiffW, maxDiffH int, tab []int) (score float64, err error)

CorrelationScoreSimple computes the correlation score value which should be the same as the result of the 'CorrelationScore' function. This function uses raster operations and is about 2-3x slower. This function makes it easier to understand how is the correlation computed.

func CorrelationScoreThresholded

func CorrelationScoreThresholded(bm1, bm2 *Bitmap, area1, area2 int, delX, delY float32, maxDiffW, maxDiffH int, tab, downcount []int, scoreThreshold float32) (bool, error)

CorrelationScoreThresholded checks whether the correlation score is >= scoreThreshold. 'area1' - number of 'ON' pixels in 'bm1'. 'area2' - number of 'ON' pixels in 'bm2'. 'delX' - x comp of centroid difference. 'delY' - y comp of centroid difference. 'maxDiffW' - max width difference between 'bm1' and 'bm2'. 'maxDiffH' - max height difference between 'bm1' and 'bm2'. 'tab' - is a sum tab for the and byte (created by MakeSumTab8 function). 'downcount' - is the number of 'ON' pixels below each row of bitmap 'bm1'. 'score_threshold' - is the correlation score that the bitmaps should have at least to return false.

func HausTest

func HausTest(p1, p2, p3, p4 *Bitmap, delX, delY float32, maxDiffW, maxDiffH int) (bool, error)

HausTest does the Hausdorff 2-way check for the provided bitmaps. Parameters:

	p1			- new not dilated bitmap
	p2			- new dilated bitmap
 p3			- exemplar not dilated bitmap
	p4			- exemplar dilated bitmap
	delX, delY	- component centroid difference for 'x' and 'y' coordinates.
	maxDiffW	- maximum width difference of 'p1' and 'p2'
	maxDiffH	- maximum height difference of 'p1' and 'p2'

The centroid difference is used to align two images to the nearest integer for each check. It checks if the dilated image of one contains all the pixels of the undilated image of the other.

func MakePixelCentroidTab8

func MakePixelCentroidTab8() []int

MakePixelCentroidTab8 creates table of integers gives the centroid weight of the 1 bits in the 8 bit index.

func MakePixelSumTab8

func MakePixelSumTab8() []int

MakePixelSumTab8 creates table of integers that gives the number of 1 bits in the 8 bit index.

func RankHausTest

func RankHausTest(p1, p2, p3, p4 *Bitmap, delX, delY float32, maxDiffW, maxDiffH, area1, area3 int, rank float32, tab8 []int) (match bool, err error)

RankHausTest does the test of the Hausdorff ranked check. Parameters:

p1			- new bitmap, not dilated
p2			- new bitmap, dilated
p3			-u exemplar bitmap, not dilated
p4			- exemplar bitmap, dilated
delX, delY	- component centroid difference for 'x' and 'y' coordinates
maxDiffW	- maximum Width difference of 'p1' and 'p2'
maxDiffH	- maximum Height difference of 'p1' and 'p2'
area1		- 'ON' - fg - pixels area of the 'p1' bitmap
area3		- 'ON' - fg - pixels area of the 'p3' bitmap
rank		- rank value of the test
tab8		- table of the pixel sums for a single byte.

The 'rank' value is being converted to a number of pixels by multiplication with the number of undilated images. The centroid difference is used for alignment of the images. The rank Hausdorff checks if dilated image of one contains the rank fraction pixels of the undilated image of the other in both directions.

func RasterOperation

func RasterOperation(dest *Bitmap, dx, dy, dw, dh int, op RasterOperator, src *Bitmap, sx, sy int) error

RasterOperation does the rastering operation on the provided 'dest' bitmap. There are 18 operations, described by the 'op' RasterOperator. The PixDst is a no-op.

PixClr, PixSet, PixNotPixDst operate only on the 'dest'.

The other 14 involve both 'src' and 'dest' bitmaps and depends on the bit values of either just the src or the both 'src' and 'dest'. Out of these 14 operators there are only 12 unique logical combinations. ~(s) ^ d) == ~(s ^ d) == s ^ ~(d). Parameters:

'dest'	 	'dest' bitmap
'dx'		x val of UL corner of 'dest' bitmap
'dy'		y val of UL corner of 'dest' bitmap
'dw'		is the width of the operational rectangle on the bitmap 'dest'
'dh'		is the height of the operational rectangle on the bitmap 'dest'
'op'		raster operator code
'src'	 	'src' bitmap
'sx'		x val of UL corner of 'src' bitmap
'sy'		y val of UL corner of 'src' bitmap

func Rect

func Rect(x, y, w, h int) (*image.Rectangle, error)

Rect create new rectangle box with the negative coordinates rules.

func TstAddSymbol

func TstAddSymbol(t *testing.T, bms *Bitmaps, sym *Bitmap, x *int, y int, space int)

TstAddSymbol is a helper function that adds 'sym' at the 'x' and 'y' position.

func TstFrameBitmapData

func TstFrameBitmapData() []byte

TstFrameBitmapData gets the test frame bitmap data.

func TstImageBitmapData

func TstImageBitmapData() []byte

TstImageBitmapData gets the test image bitmap data.

func TstImageBitmapInverseData

func TstImageBitmapInverseData() []byte

TstImageBitmapInverseData gets the test image bitmap inverse data.

func TstWriteSymbols

func TstWriteSymbols(t *testing.T, bms *Bitmaps, src *Bitmap)

TstWriteSymbols is a helper function to write given symbols from bitmaps into 'src' bitmap at the given 'x.

type Bitmap

Bitmap is the jbig2 bitmap representation.

type Bitmap struct {
    // Width and Height represents bitmap dimensions.
    Width, Height int
    // BitmapNumber is the bitmap's id number.
    BitmapNumber int
    // RowStride is the number of bytes set per row.
    RowStride int
    // Data saves the bits data for the bitmap.
    Data []byte
    // Color is the bitmap's color interpretation.
    Color Color

    // Special instructions for I/O.
    Special int

    // Text string associated with the pix.
    Text string

    // The XResolution and YResolution are the
    // image resolution parameters at width and height.
    XResolution, YResolution int
}

func Copy

func Copy(d, s *Bitmap) (*Bitmap, error)

Copy the bitmap 's' into bitmap 'd'. If 'd' is nil, it is created by the function.

func Dilate

func Dilate(d *Bitmap, s *Bitmap, sel *Selection) (*Bitmap, error)

Dilate the source bitmap 's' using hits in the selection 'sel'. The 'd' destination bitmap is optional. The following cases are possible:

'd' == 's' 	the function writes the result back to 'src'.
'd' == nil 	the function creates new bitmap and writes the result to it.
'd' != 's' 	puts the results into existing 'd'.

func DilateBrick

func DilateBrick(d, s *Bitmap, hSize, vSize int) (*Bitmap, error)

DilateBrick dilate with all sel being hit.

func Extract

func Extract(roi image.Rectangle, src *Bitmap) (*Bitmap, error)

Extract extracts the rectangle of given size from the source 'src' Bitmap.

func MorphSequence

func MorphSequence(src *Bitmap, sequence ...MorphProcess) (*Bitmap, error)

MorphSequence does the morph processes over the 'src' Bitmap with the provided sequence.

func New

func New(width, height int) *Bitmap

New creates new bitmap with the parameters as provided in the arguments.

func NewWithData

func NewWithData(width, height int, data []byte) (*Bitmap, error)

NewWithData creates new bitmap with the provided 'width', 'height' and the byte slice 'data'.

func NewWithUnpaddedData

func NewWithUnpaddedData(width, height int, data []byte) (*Bitmap, error)

NewWithUnpaddedData creates new bitmap with provided 'width', 'height' and the byte slice 'data' that doesn't contains paddings on the last byte of each row. This function adds the padding to the bitmap data.

func TstASymbol

func TstASymbol(t *testing.T) *Bitmap

TstASymbol is a helper function to get 'A' symbol.

func TstCSymbol

func TstCSymbol(t *testing.T) *Bitmap

TstCSymbol is a helper function to get 'C' symbol.

func TstDSymbol

func TstDSymbol(t *testing.T, scale ...int) *Bitmap

TstDSymbol is a helper function to get 'D' symbol.

func TstESymbol

func TstESymbol(t *testing.T, scale ...int) *Bitmap

TstESymbol is a helper function to write 'E' letter.

func TstFrameBitmap

func TstFrameBitmap() *Bitmap

TstFrameBitmap gets the test frame bitmap.

func TstGetScaledSymbol

func TstGetScaledSymbol(t *testing.T, sm *Bitmap, scale ...int) *Bitmap

TstGetScaledSymbol is a helper function to get scaled bitmap.

func TstISymbol

func TstISymbol(t *testing.T, scale ...int) *Bitmap

TstISymbol is a helper function to get 'I' symbol.

func TstImageBitmap

func TstImageBitmap() *Bitmap

TstImageBitmap gets the test image bitmap.

func TstNSymbol

func TstNSymbol(t *testing.T, scale ...int) *Bitmap

TstNSymbol is a helper function to write 'N' letter.

func TstOSymbol

func TstOSymbol(t *testing.T, scale ...int) *Bitmap

TstOSymbol is a helper function to get 'O' symbol.

func TstPSymbol

func TstPSymbol(t *testing.T) *Bitmap

TstPSymbol is a helper function to get 'P' symbol.

func TstRSymbol

func TstRSymbol(t *testing.T, scale ...int) *Bitmap

TstRSymbol is a helper function to write 'R' letter.

func TstTSymbol

func TstTSymbol(t *testing.T, scale ...int) *Bitmap

TstTSymbol is a helper function to write 'T' letter

func TstVSymbol

func TstVSymbol(t *testing.T, scale ...int) *Bitmap

TstVSymbol is a helper function to get 'V' symbol.

func TstWSymbol

func TstWSymbol(t *testing.T, scale ...int) *Bitmap

TstWSymbol is a helper function to write 'W' letter.

func TstWordBitmap

func TstWordBitmap(t *testing.T, scale ...int) *Bitmap

TstWordBitmap creates a bitmap with the words like: DO IT NOW OR NEVER without any boundaries.

func TstWordBitmapWithSpaces

func TstWordBitmapWithSpaces(t *testing.T, scale ...int) *Bitmap

TstWordBitmapWithSpaces gets no space from the top, bottom, left and right edge.

func (*Bitmap) AddBorder

func (b *Bitmap) AddBorder(borderSize, val int) (*Bitmap, error)

AddBorder creates a new bitmap with the border of size 'borderSize'. If the 'borderSize' is different than zero the resultant bitmap dimensions would increase by width += 2* borderSize, height += 2*borderSize. The value 'val' represents the binary bit 'value' of the border - '0' and '1'

func (*Bitmap) AddBorderGeneral

func (b *Bitmap) AddBorderGeneral(left, right, top, bot int, val int) (*Bitmap, error)

AddBorderGeneral creates new bitmap on the base of the bitmap 'b' with the border of size for each side 'left','right','top','bot'. The 'val' sets the border white (0) or black (1).

func (*Bitmap) And

func (b *Bitmap) And(s *Bitmap) (d *Bitmap, err error)

And does the raster operation 'AND' on the provided bitmaps 'b' and 's'.

func (*Bitmap) ClipRectangle

func (b *Bitmap) ClipRectangle(box *image.Rectangle) (d *Bitmap, boxC *image.Rectangle, err error)

ClipRectangle clips the 'b' Bitmap to the 'box' with relatively defined coordinates. If the box is not contained within the pix the 'box' is clipped to the 'b' size.

func (*Bitmap) ConnComponents

func (b *Bitmap) ConnComponents(bms *Bitmaps, connectivity int) (boxa *Boxes, err error)

ConnComponents is a top level call for decomposing the bitmap 'b' by creating components. Each component is a part of bitmap where each pixel is connected with at least one neighbor. The 'connectivity' is the number of possible directions where the pixel neighbors could be found. The only possible values it could take is 4 and 8. The connectivity 4 checks the neighbors at top, bottom, left and right, where connectivity 8 checks also upper left, upper right, bottom left and bottom right. The 'bms' is an optional argument. If it's not nil the components created by the function are added to the 'bms' Bitmaps. It sets up 2 temporary bitmaps and for each connected components that is located in raster order, it erase the c.c from one bitmap then uses the bounding box to extract component from the 'two' bitmap using XOR operation, and finally erase the component from the second bm. Returns bounding boxes of the components. If the bitmaps 'bms' are provided the boxes are added to it's Boxes variable.

func (*Bitmap) Copy

func (b *Bitmap) Copy() *Bitmap

Copy gets a copy of the 'b' bitmap.

func (*Bitmap) CountPixels

func (b *Bitmap) CountPixels() int

CountPixels counts the pixels for the bitmap 'b'.

func (*Bitmap) CreateTemplate

func (b *Bitmap) CreateTemplate() *Bitmap

CreateTemplate creates a copy template bitmap on the base of the bitmap 'b'. A template has the same parameters as bitmap 'b', but contains empty Data.

func (*Bitmap) Equals

func (b *Bitmap) Equals(s *Bitmap) bool

Equals checks if all the pixels in the 'b' bitmap are equals to the 's' bitmap.

func (*Bitmap) Equivalent

func (b *Bitmap) Equivalent(s *Bitmap) bool

Equivalent checks if the bitmaps 'b' and 's' are equivalent from the visual point of view.

func (*Bitmap) GetBitOffset

func (b *Bitmap) GetBitOffset(x int) int

GetBitOffset gets the bit offset at the 'x' coordinate.

func (*Bitmap) GetByte

func (b *Bitmap) GetByte(index int) (byte, error)

GetByte gets and returns the byte at given 'index'.

func (*Bitmap) GetByteIndex

func (b *Bitmap) GetByteIndex(x, y int) int

GetByteIndex gets the byte index from the bitmap at coordinates 'x','y'.

func (*Bitmap) GetChocolateData

func (b *Bitmap) GetChocolateData() []byte

GetChocolateData gets bitmap data as a byte slice with Chocolate bit interpretation. 'Chocolate' data is the bit interpretation where the 0'th bit means white and the 1'th bit means black. The naming convention based on the: `https://en.wikipedia.org/wiki/Binary_image#Interpretation` page.

func (*Bitmap) GetComponents

func (b *Bitmap) GetComponents(components Component, maxWidth, maxHeight int) (bitmaps *Bitmaps, boxes *Boxes, err error)

GetComponents determine the bitmap 'b' image components.

func (*Bitmap) GetPixel

func (b *Bitmap) GetPixel(x, y int) bool

GetPixel gets the pixel value at the coordinates 'x', 'y'.

func (*Bitmap) GetUnpaddedData

func (b *Bitmap) GetUnpaddedData() ([]byte, error)

GetUnpaddedData gets the data without row stride padding. The unpadded data contains bitmap.Height * bitmap.Width bits with optional last byte padding.

func (*Bitmap) GetVanillaData

func (b *Bitmap) GetVanillaData() []byte

GetVanillaData gets bitmap data as a byte slice with Vanilla bit interpretation. 'Vanilla' is the bit interpretation where the 0'th bit means black and 1'th bit means white. The naming convention based on the `https://en.wikipedia.org/wiki/Binary_image#Interpretation` page.

func (*Bitmap) InverseData

func (b *Bitmap) InverseData()

InverseData inverses the data color interpretation.

func (*Bitmap) RasterOperation

func (b *Bitmap) RasterOperation(dx, dy, dw, dh int, op RasterOperator, src *Bitmap, sx, sy int) error

RasterOperation has the same function as the RasterOperation package function, where the 'b' bitmap is the 'dest'.

func (*Bitmap) RemoveBorder

func (b *Bitmap) RemoveBorder(borderSize int) (*Bitmap, error)

RemoveBorder create a new bitmap based on the 'b' with removed border of size 'borderSize'.

func (*Bitmap) RemoveBorderGeneral

func (b *Bitmap) RemoveBorderGeneral(left, right, top, bot int) (*Bitmap, error)

RemoveBorderGeneral creates a new bitmap with removed border of size 'left', 'right', 'top', 'bot'. The resultant bitmap dimensions would be smaller by the value of border size.

func (*Bitmap) SetByte

func (b *Bitmap) SetByte(index int, v byte) error

SetByte sets the byte at 'index' with value 'v'. Returns an error if the index is out of range.

func (*Bitmap) SetDefaultPixel

func (b *Bitmap) SetDefaultPixel()

SetDefaultPixel sets all bits within bitmap to '1'.

func (*Bitmap) SetPadBits

func (b *Bitmap) SetPadBits(value int)

SetPadBits sets the pad bits for the current bitmap.

func (*Bitmap) SetPixel

func (b *Bitmap) SetPixel(x, y int, pixel byte) error

SetPixel sets the pixel at 'x', 'y' coordinates with the value of 'pixel'. Returns an error if the index is out of range.

func (*Bitmap) SizesEqual

func (b *Bitmap) SizesEqual(s *Bitmap) bool

SizesEqual checks if the bitmaps are of the same size.

func (*Bitmap) String

func (b *Bitmap) String() string

String implements the Stringer interface.

func (*Bitmap) ThresholdPixelSum

func (b *Bitmap) ThresholdPixelSum(thresh int, tab8 []int) (above bool, err error)

ThresholdPixelSum checks if the number of the 'ON' pixels is above the provided 'thresh' threshold. If the on pixel count > thresh the function returns quckly.

func (*Bitmap) ToImage

func (b *Bitmap) ToImage() image.Image

ToImage gets the bitmap data and store in the image.Image.

func (*Bitmap) Zero

func (b *Bitmap) Zero() bool

Zero check if there is no 'ONE' pixels.

type Bitmaps

Bitmaps is the structure that contains slice of the bitmaps and the bounding boxes. It allows to safely get the Bitmap and the bounding boxes.

type Bitmaps struct {
    Values []*Bitmap
    Boxes  []*image.Rectangle
}

func (*Bitmaps) AddBitmap

func (b *Bitmaps) AddBitmap(bm *Bitmap)

AddBitmap adds the bitmap 'bm' to the 'b' Bitmaps Values.

func (*Bitmaps) AddBox

func (b *Bitmaps) AddBox(box *image.Rectangle)

AddBox adds the 'box' to the 'b' Bitmaps.

func (*Bitmaps) ClipToBitmap

func (b *Bitmaps) ClipToBitmap(s *Bitmap) (*Bitmaps, error)

ClipToBitmap returns a Bitmaps where each Bitmap is 'AND'ed with with the associated region stored in box with the 's' Bitmap.

func (*Bitmaps) CountPixels

func (b *Bitmaps) CountPixels() *basic.NumSlice

CountPixels counts the pixels for all the bitmaps and stores into *basic.NumSlice.

func (*Bitmaps) GetBitmap

func (b *Bitmaps) GetBitmap(i int) (*Bitmap, error)

GetBitmap gets the bitmap at the 'i' index. If the index is out of possible range the function returns error.

func (*Bitmaps) GetBox

func (b *Bitmaps) GetBox(i int) (*image.Rectangle, error)

GetBox gets the Box at the 'i' index. If the index is out of range the function returns error.

func (*Bitmaps) GroupByHeight

func (b *Bitmaps) GroupByHeight() (*BitmapsArray, error)

GroupByHeight groups bitmaps by height sorted from the lowest to the highest.

func (*Bitmaps) GroupByWidth

func (b *Bitmaps) GroupByWidth() (*BitmapsArray, error)

GroupByWidth groups bitmaps by height sorted from the lowest to the highest.

func (*Bitmaps) HeightSorter

func (b *Bitmaps) HeightSorter() func(i, j int) bool

HeightSorter returns sorting function based on the bitmaps height.

func (*Bitmaps) SelectByIndexes

func (b *Bitmaps) SelectByIndexes(idx []int) (*Bitmaps, error)

SelectByIndexes selects bitmaps by provided indexes 'idx'.

func (*Bitmaps) SelectBySize

func (b *Bitmaps) SelectBySize(width, height int, tp LocationFilter, relation SizeComparison) (d *Bitmaps, err error)

SelectBySize selects provided bitmaps by provided 'width', 'height' location filter 'tp' and size comparison 'relation. Returns 'b' bitmap if it's empty or all the bitmaps matches the pattern.

func (*Bitmaps) Size

func (b *Bitmaps) Size() int

Size returns bitmaps size.

func (*Bitmaps) SortByHeight

func (b *Bitmaps) SortByHeight()

SortByHeight sorts the bitmaps by height.

func (*Bitmaps) SortByWidth

func (b *Bitmaps) SortByWidth()

SortByWidth sorts bitmaps by width.

func (*Bitmaps) String

func (b *Bitmaps) String() string

func (*Bitmaps) WidthSorter

func (b *Bitmaps) WidthSorter() func(i, j int) bool

WidthSorter returns the sorting function based on the bitmaps width.

type BitmapsArray

BitmapsArray is the struct that contains slice of the 'Bitmaps', with the bounding boxes around each 'Bitmaps'.

type BitmapsArray struct {
    Values []*Bitmaps
    Boxes  []*image.Rectangle
}

func (*BitmapsArray) AddBitmaps

func (b *BitmapsArray) AddBitmaps(bm *Bitmaps)

AddBitmaps adds the 'bm' Bitmaps to the 'b'.Values.

func (*BitmapsArray) AddBox

func (b *BitmapsArray) AddBox(box *image.Rectangle)

AddBox adds the 'box' to the 'b' Boxes.

func (*BitmapsArray) GetBitmaps

func (b *BitmapsArray) GetBitmaps(i int) (*Bitmaps, error)

GetBitmaps gets the 'Bitmaps' at the 'i' position. Returns error if the index is out of range.

func (*BitmapsArray) GetBox

func (b *BitmapsArray) GetBox(i int) (*image.Rectangle, error)

GetBox gets the boundary box at 'i' position. Returns error if the index is out of range.

type BoundaryCondition

BoundaryCondition is the global enum variable used to define morph operation boundary conditions. More information about the definition could be found at: http://www.leptonica.org/binary-morphology.html#boundary-conditions

type BoundaryCondition int
const (
    // AsymmetricMorphBC defines the asymmetric boundary condition for morph functions.
    AsymmetricMorphBC BoundaryCondition = iota
    // SymmetricMorphBC defines the symmetric boundary condition for morph funcftions.
    SymmetricMorphBC
)

MorphBC defines current morph boundary condition used by the morph functions. By default it is set to 'AsymetricMorphBC'.

var MorphBC BoundaryCondition

type Boxes

Boxes is the wrapper over the slice of image.Rectangles that allows to get and add the image.Rectangle safely.

type Boxes []*image.Rectangle

func (*Boxes) Add

func (b *Boxes) Add(box *image.Rectangle) error

Add adds the 'box' to the provided 'Boxes'.

func (*Boxes) Get

func (b *Boxes) Get(i int) (*image.Rectangle, error)

Get gets the box at 'i' index. Returns error if the index 'i' is out of range.

func (*Boxes) SelectBySize

func (b *Boxes) SelectBySize(width, height int, tp LocationFilter, relation SizeComparison) (result *Boxes, err error)

SelectBySize select sthe boxes 'b' by provided 'width' 'height', location filter 'tp' and 'relation'. If nothing changes the function returns the boxes 'b' by itself.

type ClassedPoints

ClassedPoints is the wrapper that contains both points and integer slice, where each index in point relates to the index of int slice. Even though the type implements sort.Interface, don't use it directly - as this would panic. Use SortByX, or SortByY function.

type ClassedPoints struct {
    *Points
    basic.IntSlice
    // contains filtered or unexported fields
}

func NewClassedPoints

func NewClassedPoints(points *Points, classes basic.IntSlice) (*ClassedPoints, error)

NewClassedPoints creates and validates PointsBitmaps based on provided 'points' and 'classes'. The classes contains id's of the classes related to the index of the 'points'.

func (*ClassedPoints) GetIntXByClass

func (c *ClassedPoints) GetIntXByClass(i int) (int, error)

GetIntXByClass gets the integer of point.Y by the index of the 'IntSlice'.

func (*ClassedPoints) GetIntYByClass

func (c *ClassedPoints) GetIntYByClass(i int) (int, error)

GetIntYByClass gets the integer of point.Y by the index of the 'IntSlice'.

func (*ClassedPoints) GroupByY

func (c *ClassedPoints) GroupByY() ([]*ClassedPoints, error)

GroupByY groups provided intSlice into ClassedPoints based on their 'Y'.

func (*ClassedPoints) Len

func (c *ClassedPoints) Len() int

Len implements sort.Interface interface.

func (*ClassedPoints) Less

func (c *ClassedPoints) Less(i, j int) bool

Less implements sort.Interface.

func (*ClassedPoints) SortByX

func (c *ClassedPoints) SortByX()

SortByX sorts classed points by x coordinate.

func (*ClassedPoints) SortByY

func (c *ClassedPoints) SortByY()

SortByY sorts classed points by y coordinate.

func (*ClassedPoints) Swap

func (c *ClassedPoints) Swap(i, j int)

Swap implements sort.Interface interface.

func (*ClassedPoints) XAtIndex

func (c *ClassedPoints) XAtIndex(i int) float32

XAtIndex gets the 'x' coordinate from the points where the 'i' is the index of the IntSlice.

func (*ClassedPoints) YAtIndex

func (c *ClassedPoints) YAtIndex(i int) float32

YAtIndex gets the 'y' coordinate from the points where the 'i' is the index of the IntSlice.

type Color

Color is the jbig2 color interpretation enum. The naming convention taken from 'https://en.wikipedia.org/wiki/Binary_image#Interpretation'.

type Color int
const (
    // Vanilla is the bit interpretation where the 1'th bit means white and the 0'th bit means black.
    Vanilla Color = iota
    // Chocolate is the bit interpretation where the 0'th bit means white and the 1'th bit means black.
    Chocolate
)

type CombinationOperator

CombinationOperator is the operator used for combining the bitmaps.

type CombinationOperator int
const (
    // CmbOpOr is the 'OR' CombinationOperator.
    CmbOpOr CombinationOperator = iota
    // CmbOpAnd is the 'AND' CombinationOperator.
    CmbOpAnd
    // CmbOpXor is the 'XOR' CombinationOperator.
    CmbOpXor
    // CmbOpXNor is the 'XNOR' CombinationOperator.
    CmbOpXNor
    // CmbOpReplace is the 'REPLACE' CombinationOperator.
    CmbOpReplace
    // CmbOpNot is the 'NOT' CombinationOperator.
    CmbOpNot
)

func (CombinationOperator) String

func (c CombinationOperator) String() string

String implements Stringer interface.

type Component

Component is the component definition enum.

type Component int

Component enum definitions.

const (
    ComponentConn Component = iota
    ComponentCharacters
    ComponentWords
)

type Getter

Getter interface used for getting the Bitmap.

type Getter interface {
    GetBitmap() *Bitmap
}

type LocationFilter

LocationFilter is predefined enum wrapper used for selection of boxes and bitmaps

type LocationFilter int
const (

    // LocSelectWidth is the location filter where the width must satisfy constraint.
    LocSelectWidth LocationFilter
    // LocSelectHeight is the location filter where the height must satisfy constarint.
    LocSelectHeight
    // LocSelectXVal is the location filter where the 'x' value must satisfy constraint.
    LocSelectXVal
    // LocSelectYVal is the location filter where the 'y' value must satisfy constraint.
    LocSelectYVal
    // LocSelectIfEither is the location filter where either width or height can satisfy constraint.
    LocSelectIfEither
    // LocSelectIfBoth is the location filter where both width and height must satisfy constraint.
    LocSelectIfBoth
)

type MorphOperation

MorphOperation is an enum that wraps the morph operations.

type MorphOperation int

Enum morph operations.

const (
    MopDilation MorphOperation = iota
    MopErosion
    MopOpening
    MopClosing
    MopRankBinaryReduction
    MopReplicativeBinaryExpansion
    MopAddBorder
)

type MorphProcess

MorphProcess is the combination of the morph operator with it's values.

type MorphProcess struct {
    Operation MorphOperation
    Arguments []int
}

type Point

Point is the basic structure that contains x, y float32 values. In compare with image.Point the x and y are floats not integers.

type Point struct {
    X, Y float32
}

func Centroid

func Centroid(bm *Bitmap, centTab, sumTab []int) (Point, error)

Centroid gets the centroid of the provided 'bm' bitmap. The parameters 'centTab' and 'sumTab' are optional. 'centTab' is a table for finding centroids. 'sumTab' is a table for finding pixel sums. The centorid point is relative to the UL corner.

type Points

Points is the slice of the float Points that has panic safe methods for getting and adding new Points.

type Points []Point

func Centroids

func Centroids(bms []*Bitmap) (*Points, error)

Centroids gets the centroids relative to the UL corner of each pix for the provided bitmaps.

func (*Points) Add

func (p *Points) Add(pt *Points) error

Add adds the points 'pt' to the slice of points.

func (*Points) AddPoint

func (p *Points) AddPoint(x, y float32)

AddPoint adds the Point{'x', 'y'} to the 'p' Points.

func (Points) Get

func (p Points) Get(i int) (Point, error)

Get gets the point at 'i' index. Returns error if the 'i' index is out of range.

func (Points) GetGeometry

func (p Points) GetGeometry(i int) (x, y float32, err error)

GetGeometry gets the geometry 'x' and 'y' of the point at the 'i' index. Returns error if the index is out of range.

func (Points) GetIntX

func (p Points) GetIntX(i int) (int, error)

GetIntX gets integer value of x coordinate for the point at index 'i'.

func (Points) GetIntY

func (p Points) GetIntY(i int) (int, error)

GetIntY gets integer value of y coordinate for the point at index 'i'.

func (Points) Size

func (p Points) Size() int

Size returns the size of the points slice.

func (Points) XSorter

func (p Points) XSorter() func(i, j int) bool

XSorter is the sorter function based on the points 'x' coordinates.

func (Points) YSorter

func (p Points) YSorter() func(i, j int) bool

YSorter is the sorter function based on the points 'y' coordinates.

type RasterOperator

RasterOperator is the raster operation flag operator. There are following raster operations:

PixClr                      	0000   0x0
PixSet                      	1111   0xf
PixSrc              s        	1100   0xc
PixDst              d        	1010   0xa
PixNotSrc		    ~s        	0011   0x3
PixNotDst		    ~d        	0101   0x5
PixSrcOrDst		    s | d       1110   0xe
PixSrcAndDst	    s & d       1000   0x8
PixSrcXorDst	    s ^ d       0110   0x6
PixNotSrcOrDst		~s | d 	    1011   0xb
PixNotSrcAndDst		~s & d		0010   0x2
PixSrcOrNotDst		s | ~d		1101   0xd
PixSrcAndNotDst		s & ~d		0100   0x4
PixNotPixSrcOrDst	~(s | d)	0001   0x1
PixNotPixSrcAndDst	~(s & d)	0111   0x7
PixNotPixSrcXorDst	~(s ^ d)	1001   0X9
type RasterOperator int

Raster operator constant definitions.

const (
    PixSrc    RasterOperator = 0xc
    PixDst    RasterOperator = 0xa
    PixNotSrc RasterOperator = 0x3
    PixNotDst RasterOperator = 0x5

    PixClr RasterOperator = 0x0
    PixSet RasterOperator = 0xf

    PixSrcOrDst        RasterOperator = 0xe
    PixSrcAndDst       RasterOperator = 0x8
    PixSrcXorDst       RasterOperator = 0x6
    PixNotSrcOrDst     RasterOperator = 0xb
    PixNotSrcAndDst    RasterOperator = 0x2
    PixSrcOrNotDst     RasterOperator = 0xd
    PixSrcAndNotDst    RasterOperator = 0x4
    PixNotPixSrcOrDst  RasterOperator = 0x1
    PixNotPixSrcAndDst RasterOperator = 0x7
    PixNotPixSrcXorDst RasterOperator = 0x9

    PixPaint    = PixSrcOrDst
    PixSubtract = PixNotSrcAndDst
    PixMask     = PixSrcAndDst
)

type Selection

Selection is the structure used for matching the bitmaps.

type Selection struct {
    Height, Width int
    // Location of the Selection origin.
    Cx, Cy int
    Name   string
    Data   [][]SelectionValue
}

func SelCreateBrick

func SelCreateBrick(h, w int, cy, cx int, tp SelectionValue) *Selection

SelCreateBrick creates a rectangular selection of all hits, misses or don't cares.

type SelectionValue

SelectionValue is the enum value used for the Selection data.

type SelectionValue int

SelectionValue enums values.

const (
    SelDontCare SelectionValue = iota
    SelHit
    SelMiss
)

type SizeComparison

SizeComparison is the predefined enum wrapper used for size comparison.

type SizeComparison int
const (

    // SizeSelectIfLT is the size comparison used to save the value if it's less than threshold.
    SizeSelectIfLT SizeComparison
    // SizeSelectIfGT is the size comparison used to save the value if it's more than threshold.
    SizeSelectIfGT
    // SizeSelectIfLTE is the size comparison used to save the value if it's less or equal to threshold.
    SizeSelectIfLTE
    // SizeSelectIfGTE is the size comparison used to save the value if it's less more or equal to threshold.
    SizeSelectIfGTE
    // SizeSelectIfEQ is the size comparison used to save the values if it's equal to threshold.
    SizeSelectIfEQ
)

type SizeSelection

SizeSelection is the predefined enum wrapper used for size selection for boxes and bitmaps.

type SizeSelection int
const (

    // SizeSelectByWidth is the size select enum used for selecting by width.
    SizeSelectByWidth SizeSelection
    // SizeSelectByHeight is the size select enum used for selecting by height.
    SizeSelectByHeight
    // SizeSelectByMaxDimension is the size select enum used for selecting by max of width and height.
    SizeSelectByMaxDimension
    // SizeSelectByArea is the size select enum used for selecting by area.
    SizeSelectByArea
    // SizeSelectByPerimeter is the size select enum used for selecting by perimeter.
    SizeSelectByPerimeter
)