đ¨ react-native-mask-segment-canvas
A React Native 0.79 interactive mask segmentation library. The core export is the MaskSegmentCanvas component, consumable via npm package or npm link from any React Native project.
- đ§ OpenCV (
react-native-fast-opencv): mask semantic layout, baseboard patching, region extraction - đī¸ Skia RuntimeEffect (SkSL): single-pass full-screen shader blending original image + LAB low/high frequency texture color overlays
- âī¸ Skia Path: dashed outline highlights for regions
- 𧲠Magnetic Lasso: manual wall partitioning with edge-snapping (Sobel gradient + Dijkstra shortest-path) and Active Contour boundary refinement
- đ Interaction: bottom color bar for brush selection (optional initialization) â tap a region to paint; tapping without a brush selected fires
onPaintCallbackwith a hint; long-press without a brush previews the region's dashed outline
This repository serves as both the library source (src/index.ts) and a self-test demo (root App.tsx).
đ For the recommended integration demo, see the example/ directory â it uses only the public API, fully simulating how a consumer project would integrate (including package.json, Metro configuration, and a complete reference App.tsx).
đ Overviewâ
MaskSegmentCanvas renders an original image with an overlaid semantic mask, allowing users to tap regions and apply colors. The pipeline:
- đĨ Load the origin image and mask image (local
file://or remotehttp(s)://) - đ§Š Segment the mask via OpenCV into semantic regions (walls, ceiling, baseboard, etc.)
- đ¨ Prepare LAB frequency-layer textures via SkSL for realistic color blending
- đ Build Skia dashed-outline paths for each region
- 𧲠Manual Split (optional) â draw lasso polygons on walls to subdivide into independently-paintable
wall-Nregions, with optional edge-snapping and Active Contour refinement - đ Interactive â users select a brush color and tap regions to paint; paint layers preserve the underlying texture
- đž Save the composited result as PNG; export a JSON session for draft recovery
The component emits onWatch state transitions through the pipeline so the host app can show appropriate loading states.
đ Requirementsâ
- đĸ Node.js >= 18 (recommended 20+)
- đ Xcode 15+ (iOS)
- đ¤ Android Studio + JDK 17 (Android)
- đĻ CocoaPods (iOS)
đ Next Stepsâ
- Installation â set up the library in your project
- Quick Start â run the dev demo
- Basic Usage â minimal example to get started
- API Reference â full prop and method documentation