Skip to content

Decompose image into layers (Fast Soft Color Segmentation)

License

Notifications You must be signed in to change notification settings

setanarut/decompose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Decompose

Fast Soft Color Segmentation without Residue predictor. Paper PDF

Installation

pip install git+https://github.com/setanarut/decompose 

Example

from decompose.decomposer import decompose
from PIL import Image

img = Image.open("image.jpg")
layers = decompose(img)

for layer in layers:
    print(layer)

# Decomposer mask generation...
# Decomposer processing alpha layers...
# Decomposer Done!
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x1144F71D0>
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x111EA4A90>
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x114585510>
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x114587790>
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x1145856D0>
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x1145858D0>
# <PIL.Image.Image image mode=RGBA size=904x368 at 0x114585C90>

You can write layers as ORA file

from decompose.utils import images_to_ORA

images_to_ORA(layers).save("img.ora")

If palette is not given as an argument, a palette is created automatically. Colors can be selected manually.

manual_palette = [
    (255, 255, 255),
    (3, 135, 3),
    (3, 193, 160),
    (1, 167, 255),
    (255, 243, 0),
    (193, 0, 0),
    (3, 0, 2),
]
layers = decompose(img, manual_palette)

decomp command-line tool example

Saves layers as ORA (Open Raster) file. It can be opened with Krita. Also saves the palette.

$ decomp ~/Desktop/img.png

# Decomposer mask generation...
# Decomposer processing alpha layers...
# Decomposer Done!
# ORA saved: img.ora
# 7
# Palette saved: img_palette.png

Note

The model only supports 7 colors. The same color can be repeated for less color.

palette