Heightmap to STL

by mfussi, published

Heightmap to STL by mfussi Jan 1, 2012

Featured Thing!

6 Share
Download All Files

Thing Apps Enabled

Order This Printed View All Apps

Thing Info

24445Views 4023Downloads
Report Thing


Small (and dirty ;) ) script to convert grayscale heightmaps to stl models. Usable for landscapes or terrain prints.

Supported Image Formats: GIF, PNG (preferred), JPEG, BMP

Update: New version released


Please follow this tutorial:
http://adv-geo-research.blogspot.de/2013/10/converting-dems-to-stl-files-for-3d.html (Special thanks to James Dietrich for writing such a good guide)

After you finished step 10 convert the image with heightmap2stl.


java -jar heightmap2stl.jar 'path to imagefile' 'height of model' 'height of base'


'path': Path to the heightmap (png, jpegs,... )

'height of model': Z scale of the model. Height of the max elevation.

'height of base': Height of the base, the model stands on.

https://sourceforge.net/projects/heightmap2stl/?source=directory - Feel free to contribute.

Attached is a low resolution model of the above provided heightmap.

Thing Info

24445Views 4023Downloads
Report Thing

Liked By

View All


Give a Shout Out

If you print this Thing and display it in public proudly give attribution by printing and displaying this tag. Print Thing Tag

All Apps

3D Print your file with 3D Hubs, the world’s largest online marketplace for 3D printing services.

App Info Launch App

This App connects Thingiverse with Makeprintable, a cloud-based mesh repair service that analyzes, validates and repairs most common mesh errors that can occur when preparing a 3D design file for p...

App Info Launch App

Kiri:Moto is an integrated cloud-based slicer and tool-path generator for 3D Printing, CAM / CNC and Laser cutting. *** 3D printing mode provides model slicing and GCode output using built-in...

App Info Launch App
KiriMoto Thing App

With 3D Slash, you can edit 3d models like a stonecutter. A unique interface: as fun as a building game! The perfect tool for non-designers and children to create in 3D.

App Info Launch App
Jun 30, 2015 - Modified Jun 30, 2015

there is another one here that accepts JPG and PNG files and perhaps has less errors: This one seems awesome, first run worked well. I searched heightmap to mesh image to mesh many times online and only found this 1-2 weeks after. it can do JPG and PNG in too :D



Novam - 2D->3D
HGT 2 STL Converter
Oct 13, 2014 - Modified Oct 13, 2014

Exception in thread "main" java.lang.OutOfMemoryError: java heap space
at com.heightmap.Main.main(Main.java:75)

reduced image to 800x600, says output will be 44mb (woah).

Yes, either reduce the image dimensions or add -Xmx1024m to the java arguments (This increases the max heap size to 1GB)

i have run a 1200x1200 one and it produced a 145mb mesh. which was ok in meshlab using 600 megabytes of memory, but is saved it to PLY in netfabb first. don't know if it's artefact free for a slicer program thought. i had an artefact in slicer on a something on the first try of a BW CG image.

It appears that the link to the guide is down. It only brings you to the forum mainpage and not directly to tutorial. Could you please repost or suggest another way to access this? Thank you

Can you make something like this for the reverse, that is convert STL or other 3D model format to grey scale height map image? I have a CNC router that works off of grey scale height maps as the input format and this would be an indispensable tool.

Hello, I am a graduate student in San Diego State University, Computer Science Dept. and working on my thesis project which involves 3D print. I found this script (heightmap2stl.jar) and trying to use it. I want to use this script in my Android app, so wanted to know if this is possible. Also wanted to check if I can get the source code of this jar file.

This would be really helpful to proceed for my thesis work. Hope to hear from you soon!


The left and right ends are not entirely closed properly.... They look like rectangles that go up to the least high side, but they don't close the little triangle on the top. So, it doesn't print. Here's the thing that I made which isn't properly closed, you can see it in "Thingiview" even if you look close at the ends: http://www.thingiverse.com/thing:106087http://www.thingiverse.com/thi...

Ishtar Terra on Venus

I fixed it. The issue with the java program I used is that it doesn't close the left and right ends properly with triangles (just uses rectangles), so add a column at each end of the same color (greyscale).

In my map, the highest point is 12441 ft and the lowest is 6800. if I make my base 10, what should I make the model height to be so the terrain stays to scale?

Hi, thanks for the cool JAR : ) I have a problem, after converting the PNG to to STL file, I opened it in MakerWare. It seems the grid lines are drawn into the model, it goes right into the model. Am I doing something wrong?


Screen shot at

THG - in reply to THG

Silly me, I forgot to switch off the grid lines in MicroDEM. Works fine now : )

Is there anything I can do in MicroDEM or GIMP that will result in
smaller STL file size? Right now I have a lot more resolution then I

Also, do you have any tips on setting the heights so it's to scale?

I get this error when I run the script:

Processing - 3D Topo test.tga
java.lang.IllegalArgumentException: Empty region!
at javax.imageio.ImageReader.computeRegions(ImageReader.java:2689)
at com.sun.imageio.plugins.wbmp.WBMPImageReader.read(WBMPImageReader.java:184)
at javax.imageio.ImageIO.read(ImageIO.java:1422)
at javax.imageio.ImageIO.read(ImageIO.java:1282)
at com.heightmap.Main.main(Main.java:49)

I don't know what it means. Your script and the tga file are in the same directory, this is the command I typed:
java -jar heightmap2stl.jar "3D Topo test.tga" 10 100

I changed file type to png and that seems to work okay.

I'm wondering how you made the base come out properly. I have been using your script on a height map I created and when I slice the file using slic3r and check out the layers it seems like the object gets chopped in 1/2 along the z axis on the xy plane (that is, it starts printing halfway up the object and doesn't print the bottom half). I tried editing the stl file in freecad and meshlab by raising the object to the z floor and nothing seems to work. Can you provide a step by step tutorial from creating the file to creating the g-code? I literally have been working for hours on this and can't find anything helpful. Thanks,

hey, thanks for posting this.  I put a test png image into the program, just 256px strip that ranged from 0-255, and I found that the stl file that was generated was curved.  So it seems that the relationship between greyscale value and height in this program is not linear?  can you suggest a way to make it linear?

I just discovered that the file can be imported directly into openscad. Open the .asc file that was downloaded from google earth.. open it with notepad.. delete the header part and save it as surface.dat

surface(file = "surface.dat", center = true, convexity = 20);

Note: You need a lot better computer than my laptop to render it.

This is pretty awesome.

I have a feature request: can you make it respect transparent pixels? If I have a transparent pixel in a GIF or PNG, make it a hole in the model (or outside the model if on the edge).

There are lots of non-rectangular things which can be modeled as 2D heightmaps, like medallions, sheriff's badges
, etc. This would open up a whole new set of tools for creating 3D objects: design in Photoshop or Illustrator, export as transparent PNG, and convert to STL.

Thanks, this is just what I needed. I've tried every 3d program I have and they all bail on my 1100x1500 binary height map. This program worked very well after I bumped up the memory limits in the JVM by passing -Xmx819200k on the command line (this is probably an unreasonably large number - I just needed it to be big enough to not exhaust the heap).

You can also use MICRODEM to simply export a 3D model (.OBJ) file of the displayed map. I used the GPS tool to enter real-world GPS coordinates for the 4 corners of my 40 acre property, then zoomed to that region
amp; exported a 3D model of it. This creates a VERY large file (mine was 205MB) which can then be edited in most 3D programs.

Alternately, you can also create a 3D height field (elevated mesh) using Rhinocerous, using a greyscale image of your property terrain data. ;) This creates a much smaller file to work with, as well.

thanks for the information, but i needed it two days ago ;) I searched and didn't found anything useable. So i had to code it myself.

I am getting the following error when I try to use heightmap2stl:

Ripped-Pants:Downloads username$ java -jar heightmap2stl.jar sandias.tga 100 3

File: sandias.tga

Model height: 100.0

Base height: 3.0

Processing - sandias.tga

java.lang.IllegalArgumentException: Empty region!

at javax.imageio.ImageReader.computeRegions(ImageReader.java:2689)

at com.sun.imageio.plugins.wbmp.WBMPImageReader.read(WBMPImageReader.java:184)

at javax.imageio.ImageIO.read(ImageIO.java:1422)

at javax.imageio.ImageIO.read(ImageIO.java:1282)

at com.heightmap.Main.main(Main.java:49)

I am on a Mac with OS X 10.6.8 and the following Java verison:
java version "1.6.0_29"
Java(TM) SE Runtime Environment (build 1.6.0_29-b11-402-10M3527)
Java HotSpot(TM) 64-Bit Server VM (build 20.4-b02-402, mixed mode)

seems to be a problem with TGA pictures, use PNG instead.

I tried it with a png image and got the following errors:

Ripped-Pants:Downloads username$ java -jar heightmap2stl.jar sandias.png 100 3
File: sandias.png
Model height: 100.0
Base height: 3.0

Processing - sandias.png
Exception in thread "main" java.lang.UnsatisfiedLinkError: no threedmodel in java.library.path
at java.lang.ClassL
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at com.heightmap.stl.ModelObject.

at com.heightmap.Main.main(Main.java:74)

sorry my bad, thats because of some old code i forgot to remove from the archive. I repacked it, please try the new jar. It should work fine now.


Thanks! :)

Can you specify how to install, and start the software?

after unjar on my mac...

thers just this bunch of files with strange endings (.class,.so,.h,)

.. nothing i can open with anything i have.

crossover wont recognise it as app either.

mfussi - in reply to yzorg

Its a terminal application, so just download it. Open your terminal, navigate to your download folder and start it with this command:

java -jar heightmap2stl.jar 'path to imagefile' 'height of model' 'height of base'
Example: java -jar heightmap2stl.jar image.png 50 5

Hope this helps.

yzorg - in reply to mfussi

doing this nothing happens..

soo thers no user interface then?

Do i have to place the image somewhere in the folder and then after i do the terminal thing?

Jinja - in reply to yzorg

This is a java application packed into a jar file. You execute java applications by passing the jar file to the java runtime. The java runtime is called java.exe and is probably already installed. You can find out if it's installed by opening a terminal and typing java. If it's installed then you'll get a load of usage parameters output.

If you're not used to using the terminal then to make things easier make sure the jar file and image file are in the same directory.

Navigate the prompt to the location where you saved the jar and image files then type the following at the prompt...

java -jar heightmap2stl.jar image.png 50 5

pe that helps.

Sounds interesting but I am clueless with what to do with these files

This is useful for creating 3d images from grayscale images. Great for 3d relief carving with a cnc machine or 3d printing. While the author wrote the program for making 3d maps from 2d images, it works well for a lot of different pngs. Search 3d relief grayscale on google for a better idea of how cool this program is.