8bit -> 16bit + "colorize"

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
wolas
Posts: 4
Joined: 2011-09-15T05:22:12-07:00
Authentication code: 8675308

8bit -> 16bit + "colorize"

Post by wolas »

I have grayscale 8bit image it serves as heightmap, and I want to convert it to 16bit heightmap. I also want to increase color count or how I should say... Algorithm which if sees if colurs was lineary decreasing then will add more values, if sees that color after color is same leave them. So basically I want remove "stairs" from my heightmap which is due 256 colours. Blur kinda works but isint perfect when colors is changing "slowly". Is there better way convert image and increase color count?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: 8bit -> 16bit + "colorize"

Post by anthony »

Okay increasing the saved image file 'depth' is not a problem. Just add -depth 16 just before the fine image save.

This however does not change the image depth or quality, while the image is in memory! That is a compile time setting. So increasing the color value quality is already done for you.
http://www.imagemagick.org/Usage/basics/#depth

ASIDE: be careful with the height map images. These are typically saved without any 'colorspace correction'. that is they are saved using a 'linear RGB' colorspace. in IM v6 this is the default, so you chould have no problems, but IM v7 and other image processing programs will typically automatically think of a saved image as using non-linear sRGB colorspace. Caution and testing is recommended.

For details about why images are typically saved using a non-linear colorspace corrected form see...
http://www.imagemagick.org/Usage/color_ ... perception

To the problem at hand...

The problem is that your hight map as been mangled, so as to produce 'staircased values'.
For an example of this see this example where a linear gradient was compressed to 4 bit depth/quality
http://www.imagemagick.org/Usage/basics ... um_effects

Now assuming that the height map is smooth, a blur should produce the right result. The problem is that if the image is not smooth, that is you have sudden 'jumps' or edges (cliffs in terms of a height map) then you need to try and preserve the sharpness of those edges.

This sounds more like adaptive-blur or possibly LAT image processing. IM has these, but I have not played with them much. Try out these local area operators, and let us know how they with before and after images, and the command.

The other suggestion I have is to find areas which are 'flat', and clear them (edge detect). You can then 'hole-fill' those flat areas to interpolate the values. See one example of hole filling images.
Sparse Color Shepards, a Blur Alternative
http://www.imagemagick.org/Usage/canvas/#sparse_blur

If you have a small example image I can experiment with it to see what I can do.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
wolas
Posts: 4
Joined: 2011-09-15T05:22:12-07:00
Authentication code: 8675308

Re: 8bit -> 16bit + "colorize"

Post by wolas »

Thanks for helpful answer, well I m creating it for game/engine "springrts", and my map isint significant or something it is not worth your time to be messed with. Somehow I thinked that this should be simple procedure/command.

Now I understand how powerful IM is, and now I know what I need to do exactly. I need to convert from digital "signal" to "analog" (kinda but algorythm should be same), in fact I even had done this in matlab in signal theory course, somehow didint even remembered it until you showed quantum links. Will try to do so :)
wolas
Posts: 4
Joined: 2011-09-15T05:22:12-07:00
Authentication code: 8675308

Re: 8bit -> 16bit + "colorize"

Post by wolas »

Found what I wanted -selective-blur works perfectly.
Post Reply