Skip to content

Commit

Permalink
Improved dithering for 2 color palettes
Browse files Browse the repository at this point in the history
- taking square root of 2 color PMFs for more dithering
- added Pal.list() to Pal
- updated README.md examples and examples Notebook
- increased version number to 2.0.1
  • Loading branch information
sedthh committed Apr 7, 2021
1 parent de1ce9a commit 3685a4d
Show file tree
Hide file tree
Showing 9 changed files with 83 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pyx_robocop.transform(car)
pyx_robocop.transform(robocop)
"""
```
![Fit Transform Palette](/examples/p_fit_transform_.png)
![Fit Transform Palette](/examples/p_fit_transform.png)

For a single image, it is possible to call both fit() and transform() at the same time:

Expand Down
74 changes: 66 additions & 8 deletions examples.ipynb

Large diffs are not rendered by default.

Binary file modified examples/p_br.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified examples/p_br2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
2 changes: 1 addition & 1 deletion pyxelate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = "2.0.0"
__version__ = "2.0.1"

__short_description__ = (
"Downsample images to 8-bit pixel art.",
Expand Down
5 changes: 5 additions & 0 deletions pyxelate/pal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def __next__(self):
else:
raise StopIteration

@classmethod
def list(self):
"""list all available Palette names"""
return list(map(lambda x: x.name, self))

def from_hex(hex_list):
"""Generate Pal palette from list of #HEX color values"""
hex_list = [h.lstrip("#") for h in hex_list]
Expand Down
9 changes: 9 additions & 0 deletions pyxelate/pyx.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ def fit(self, X, y=None):
warnings.warn("Pyxelate could not properly assign colors, try a different palette size for better results!", Warning)
return self

def predict_proba(self, X):
p = super().predict_proba(X)
if self.find_palette:
if self.palette < 3:
return np.sqrt(p)
elif len(self.palette) < 3:
return np.sqrt(p)
return p


class Pyx(BaseEstimator, TransformerMixin):
"""Pyx extends scikit-learn transformers"""
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from setuptools import setup

setup(name='pyxelate',
version='2.0.0',
version='2.0.1',
description='Pyxelate is a Python class that converts images into 8-bit pixel art.',
url='http://github.com/sedthh/pyxelate',
author='sedthh',
Expand Down

0 comments on commit 3685a4d

Please sign in to comment.