PDA

View Full Version : Reverse Quantizing, AKA - how to get a heightfield from contour lines



RobA
11-28-2007, 09:13 PM
Reading Geoff's post on creating a heightfield got me thinking about the best way to do it.

Starting with contour lines (which are basically quantized heightfields) how can I go back and get the heightfield I started with (or least a close approximation)

Ideally, this should retain the detailed information of the contour lines, while providing a smooth representation of the heightfield between.

The common suggestion seems to stack up the contour lines, filling each band with colours reflecting the elevations, then blur them all. The problems I have experienced are that 1) with too little blur, we get steps, and with too much blur, all definition of the shape and detail at the contour lines is lost.

Look at these full size, the thumbnailer really messed these up!

So I drew a problematic (sharp edges, variable slopes) heightfield:
1790

This represents my best case 3d render:
1794

Now I quantized the image with 8 levels to represent what I could get from contour lines:
1791

I ran this with three different blur amounts, 5px, 35px and 50px. Unfortunately stepping was horible in the 5 px, noticeable in the 35, and minimal in the 50, but all detail was lost in the 50, with the image looking like a smooth hump.

So I pulled the quantized image into inkscape, ran the bitmap tracer on it to get the 8 paths representing the countour levels, then interpolated the colour with 8 steps between each of the adjacent contour paths. This produces pretty good results, but the small interpolation were visible as fine steps, so I applied a 2% blur to all the objects in Inkscape and ran it one last time.

The results here were quite good! there is still a small band at each of the contour lines...due (I think) to double copies of each of the original contour lines. The detail however is excellent, with the original shape very well preserved:
1795

Lastly, here is a test sheet with all of them for comparison purposes:
1793

This technique works well for single shapes...but I am not sure how well it would work for complex shapes... they may break the interpolate function. Something to play with later, I guess...

-Rob A>

ravells
11-29-2007, 05:27 AM
Very cool!

Being able to generate a smooth heightfield from contours would be amazingly useful in terms of controlling where you want your mountains etc to go, how high they are and how steep.

By 'interpolate' do you mean a gradient fill from one one colour's level to the next or is what is referred to as a 'blend' in illustrator, where you create new vector shapes that ...er..interpolate from one shape to the next. (have I answered my own question?)

I'd like to play around with this too. If the shapes are complex, I wonder whether feathering or using an inner glow might work to blend the colours between levels?

If we can crack this problem, then overlaying the resulting image against a faint perlian noise background would provide a nice natural 'noise' to the mountains.

RobA
11-29-2007, 10:18 AM
Interpolate actually creates new shapes between two paths and optionally interpolates the style attributes. Here is an example of interpolating between two shapes apart from each other, and of a white circle on a black square (similar to the way I did the contour interpolating).
1802

Now please explain what is the 'blend' in illustrator - I don't know what it is...

-Rob A>

ravells
11-29-2007, 10:28 AM
It's the same as interpolate.

bricka
11-29-2007, 10:34 AM
I think this is a good place to explain in more detail what I've already done about this; I've written a Python script which will interoplate between contours in a rather vanilla way. For each point not on a contour, it finds the closest points to the contours on either side and calculates the height according to the distances to these points, so if a point was halfway between the nearest points on each of the 1000 and 2000 metre contours, it would be set to 1500 metres. Points within the topmost contour line are interpolated relative to the top two contours, which seems the only sensible thing to do.

This works well enough for a first approximation, but it lacks detail and isn't very useful for my purposes, which require a lot more realism. I tried to make the results more realistic by incorporating some plasma-generated landscaping, without much success. Ideally my program could take a quantised heightmap, interpolate in between the discrete levels, and apply some magic to generate realistic-looking mountains and so on. Any ideas?

RobA
11-29-2007, 11:00 AM
Bricka-

How slow is it to process a large image?

-Rob A>

su_liam
11-29-2007, 11:39 AM
Funny coincidence. I've just been working on a similar problem. I was playing around with a heightfield I found on the net(I've been looking into the possibility of stitching together real-world heightmaps and subtly altering them to produce interesting and "realistic" extraterrestrial landscapes). The heightmap had serious stairsteps so, in Bryce, I used several iterations of the smoothing, noise, erode and eroded tools to obliterate the steps(mostly), and then applied a fractal at very low opacity on top of that. Thus far my methods aren't at all systematic(just to taste) and won't necessarily maintain the original landform with great fidelity.

Attached, I have an image generated from the original hf at upper left. From lower right clockwise: a heavily modified version(this was my second try, I lost the first one, which was my favorite :( ), a less modified version, and on the upper right a minimally modified version(this is about as much of the original structure as I could maintain without obvious stepping.

I'll try to add individual closeups and heightfields later. I'll also try to work out my methodology. This really isn't interpolation(since it doesn't maintain the existing contours), it's more like draping a canvas over a frame. Only the frame can get a little whacked out of shape.

RobA
11-29-2007, 01:54 PM
su_liam-

Can you post that original heightfield (as b/w or contour lines)?

It would be nice to have a standard example to play at with different techniques and compare the result.

-Rob A>

su_liam
11-29-2007, 02:34 PM
su_liam-

Can you post that original heightfield (as b/w or contour lines)?

It would be nice to have a standard example to play at with different techniques and compare the result.

-Rob A>

They're jpeg and not my original 16-bit tiffs, but here you go...

interpOrig.jpg is the original. Mmm, duh?
interpHeavy.jpg is the one at lower right.
interpModerate.jpg is the one at lower left.
interpLight.jpg is the one at upper right.

edit: just noticed how bryce pooped all over the original aspect ratio. Sorry 'bout that.

bricka
11-29-2007, 02:57 PM
Bricka-

How slow is it to process a large image?

It certainly wouldn't win any awards for speed; a file of a million pixels takes a few minutes.

Redrobes
12-06-2007, 07:47 PM
In terms of stitching arbitrary height maps may I point you at some work done by Howard Zhou who has been working on this sort of thing for a while...

http://terrain.cg-arts.org/forum/index.php?topic=88.msg821#msg821
http://www.howardzzh.com/research/terrain/

To keep it simple, I believe he is finding the closest path between two maps and cutting along them - a bit like photo stitching I think. I reckon there is a lot more to it tho. Its unbelievably awesome actually. Anyways there is a world machine plug in to do it.

HandsomeRob
12-07-2007, 09:29 AM
http://www.howardzzh.com/research/terrain/

That looks amazing. Being a professional cartographer I have a very large supply of real-world DEMs to use as source files, and it looks like this is just the application to create the mountain ranges, valleys, canyons, etc. for my world. But I could not find the download.

I WANT.

Redrobes
12-07-2007, 11:10 AM
The public interface to this utility is a plugin for WorldMachine.

http://www.terrainsynthesis.org/worldMachine/plugins/merger/index.htm

su_liam
02-11-2008, 03:51 PM
Okay, here's my experiment.

First, I took the quantized image and applied a 2.5-pixel Gaussian Blur to start. Next, I applied the Spatter filter at a radius of 8 and a smoothing of 1.

Next, I tried a smaller 1.3-pixel blur, and a spatter at the same settings as before. I repeated this a couple times.

I finally did a blur at 2.8 pixels to reduce the spots a bit.

This is what I was thinking of calling my Stochastic Deterrace Algorithm. I'm not sure how satisfactory this is. What do you think?

su_liam
02-11-2008, 04:06 PM
Next, I tried a morphological close operation: an erode followed by a dilate. I was hoping to denoise it a bit. Basically, I copied the image, pasted it as a channel. Used the channel as a selection then expanded the selection by one pixel, followed by a 1-pixel contraction of the selection. Then I saved the selection as a channel, copied the new channel and pasted it into a new layer. Didn't really help.

Finally, I tried Filter>Noise>Median... with a radius of 7 pixels. Here is the result.

See what you think?

su_liam
02-11-2008, 04:47 PM
I rendered the last heightfield in Bryce. There's a lot of moiré, edges are significantly rounded and there's still a very noticeable terracing.

I'm going to try applying just a touch of smoothing in bryce, but the SDA even with a last Median stage is feeling pretty busted. I had such high hopes, too...

RobA
02-12-2008, 10:09 PM
The banding was even noticeable in the greyscale version of the last one. Good try though!

-Rob A>