Convert [8*4] depth image into 32 depth image

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
feranti
Posts: 2
Joined: 2011-12-07T08:49:37-07:00
Authentication code: 8675308

Convert [8*4] depth image into 32 depth image

Post by feranti »

Hello everybody,

I have a specific need in image processing and I hope you can help me or orient me.
I need to output a 16 bits per channel (BPC) depth map from my 3D authoring tool (Virtools, for the record). I will be quick on details but I use a post-processing shader which generate this map :

Image

Internally in Virtools, this image has 32 BPC (and not 32 bits image: 8 BPC). But I cannot output it from Virtools in this pixel format. There is no way to do that.
The software only allows me to output it in 8 BPC and I lose all the depth details needed for an accurate use of this depthmap further in my workflow.
So I have modified my shader to write a grayscale 32 bits value in an 8 BPC image using the 8*4 bits of the image.
Here is the important part of the shader code :

Code: Select all

float distance ; // distance from the camera at this pixel
color.r = floor(distance)/256;
distance = frac(distance)* 256.0; // frac(x) is the fractional decimal part of the float [frac(x) = x - floor(x)] (for 23.6348 -> 0.6348)
color.g = floor(distance)/256;
distance = frac(distance)* 256.0;
color.b = floor(distance)/256;
distance = frac(distance)* 256.0;
color.a = floor(distance)/256;
which gives me this kind of psychedelic image :

Image

------------------------------------------------------------------------------------

And now... finally :), here is a simplified schema of the conversion I need to do in ImageMagick :

Image

I know that ImageMagick connat handle 32 BPC images but if I could have a 16 BPC greyscale image, it would be just fine !

Here is a post which seems to be useful :
viewtopic.php?f=1&t=19752

Thanks for advance for your advices.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert [8*4] depth image into 32 depth image

Post by fmw42 »

IM will handle 32-bits per channel if you compile IM with Q32 or 16-bits per channel if you install with Q16 (the default).

See binary releases available at http://www.imagemagick.org/download/www ... eases.html

See source code install at http://www.imagemagick.org/download/www ... ource.html
See advanced source code install notes at http://www.imagemagick.org/script/advan ... lation.php
See quantum depth at http://www.imagemagick.org/script/advan ... #configure
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert [8*4] depth image into 32 depth image

Post by fmw42 »

Sorry, posted to the wrong topic.
feranti
Posts: 2
Joined: 2011-12-07T08:49:37-07:00
Authentication code: 8675308

Re: Convert [8*4] depth image into 32 depth image

Post by feranti »

Ok! Thanks for the 32 bits depth IM trick! This will be useful.

Anybody could help me on the command line to use to do the conversion ?
Post Reply