Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/setanarut/decompose

Decompose image into layers (Fast Soft Color Segmentation)
https://github.com/setanarut/decompose

alpha-compositing color-separation decomposition image-processing pytorch-implementation segmentation

Last synced: 26 days ago
JSON representation

Decompose image into layers (Fast Soft Color Segmentation)

Awesome Lists containing this project

README

        

# Decompose

[Fast Soft Color Segmentation](https://github.com/pfnet-research/FSCS) without `Residue predictor`.
[Paper PDF](https://arxiv.org/pdf/2004.08096.pdf)

## Installation

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

## Example

```python

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!
#
#
#
#
#
#
#
```

You can write layers as [ORA](https://docs.krita.org/en/general_concepts/file_formats/file_ora.html) file

```python
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.

```python
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.

```bash
$ 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](./assets/palette.jpg)