1
$\begingroup$

Say I have rendered an HDR ray traced image with dimensions 1920x1080 (width x height) pixels and I want to instead represent it with dimensions 960x540. Assume as well that the image has not yet been gamma corrected (i.e. it is still in linear space). How should I go about downsampling the image such that I don't need to re-render the image in the new dimensions?

$\endgroup$
  • 5
    $\begingroup$ You can use any standard image downsampling method. There's nothing special about raytraced images that requires a different method. $\endgroup$ – Nathan Reed Apr 26 '16 at 17:29
  • 1
    $\begingroup$ Is part of the question whether or not downsampling should be done in linear or gamma corrected space? Linear space is always appropriate - GPUs can apply a degamma-regamma when resolving gamma-corrected multisample buffers. $\endgroup$ – Daniel M Gessel Apr 26 '16 at 18:08
  • $\begingroup$ I'm not asking about whether it should be done in linear or gamma space (I know that it should be done in linear space). @NathanReed could you suggest an easy to implement one? $\endgroup$ – DIMMSum Apr 26 '16 at 19:42
5
$\begingroup$

Since you want to downsample the image by a factor of 2 along each axis, a simple and easy thing to do is just average a 2×2 box of source pixels to generate each destination pixel. In pseudocode this would look like:

for dest_y = 0 to 540
    src_y = dest_y*2
    for dest_x = 0 to 960
        src_x = dest_x*2
        average = 0.25 * (src[src_y][src_x] + src[src_y][src_x+1] +
                          src[src_y+1][src_x] + src[src_y+1][src_x+1])
        dest[dest_y][dest_x] = average

This will do an okay job, but for higher-quality downsampling or resizing images to any size (not just neat integer factors), I suggest looking at the stb_image_resize library. It's quite easy to use, supports either 8-bit or floating-point images with any number of channels, and gives good results.

| improve this answer | |
$\endgroup$
  • $\begingroup$ I wonder if there are any high performance libraries out there instead of stb? Would halide support doing something like this? $\endgroup$ – DIMMSum Apr 27 '16 at 21:52
  • $\begingroup$ @Decave I don't know off the top of my head, but I did find this image-resizing sample in the Halide repository. $\endgroup$ – Nathan Reed Apr 28 '16 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.