architram-smart-fill-segmentation
v0.1.1
Published
Fill Segmentation
Downloads
165
Maintainers
Readme
Smart Fill Segmentation for Expo & React Native
A high-performance React Native / Expo Native Module for "Smart Region Filling" (flood fill based image segmentation).
Ever wanted a "magic wand" tool or "paint bucket fill" that constraints shapes within an image? This module provides exactly that. It runs an optimized native algorithm directly on the device memory to process complex images and generate scalable SVG path masks in milliseconds.
Features
- True Native Implementation: Written in Kotlin with memory-safe coroutine concurrency via
Dispatchers.Default. - Intelligent Edge Tracing: Uses flood filling and Moore-Neighbor edge tracking to export the closed boundary of an object automatically.
- Expo Friendly: Operates as a pure Expo plugin. Easy to drop into any managed workflow app!
- Works offline: Does not require hefty AI models. It runs purely on mathematical pixel similarity calculation.
Installation
npm install architram-smart-fill-segmentationQuick Start
import { getSmartFillMask } from "architram-smart-fill-segmentation";
import type { SmartFillConfig } from "architram-smart-fill-segmentation";
async function handleTapOnImage(x: number, y: number, imageLocalUri: string) {
try {
const config: SmartFillConfig = {
imageUri: imageLocalUri, // Must be a local `file://` URI
startX: Math.floor(x), // X pixel coordinate of touch point against origin image resolution
startY: Math.floor(y), // Y pixel coordinate of touch point against origin image resolution
tolerance: 20 // Default is 20, up it for wider selection (0-255).
};
// Returns a raw SVG path string "M 10 10 L ... Z"
const svgPathMask = await getSmartFillMask(config);
console.log("Segment Boundary Path:", svgPathMask);
} catch (error) {
console.error("Failed to generate segmentation mask.", error);
}
}API
getSmartFillMask(config: SmartFillConfig): Promise<string>
Returns a Promise that yields a calculated SVG path <Path d="..." /> string for the connected color region clicked upon. If no valid path was found, it returns "" empty string.
SmartFillConfig Configuration
| Property | Type | Required | Description |
| --------- | -------- | -------- | ------------------------------------------------------------ |
| imageUri| string | Yes | Internal file:/// location of the fully downloaded image. |
| startX | number | Yes | The x coordinate starting seed pixel (unzoomed image coord). |
| startY | number | Yes | The y coordinate starting seed pixel (unzoomed image coord). |
| tolerance| number | Optional | Color variance threshold integer value (0 - 255). 20 Default.|
Use-cases
- Interactive Coloring Book constraints.
- Background removal (invert selection path mask).
- Smart touch magic wand tooling.
Support & Contributions
Feel free to open an issue or pull request!
