Segments objects in an image by grouping connected pixels with similar RGB values using a flood-fill algorithm. It filters small objects, identifies the largest as the background, and assigns unique IDs. The results are visualized by overlaying object IDs on an output image, skipping the background.
This project performs object segmentation in an image based on color similarity. It identifies connected components, assigns unique IDs to each object, and generates an overlay image with object IDs.
- Flood-Fill Algorithm: Groups connected pixels with similar RGB values.
- Object Filtering: Removes small objects below a size threshold.
- Background Identification: Recognizes and labels the largest object as the background.
- Overlay Generation: Outputs an image with object IDs displayed.
- Python 3.7+
- Libraries:
Pillow,numpy
Install dependencies with:
pip install Pillow numpy-
Place your input image in the
inputdirectory and name itimage1.png(or modify thefile_pathin the script). -
Run the script:
python script.py- The output image with overlaid object IDs will be saved to the
outputdirectory asoverlay_with_numbers.png.
-
Threshold (
threshold) : Adjusts color similarity sensitivity (default: 170). -
Min Object Size (
min_object_size) : Filters out small objects (default: 100).
This project is licensed under the MIT License. See LICENSE for details.