slicing

package
v0.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package slicing prepares large images for OCR by cutting them into horizontal slices.

OCR engines degrade on very tall images: Apple Vision in particular downscales its input internally, so fine print on a tall page (e.g. a web page rendered to PDF) simply vanishes — measured on a 3848x17576 page, Vision found 3% of the fine-print words, versus 85% when handed just that region. Slicing restores full-resolution recognition.

Cutting is delegated to github.com/goodblaster/vertigo/slicer, which only cuts through visually blank rows, so text lines are never severed and paragraph breaks are preferred.

Callers OCR each slice independently and merge the results back into full-page coordinates using each slice's OffsetY.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadImage

func LoadImage(path string) (image.Image, error)

LoadImage decodes a PNG or JPEG image from disk.

Types

type Config

type Config struct {
	// Enabled turns slicing on. When false, SliceImage always returns the
	// whole image as a single slice.
	Enabled bool

	// HeightThreshold is the image height in pixels above which slicing
	// kicks in. Images at or below the threshold pass through untouched.
	HeightThreshold int

	// TargetHeight is the desired slice height in pixels (soft limit).
	TargetHeight int

	// MinHeight is the minimum slice height in pixels (soft limit). The
	// range between MinHeight and TargetHeight is the window searched for a
	// clean cut.
	MinHeight int
}

Config controls when and how images are sliced before OCR.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the recommended slicing configuration.

The threshold (4000px) sits between our standard test pages (2112px tall, which OCR handles fine) and the tall-page regime where Vision's internal downscaling destroys small text. Slice heights target the size range measured to OCR at full quality.

type Slice

type Slice struct {
	// Image is the strip itself. Its bounds may be offset within the parent
	// image's coordinate space; use OffsetY, not Bounds().Min.Y.
	Image image.Image

	// OffsetY is the strip's top edge in pixels from the top of the
	// original image.
	OffsetY int
}

Slice is one horizontal strip of a larger image.

func SliceImage

func SliceImage(img image.Image, cfg Config) ([]Slice, error)

SliceImage cuts img into horizontal strips per cfg. Images that are not taller than cfg.HeightThreshold (or when slicing is disabled) are returned unmodified as a single slice with OffsetY 0, so callers can use one code path for both cases.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL