# How can I resize a rendered ray traced image?

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?

• You can use any standard image downsampling method. There's nothing special about raytraced images that requires a different method. Apr 26, 2016 at 17:29
• 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.
– user2500
Apr 26, 2016 at 18:08
• 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? Apr 26, 2016 at 19:42

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.

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