Abstract
Recently, instant level labeling for supervised machine learning requires a considerable number of filled masks. In this paper, we propose an efficient automatic region filling algorithm for complicated regions. Distinguishing between adjacent connected regions, the Main Filling Process scans through all pixels and fills all the pixels except boundary ones with either exterior or interior label color. In this way, we succeed in classifying all the pixels inside the region except boundary ones in the given image to form two groups: a background group and a mask group. We then set all exterior label pixels to background color, and interior label pixels to mask color. With this algorithm, we are able to generate output masks precisely and efficiently even for complicated regions as long as boundary pixels are given. Experimental results show that the proposed algorithm can generate precise masks that allow for various machine learning tasks such as supervised training. This algorithm can effectively handle multiple regions, complicated 'holes' and regions whose boundaries touch the image border. By testing the algorithm on both toy and practical images, we show that the performance of Scan-flood Fill(SCAFF) has achieved favorable results.
Introduction
In supervised machine learning, especially for tasks like salient object segmentation, researchers need precise masks (ground truth). However, to save storage space, many large datasets only provide boundary annotations—the "outline" of the object. Converting these outlines into solid masks is surprisingly tricky. Traditional "seed filling" requires a human to click inside the shape, and existing automatic methods often fail when an object has "holes" inside it, touches the edge of the image, or when multiple disconnected objects exist in one frame.
SCAFF (Scan-Flood Fill) aims to solve these issues with a robust, "set-it-and-forget-it" preprocessing tool that converts object boundaries into precise binary masks without requiring manual seed points.
Methods
The authors propose a multi-step process for SCAFF:
- Padding: Adds a 1-pixel border to ensure the "background" is always connected.
- Initial Fill: Flood-fills the outermost background.
- The Main Filling Process: The algorithm scans the image pixel by pixel. When it hits an unfilled pixel, it "looks back" to find the nearest filled neighbor.
- If the neighbor was "Exterior," the new region must be "Interior" (part of the mask).
- If the neighbor was "Interior," the new region must be "Exterior" (a hole).
- Color Inversion: Finally, it maps these temporary labels back to a standard binary mask.
The core innovation is the alternating property: in a nested structure, every time you cross a boundary, the "type" of the region (background vs. mask) flips. This allows the algorithm to implicitly understand the topology of the image, treating "holes" not as errors, but as nested exterior regions.
Key Results
The authors evaluated SCAFF using a custom toy dataset and the MSRA10K salient object segmentation dataset. On MSRA10K, SCAFF achieved an F1 score of 0.988 and a Mean Absolute Error (MAE) of 0.0041, significantly outperforming simpler methods like Exterior-Fill and Color Inversion (EFCI).
In terms of efficiency, for a 2000x2000 image, SCAFF takes roughly 11.7 seconds on a standard laptop (i7-8550U). While slightly slower than the basic EFCI, it is far more accurate for complex shapes. The algorithm’s runtime scales linearly ($O(p)$) with the number of pixels, making it highly efficient for processing thousands of high-resolution images.
Conclusion
SCAFF provides a highly efficient and precise method for generating masks from boundaries, even for complex topologies. By combining scan-line logic with flood-filling and a clever neighbor-checking heuristic, it successfully handles nested holes and objects touching the image border. This makes it a valuable tool for automating the generation of ground truth masks for machine learning tasks.
Summary updated