Skip to main content

cut_column

Function cut_column 

Source
pub fn cut_column(crop: &GrayImage, x0: u32, ideal: u32, crop_w: u32) -> u32
Expand description

Where to end a tile that starts at x0 and may not pass ideal.

Cutting at exactly ideal lands wherever the arithmetic falls, which is usually the middle of a glyph. Both halves keep their pixels, so a coverage check still passes, but the model reads each half as a whole character and one glyph becomes two. Measured upstream on 120 drawn lines this showed up as ဗော် read back as ဗေဗိာ်.

So search backwards from ideal for a column of white. A tile may only get narrower, never wider, or it stops fitting the model window. Returns ideal unchanged when there is no gap to cut at, which is the honest outcome for a continuous script: a known-bad seam beats an overflowing tile.

Ported from monocr_onnx.segmenter.cut_column; the constants and the tie-breaking are the same, so the two produce the same cuts on the same input. The shared fixture in monocr-monorepo/shared/segmentation-fixtures is what holds them together.