Comments (5)
I just ran into this with my own B&W inkypHAT. Here's what I'm using to take an arbitrary image and convert it to black or white pixels based on a threshold.
def reindex_image (other):
rgb_im = other.convert('RGB')
img = Image.new("P", (inky_display.WIDTH, inky_display.HEIGHT))
for x in range(inky_display.WIDTH):
for y in range(inky_display.HEIGHT):
(r, g, b) = rgb_im.getpixel((x, y))
color = inky_display.WHITE if r > 127 else inky_display.BLACK
img.putpixel((x, y), color)
return img
# Read your indexed PNG image ...
img = Image.open("foo.png")
# Reindex into black and white colors
img = reindex_image(img)
# buffer & show
inky_dispay.set_image(img)
inky_display.show()
from inky.
This caused me a bit of trouble since I was trying to load PNGs and didn't have a good way to change the palette ordering. I made a python script to convert a PNG to the correct Black/White/Red colors for the 3 color display. I figured I'd share to save anyone else the trouble:
from PIL import Image
source = "old.png"
destination = "new.png"
# Open source file
oldimage = Image.open(source)
# Create palette. Must contain 768 integer values
palettedata = [
255, 255, 255,
0, 0, 0,
255, 0, 0
]
palettedata += [0] * (768 - len(palettedata))
# Create palette image
palimage = Image.new('P', (1, 1))
palimage.putpalette(palettedata)
# Quantize (change to dither=1 if you want dithering)
newimage = oldimage.quantize(palette=palimage, dither=0)
# Save
newimage.save(destination, "PNG")
from inky.
We should probably whip up an example with this approach, or perhaps build it in. I'm conflicted!
I was deliberately trying to make Inky image-library-agnostic, but that does make it difficult to re-introduce features such as palette-order.
Right now converting the image with PIL before displaying it on Inky is the "right" approach, but I'm not convinced it's the best.
from inky.
I cannot do the conversion with PIL because it cannot handle my input images. Since i'm using imagemagick for conversion anyway, i can just as well do everything there. Except palette order, unfortunately. My workaround works for me, i hope it is useful for someone else too 😁
from inky.
The old inky-phat
library had a colswap
parameter in set_image
that could be used to swap colors (see here). Of course, this does not really help honor the palette, but would make it easier to manually reorder the colors. IMO, reintroducing the colswap
functionality would not conflict with the aim to make inky
image-library-agnostic.
from inky.
Related Issues (20)
- New issues with running this out of the box - 7-Colour (UC8159) Inky Impression HOT 1
- 'pip3 install inky' fails to install 'spidev' dependency HOT 1
- 404 for libtiff5 package needed for examples that use PIL HOT 4
- Inky Developer + HAT Mini (Host) not working HOT 2
- pHAT weather example stopped working HOT 2
- Feature request: faster monochrome updates on Inky Impression HOT 2
- eeprom.py SMBus needs to be closed HOT 1
- SSD1608 Custom Lookup table HOT 2
- How to map palette to impression 7.3 colours and avoid dithering
- Make inky work with NVIDIA Jetson Nano HOT 1
- Magic number and checksum for eeprom HOT 1
- Pi Zero W - Not Enough Ram to pip install seaborn HOT 1
- `InkyMockImpression.set_image` fails with `AttributeError`
- `InkyMockImpression` class doesn't easily support multiple resolutions
- Use on any non-Pi machines? HOT 3
- Treating Inky pHAT-Red as Black/White doesn't work
- Busy Wait error - Line 323/333 HOT 1
- AttributeError: 'FreeTypeFont' object has no attribute 'getsize'
- Odd permissions issue on new Inky Impressions 7.3" HOT 1
- error: externally-managed-environment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from inky.