PDA

View Full Version : Contour Lines/Maps in GIMP



Zach
01-23-2014, 06:05 PM
This isn't strictly a tutorial per se, but I can find no better place to put this up. I created a GIMP Script-Fu plugin that will take any heightfield and generate a contour map of it. Somebody requested that I post it, so here it is.

There are two scripts: Contour Line, which adds one contour line to the heightfield, and Contour Map, which adds a lot of contour lines at once by calling Contour Line.

To install the scripts in GIMP, put both .scm files in any of the folders GIMP looks in for scripts (to find this out, go to GIMP Preferences→Folders→Scripts). Then refresh the scripts by going to Filters→Script-Fu→Refresh Scripts, or just by restarting GIMP.

The script expects a simple image in shades of grey, which represents a height field (see the first example image). Contour Map allows you to set the upper and lower bounds of height (to do the whole thing use 0 and 255 respectively), set the width of the contour lines, set how much elevation is skipped between lines, and set how much smoothing the lines will receive. The example maps are only 512 x 512, so there are a lot of little artifacts that would disappear on larger maps.

Jacktannery
01-23-2014, 06:51 PM
That's brilliant - well done Zach.

ltan
10-09-2014, 05:44 PM
Perhaps I am the only one who had issues running these scripts, but here is what I figured out {in case it helps others}

When you are using a height map, make sure that you are using grey scale colors, but the image is in RGB.

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/HeightMapUsed.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/HeightMapUsed.png)

The next step is to call the Contour Map script.

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/WhereToFindContourScripts.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/WhereToFindContourScripts.png)

The following dialog should open, and the example here has already been filed out to what I was using at the time.

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/ContourMapOptionsUsed.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/ContourMapOptionsUsed.png)

After adjusting the sliders / numbers to those that you want, clicky the Ok button. These settings made a busy topo map that took a minute or so to run.

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/ResultingMap.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/ResultingMap.png)

These lines are tooo light for my liking. There are two options that can be done to correct this. The first option is to duplicate the Contour Map layer until the desired contrast is achieved. The other option is to delete the Contour Map layer and redo the script with a different Hardness selected.

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/ResultingMap0p6Hardness.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/ResultingMap0p6Hardness.png)

I found 0.6 to be almost too dark when I re-ran the script, so this will be something that I will probably play with on every map. Of course it could just be the level of detail that I am having the script run with that is jamming everything together and looking busy.

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/ResultingMap0p6Hardness10unitsChangeE20Special.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/ResultingMap0p6Hardness10unitsChangeE20Special.png )

And that was indeed the issue with this height map. I was changing the height difference too gradually which crams all of the contours ontop of each other. Not idea for the small-ish image that I am using, well previewing, as when the image is viewed at full resolution the lines are not so squashed.

From here artistic license can be given to the end user to allow some nice looking topo maps. Thanks for the scripts Zach!!!!

http://imghost.thumbprintpro.com/var/thumbs/GiMP---Map-Making/ColoredTopo.png (http://imghost.thumbprintpro.com/var/albums/GiMP---Map-Making/ColoredTopo.png)


Sorry for the rambling.

RobA
10-16-2014, 01:30 AM
Hi Zach!

As a tip, to get smother strokes in your script, convert the selections to paths then stroke those.

For example, if you change this bit in your script:

(gimp-edit-stroke theLayer)

to be:

(plug-in-sel2path RUN-NONINTERACTIVE theImage theLayer)
(gimp-selection-none theImage)
(gimp-edit-stroke-vectors theLayer (vector-ref (cadr (gimp-image-get-vectors theImage)) 0))
(gimp-image-remove-vectors theImage (vector-ref (cadr (gimp-image-get-vectors theImage)) 0))

You will end up with smoother contour lines.

Here is an example (the stroked selection on the left half, the stroked path on the right half):
68391

You could also go crazy and use the plug-in-sel2path-advanced command that lets you specify corner thresholds, align thresholds, and all other kinds of path tracing voodoo, but that could be overkill :)

-Rob A>