pngtostl is a program that converts a PNG image into STL 3D models

Overview

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  | Relief height.      Default: 1 mm
  --base-height    | 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.

You might also like...
PoC black/white image sequence to dumpy gif image sequence converter

PoC black/white image sequence to dumpy gif image sequence converter

The “Quite OK Image” format for fast, lossless image compression

The “Quite OK Image” format for fast, lossless image compression

Example program for integrating Dear ImGui and GLFW into Source's App System

This is an example program for integrating Dear ImGui and GLFW into Source's app system, the same thing Source's tools use. Feel free to do with this

Implement a program that recovers JPEGs from a forensic image, per the below.

Recover - CS50 Implement a program that recovers JPEGs from a forensic image, per the below. $ ./recover card.raw Background In anticipation of this

C++ library thats implemets class color. Available models: RGB, HSL, HSV, CMY, CMYK, YIQ, YUV and growing.

Yet another c++ library that implements color. Description Yet another c++ library that implements color conversion and manipulation. Key features: No

ZT is a zig-contained library that automatically compiles+links ImGui, OpenGL, and GLFW into typed packages.
ZT is a zig-contained library that automatically compiles+links ImGui, OpenGL, and GLFW into typed packages.

ZT is a zig-contained library that automatically compiles+links ImGui, OpenGL, and GLFW into typed packages. By zig contained I mean that ZT is intend

Diagon transforms markdown-style expression into an ascii-art representation.
Diagon transforms markdown-style expression into an ascii-art representation.

Diagon is an interactive interpreter. It transforms markdown-style expression into an ascii-art representation.It is written in C++ and use WebAssembly, HTML and CSS to make a Web Application.

You can use this to compile the code and output images into a word doc for assignment purposes
You can use this to compile the code and output images into a word doc for assignment purposes

Code_n_Ouput_to_docx You can use this to compile the code and output images into a word doc for assignment purposes Basic requirements: Python 3.7 or

Utility to combine color channels from different textures into a single output.
Utility to combine color channels from different textures into a single output.

unity-texture-packer 🔨 Utility to merge different texture channels into a final texture output. Install Using Git Make sure the Git client is install

Comments
  • Math library needed?

    Math library needed?

    I had to edit the Makefile to add -lm in order to successfully compile, otherwise:

    /usr/bin/ld: /tmp/cc3A4ed2.o: undefined reference to symbol 'roundf@@GLIBC_2.2.5'
    /usr/bin/ld: /lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing from command line
    

    My platform: Ubuntu 20.04.3 LTS

    opened by Spiritdude 1
Owner
Salvatore Sanfilippo
Computer programmer based in Sicily, Italy. I mostly write OSS software. Born 1977. Not a puritan.
Salvatore Sanfilippo
Arduino PNG image decoder library

An 'embedded-friendly' (aka Arduino) PNG image decoding library

Larry Bank 102 Jan 6, 2023
An image and texture viewer for tga, png, apng, exr, dds, gif, hdr, jpg, tif, ico, webp, and bmp files

An image and texture viewer for tga, png, apng, exr, dds, gif, hdr, jpg, tif, ico, webp, and bmp files. Uses Dear ImGui, OpenGL, and Tacent. Useful for game devs as it displays information like the presence of an alpha channel and querying specific pixels for their colour.

Tristan Grimmer 159 Dec 31, 2022
libspng is a C library for reading and writing PNG format files with a focus on security and ease of use.

libspng (simple png) is a C library for reading and writing Portable Network Graphics (PNG) format files with a focus on security and ease of use.

Randy 570 Dec 29, 2022
Simple, generally spec-compliant, hacky PNG Decoder written in C99.

Simple, generally spec-compliant, hacky PNG Decoder written in C99.

cristei 2 Nov 2, 2021
Very fast C++ .PNG writer for 24/32bpp images.

fpng Very fast C++ .PNG writer for 24/32bpp images. fpng.cpp was written to see just how fast you can write .PNG's without sacrificing too much compre

Rich Geldreich 639 Dec 25, 2022
Demo of a fast PNG encoder.

Fast PNG Encoder This is a proof-of-concept fast PNG encoder that uses AVX2 and a special Huffman table to encode images faster. Speed on a single cor

Luca Versari 58 Dec 27, 2022
PNG encoder and decoder in C and C++.

PNG encoder and decoder in C and C++, without dependencies

Lode Vandevenne 1.7k Dec 25, 2022
Rate-Distortion Optimized Lossy PNG Encoding Tool

rdopng is a command line tool which uses LZ match optimization, Lagrangian multiplier rate distortion optimization (RDO), a simple perceptual error tolerance model, and Oklab-based colorspace error metrics to encode 24/32bpp PNG files which are 30-80% smaller relative to lodepng/libpng.

Rich Geldreich 40 Dec 24, 2022
Fast streaming PNG<->QOI converter with some compression-improving extensions

QOIG Fast streaming PNG<->QOI converter with some compression-improving extensions. Can achieve 1%-10% better compression than QOI without sacrificing

David Rutter 3 Oct 3, 2022