2
$\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$
3
  • 5
    $\begingroup$ You can use any standard image downsampling method. There's nothing special about raytraced images that requires a different method. $\endgroup$ Apr 26, 2016 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$
    – user2500
    Apr 26, 2016 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$
    – Byte Lab
    Apr 26, 2016 at 19:42

1 Answer 1

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.

$\endgroup$
2
  • $\begingroup$ I wonder if there are any high performance libraries out there instead of stb? Would halide support doing something like this? $\endgroup$
    – Byte Lab
    Apr 27, 2016 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$ Apr 28, 2016 at 15:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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