An algorithm to polygonize images. Make images more concise, an effect like paper cut in photoshop. Also support to fix the direction of edges to make them more regular.
The Great Wave off Kanagawa, Katsushika Hokusa, 1831
The Starry Night, Vincent van Gogh, 1889
Portrait of an Unknown Woman, Ivan Kramskoi, 1889
Core ideas:
- Using Superpixel to segment images
- Create region adjacency graph
- Merge adjacent regions base on certain thershold
- Extract separate fused regions and their colors
- Polygonize each area
- [Fix directions]
- Python 3.x
- opencv-python > 4.5
- skimage
- numpy
python main.py input.jpg output.jpg [-d fix-option]
fix-option == 1: create octagon like polygons, with all lines vertical or horizontal or 45 degrees oblique
fix-option == 2: create rectangle like polygons, with all lines vertical or horizontal
Support SVG format output 😋
- Add more polygon edge diretion fix options
- Add pre-processing to increase the contrast to make the segmentation effect more obvious
- Remove noise