• Stars
    star
    157
  • Rank 230,637 (Top 5 %)
  • Language
    C
  • License
    BSD 2-Clause "Sim...
  • Created almost 3 years ago
  • Updated almost 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Turn PNG images into STL 3D models that will "develop" in front of a light source

pngtostl is a program that converts a PNG image into a litophane, in STL format, suitable to be printed by entry level 3D printers.

What is a litophane?

It's a piece of plastic (3D printed plastic, usually) that is thicker in correspondence of places where the original image is darker, and thinner in correspondence of places where the original image is lighter. Putting this 3D model negative between the observer and a light source (for instance the daylight sun, a lamp, ...) will show the original image, because the parts where the plastic is thicker will let less light to flow from one side to the other. It's like "developing" a photo negative :)

This is really one of those cases where an image is worth more than words:

Positive 3D model

Negative 3D model

The above example was printed using a Prusa Mini printer, using the STL file generated by pngtostl and sliced using PrusaSlicer.

Usage

Compile with make (you need libpng). Then use like this:

./pngtostl image.png > model.stl

Warning: use reltaively low resolution images, if the image is big resize it, otherwise the resulting STL file will be huge without any good reason. Most printers can't go over a given (small) resolution anyway. Do a first try with a very small image, like 300x300 pixels, then move to larger images as you want to print larger negatives.

By default the generated model will use 1x1 millimeters per pixel, 20 "levels" (different heights) to generate 20 levels of grey, and will produce a model with total height of 1.2 millimeters: 0.2 millimeters base, 1 millimeter to reproduce the greys.

The conversion to greyscale works just taking the average of RGB pixels, and the 20 greys are selected by normalizing the image min/max luminosity, and mapping the greys (heights) linearly.

Note that after you import the STL in the slicer, you'll likely have to reduce its size, unless the image is tiny. This would produce a model that is too "flat" so you'll have to stretch it to reach 1 or 2 millimeters of height at least: this depends on the layer height you selected in the slicer. If you have a .10 layer height, and a model total height of 1.2 millimeters, only 10 different levels will be printed (0.2 is lost in the base), and so forth.

Using the program options you can change all the sttings discussed above:

./pngtostl --help
png2stl image.png [... options ...]
  --relief-height <mm> | Relief height.      Default: 1 mm
  --base-height <mm>   | Fixed base height.  Default: .2 mm
  --levels             | Number of different levels (heights/greys). Default: 20
  --negative           | Use thicker plastic for black (default).
  --positive           | Use thicker plastic for white.

If you use a big enough base, you can try to print the model vertically: 3D printers usually have a much higher resolution in the XY plane, so the result will be much better. However in this case make sure the print will not detach during printing (maybe use a brim).

Generating positive images

The default is to produce a negative model that you can develop putting it in front of a light source, but the program also supports the other mode, where the lighter parts of the image will be the one with the greater height in the plastic model.

This mode is activated by using the --positive option. This mode is thought to be used with color change during the print. I'll hope to produce a proper experiment with it and add a picture here.

STL generation

This program was written in about 1 hour (it took me more time to do the test and write this README file!) so is very limited and not very optimized. Every pixel is a separated box, this makes its internals a lot simpler but will produce more triangles, and the STL files will be very big.

Every pixel will generate a box that is composed of 12 triangles. Normals are not set in the STL file, instead the right hand rule is used in order to ensure that all the triangles in a box will point outwards.

License

This program is free software released under the BSD 2-clause license.

More Repositories

1

disque

Disque is a distributed message broker
C
7,969
star
2

kilo

A text editor in less than 1000 LOC with syntax highlight and search.
C
6,839
star
3

smallchat

A minimal programming example for a chat server
C
6,606
star
4

sds

Simple Dynamic Strings library for C
C
4,649
star
5

linenoise

A small self-contained alternative to readline and libedit
C
3,348
star
6

dump1090

Dump1090 is a simple Mode S decoder for RTLSDR devices
C
2,232
star
7

neural-redis

Neural networks module for Redis
C
2,218
star
8

lamernews

Lamer News -- an HN style social news site written in Ruby/Sinatra/Redis/JQuery
Ruby
1,357
star
9

hping

hping network tool
C
1,327
star
10

smaz

Small strings compression library
C
1,096
star
11

rax

A radix tree implementation in ANSI C
C
1,043
star
12

botlib

C Telegram bot framework
C
754
star
13

load81

SDL based Lua programming environment for kids similar to Codea
C
586
star
14

disque-module

Disque ported as Redis module
C
480
star
15

protoview

Flipper Zero app to display known and unknown signals
C
445
star
16

shapeme

Evolve images using simulated annealing
C
382
star
17

aocla

A small stack based, written to bring Advent of Code 2022 Day 13 puzzle to the extreme consequences
C
371
star
18

retwis

A Twitter-toy clone written in PHP and Redis, used in the early days to introduce Redis data types.
PHP
357
star
19

lua-cmsgpack

A self contained Lua MessagePack C implementation.
C
343
star
20

freakwan

A MicroPython driver for the SX1276 LoRa chip
C++
274
star
21

otree

a simple btree implementation with automatic space reclaiming
C
268
star
22

redis-sampler

Small program to understand the composition of your Redis data set
Ruby
260
star
23

redis-rb-cluster

Redis Cluster Ruby client based on redis-rb
Ruby
246
star
24

stonky

Stock market Telegram bot
C
242
star
25

RESP3

RESP protocol V3 repository. Contains the specification, and other related resource
221
star
26

redlock-rb

Redlock Redis-based distributed locks implementation in Ruby
Ruby
197
star
27

lloogg

LLOOGG realtime web log analyzer
PHP
195
star
28

redis-timeseries

Ruby library for Redis backed time series.
Ruby
195
star
29

redis-tools

Abandoned project "Redis tools". What was relevant is now part of redis-cli & redis-benchmark
C
194
star
30

iconping

Icon Ping - visual ping to 4.2.2.2
Objective-C
129
star
31

jsrt

Javascript ray tracing engine
118
star
32

adventofcode2022

A few Advent of Code puzzles (2022 edition) in C
C
102
star
33

redimension

Redis multi-dimensional query library
Ruby
98
star
34

gopher2redis

A Ruby script that translates a directory structure and its files into the Redis keys to be served via Redis Gopher protocol
Ruby
90
star
35

mc-benchmark

Memcache port of Redis benchmark
C
85
star
36

listpack

A serialization format and implementation for backward-traversable lists of strings.
C
79
star
37

Bigdis

Bigdis - a file-based KV store speaking the Redis protocol
Tcl
76
star
38

visitors

Visitors fast web log analyzer
C
76
star
39

book-examples

Redis The Definitive Guide book code examples
Ruby
51
star
40

flipper-asteroids

Asteroids for Flipper Zero
C
50
star
41

Gitan

Gitan is a very basic web interface to create and inspect bare git repositories
Ruby
45
star
42

aspark

ASCII sparklines for the Enterprise
C
41
star
43

Jim

Jim is a small footprint Tcl interpreter, with some changes to the original language but mostly compatible.
40
star
44

nolate

NO LAme TEmplate System for Ruby
Ruby
40
star
45

recidiv

minimal continuous integration framework written in Tcl (used for Redis CI)
Tcl
38
star
46

tclircd

An IRC server I wrote in 2004 for fun, using the Tcl language.
Tcl
37
star
47

partitions

Partitions.tcl is a Tcl program to simulate partitions between physical hosts
Tcl
36
star
48

connect4-montecarlo

Simple connect 4 AI using Monte Carlo method
C
31
star
49

talk32

C program to talk via serial to MicroPython powered ESP32 boards
C
28
star
50

failed-3d-prints-bot

A Telegram bot that detects failed prints and send you an image of your printer
C
22
star
51

iqmeteo

Meteo widget for the Garmin Vivoactive HR powered by Yahoo Weather API
Shell
21
star
52

siphash

A modification of SipHash reference implementation to make it more practical for Redis usage
C
20
star
53

redisdotphp

Legacy Redis PHP client lib. A best-effort support repository.
18
star
54

yaku-ns

a DNS server I wrote 10 years ago. Here for historical reasons
C
18
star
55

strabo

Turns HGT elevation maps into 2D images or 3D models
C
18
star
56

nn-2003

2003 Neural Networks experiments -- when it was not mainstream ;-)
C
17
star
57

zx2040

RP2040 ZX Spectrum emulator
C
15
star
58

crack-checksum

Find checksum (crc8, xor, add) parameters in a set of messages.
C
13
star
59

hiredis

WARNING: hiredis repository moved to http://github.com/redis/hiredis. Just my private fork.
13
star
60

dict-scan-fuzz-tester

Fuzz testing for the SCAN underlying algorithm
C
11
star
61

Siboom

A simple markup system for writing books drafts
Ruby
10
star
62

sbignum

Old code about C library for big numbers plus Tcl bindings
C
9
star
63

codakido

Redirects to Load81 project
8
star
64

redis-cp-rewrite-sim

Redis/Raft snapshotting rewriting simulation
C
8
star
65

cache-mem-tester

Test memory efficiency of Redis / Memcached against values with a given size distribution.
Ruby
7
star
66

rascan

A prototype for a multi processes port scanner I wrote in 1998. Here only to archive it for myself.
C
6
star
67

LLM-FTC-sampling

First token cutoff sampling inference example
Python
6
star
68

t-watch-s3-micropython

Minimal MicroPython programming example for the Lilygo T-WATCH S3
Python
4
star
69

bma423-pure-mp

Pure MicroPython BMA423 accelerometer driver
Python
4
star
70

simple-language-model

Code for the video on feed-forward language model
Python
4
star
71

gif-pure-tcl

Pure TCL GIF generator
Tcl
4
star
72

bme680-pure-mp

Pure MicroPython Bosch BME680 sensor driver
Python
3
star
73

uc8151_micropython

UC8151 / IL0373 MicroPython e-paper display driver with support for greyscales and fast updates
Python
2
star
74

vl53l0x-nb

Fork of MicroPython driver for vl53l0x TOF sensor to add non-blocking mode.
Python
1
star
75

micropython-ft6x06

Simple driver for FT6x06 capacitive touch sensor in pure Python
Python
1
star