Convert tif, rgba16 to rgba8; Filling concaves of heightmap

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
Chronocide
Posts: 4
Joined: 2014-03-01T02:53:02-07:00
Authentication code: 6789

Convert tif, rgba16 to rgba8; Filling concaves of heightmap

Post by Chronocide »

ImageMagick looks awesome and very versatile.
Two things at the moment I'm wondering if and how ImageMagick could do:
1) Convert tif, rgba16 to rgba8. There's also something about orientation involved, as flipping occurs when down-sampling with photoshop.
2) World Machine has a snow function which fills concave areas, and spills over, much as you'd expect snow to do. But it adds overflow and mounds. I'm wondering if ImageMagick could do something similar, but simplified, as if with water levels, finding brightest rings of pixels encompassing darker areas, and filling them with like brightness.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by snibgo »

2) Some examples might explain the concept.
snibgo's IM pages: im.snibgo.com
Chronocide
Posts: 4
Joined: 2014-03-01T02:53:02-07:00
Authentication code: 6789

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by Chronocide »

Terrain without snow effect:
Image

With snow:
Image

Heightmap, before:
Image

After:
Image


It's snow device does snow well, but I can't get it to fill all concave areas without a bunch of overflow (it's a moderate amount in the example). I think some nice plateaus might be achieved if these concave areas could be filled to the 'brim' - the 'brim' being the brightest encircling ring of pixels, defining a region of darker pixels.
I think such a function would make lots of flat, traversable areas, at varying levels, for a somewhat noisy heightmap like that.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by snibgo »

Hmm, interesting problem. It really depends on the exact rules. Suppose we have a shallow basin next to a deeper basin, so there is a ridge between them. Some water (or snow) falls, so both basins have the same depth of water in them. More rain so the water levels rise until the shallow basin becomes full, level with the ridge. What happens them? Perhaps water spills over, instantly filling the deep basin. Or maybe the next rain makes no difference to the shallow basin because it is already full, so the level in only the deep basin rises.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by fmw42 »

Imagemagick does not have a "watershed" function. It is one of the feature that did not get implemented in the -morphology function.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by snibgo »

A watershed function is:

Code: Select all

%IM%convert ^
  %INFILE% ^
  ( +clone ^
    -statistic NonPeak 3x3 ^
  ) ^
  -compose MinusSrc -composite ^
  -fill white +opaque black ^
  %OUTFILE%
snibgo's IM pages: im.snibgo.com
Chronocide
Posts: 4
Joined: 2014-03-01T02:53:02-07:00
Authentication code: 6789

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by Chronocide »

"It is one of the feature that did not get implemented in the -morphology function"
Does that mean there's some un-implemented code lying around somewhere? :D


I've overlayed the result as black.
Image
That's interesting. It traced the convex edges, one pixel in width. Is that what it's supposed to do? I don't see any fill happening, and, it's a binary map.
I suppose it would be a good supply of starting points in finding areas to fill.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by fmw42 »

"It is one of the feature that did not get implemented in the -morphology function"
Does that mean there's some un-implemented code lying around somewhere?
No, not that I know about. It just never got implemented. I suspect Anthony either did not know about that function or just never got around to it, when he build the -morphology command.
Chronocide
Posts: 4
Joined: 2014-03-01T02:53:02-07:00
Authentication code: 6789

Re: Convert tif, rgba16 to rgba8; Filling concaves of height

Post by Chronocide »

This watershed thing is an interesting subject. I've found it lead into image scanning of grains of rice.
Post Reply