![@thi.ng/geom-trace-bitmap](https://media.thi.ng/umbrella/banners-20220914/thing-geom-trace-bitmap.svg?f80a6c2d)
![Mastodon Follow](https://img.shields.io/mastodon/follow/109331703950160316?domain=https%3A%2F%2Fmastodon.thi.ng&style=social)
This project is part of the
@thi.ng/umbrella monorepo.
About
Bitmap image to hairline vector and point cloud conversions. This is a support package for @thi.ng/geom.
This package provides an extensible setup to extract user selectable
single-pixel width line segments in horizontal, vertical and diagonal (45°)
directions and/or single pixels as 2d point cloud. The main
traceBitmap()
function supports a predicate function to filter qualifying pixel values,
options to control which line orientations should be considered (incl. providing
custom ones and in which order of application), as well as a 2x3 matrix to
transform extracted points (pixel coordinates). See
TraceBitmapOpts
and example below for details.
Status
ALPHA - bleeding edge / work-in-progress
Search or submit any issues for this package
Related packages
- @thi.ng/geom-axidraw - Conversion and preparation of thi.ng/geom shapes & shape groups to/from AxiDraw pen plotter draw commands
- @thi.ng/pixel - Typedarray integer & float pixel buffers w/ customizable formats, blitting, drawing, convolution
Installation
yarn add @thi.ng/geom-trace-bitmap
ES module import:
<script type="module" src="https://cdn.skypack.dev/@thi.ng/geom-trace-bitmap"></script>
Skypack documentation
For Node.js REPL:
const geomTraceBitmap = await import("@thi.ng/geom-trace-bitmap");
Package sizes (brotli'd, pre-treeshake): ESM: 988 bytes
Dependencies
Usage examples
Several demos in this repo's
/examples
directory are using this package.
A selection:
Screenshot | Description | Live demo | Source |
---|
![](https://raw.githubusercontent.com/thi-ng/umbrella/develop/assets/examples/trace-bitmap.jpg) | Multi-layer vectorization & dithering of bitmap images | Demo | Source |
API
Generated API docs
TODO
Basic usage
For brevity, this example uses
thi.ng/pixel-io-netpbm
to load an image in PGM format. For that image format, the read()
function
returns a thi.ng/pixel
IntBuffer using the
GRAY8
pixel format...
import { asSvg, group, line, points, svgDoc } from "@thi.ng/geom";
import { traceBitmap } from "@thi.ng/geom-trace-bitmap";
import { read } from "@thi.ng/pixel-io-netpbm";
import { readFileSync, writeFileSync } from "fs";
const { lines, points: dots } = traceBitmap({
img: read(readFileSync("foo.pgm")),
select: (x) => x > 128,
dir: ["h", "v", "d1", "d2", "p"]
});
writeFileSync(
"export/trace.svg",
asSvg(
svgDoc(
{},
group({}, lines.map(([a,b]) => line(a, b))),
points(dots, { fill: "#000", stroke: "none" })
)
)
);
Authors
If this project contributes to an academic publication, please cite it as:
@misc{thing-geom-trace-bitmap,
title = "@thi.ng/geom-trace-bitmap",
author = "Karsten Schmidt",
note = "https://thi.ng/geom-trace-bitmap",
year = 2022
}
License
© 2022 - 2023 Karsten Schmidt // Apache License 2.0