How to render a portion of an image?


#1

I would like to render just a portion of an image, say by giving bounding box XY pixel coordinates, and then replace that portion of the image on a full resolution image that I have previously rendered. For instance, I would render out an image, then I would realise I made a mistake in just an isolated area of the image - I would like to render just that part and “swap” it out with my new rendered portion to fix it.

I looked at rpiece and pcompos, which I think can do the job, but it seems quite manual, and in particular I would like to reuse the .rif file I use with rad so that all the settings are identical. Does anyone do this regularly and how do you do it?


#2

First, you can record the options used by rad with:

rad -v 0 input.rif OPT=saved.opt

These may be subsequently applied to rpict using:

rpict @saved.opt [view options] scene.oct > tile.hdr

You could then place the tile on top of the old image with:

pcompos orig.hdr 0 0 tile.hdr xleft ybottom > combined.hdr

The view options are the most troublesome to compute, and are done differently for different view types. You are on the right track looking at rpiece, and I think you can avoid the pcompos step by running rpiece on an uncompressed version of the image:

ra_rgbe orig.hdr uncompressed.hdr
echo tile_i tile_j | rpiece -x xres -y yres -X xdiv -Y ydiv @saved.opt -o uncompressed.hdr scene.oct

You need to divvy up the image so that the given tile coordinates overlap the area you are replacing. The xdiv and ydiv must divide the original image dimensions (xres and yres) exactly or this won’t work. Also, the “orig.hdr” image cannot have passed through pfilt or any other filter that might alter its pixel exposure.

Does this make sense?


#4

if your image has gone through pfilt and you do not have a RAWFILE specified in your rif file. And if your view is a perspective (-vtv) this may work:

rpict @saved.opt [view options] -vh VH -vv VV -vs VS -vl VL -x X -y Y scene.oct > tile.hdr

for example lets say your original resolution is 1000 and QUALITY=HIGH (so pfilt -x /3 -y /3), the dimensions of your final image are 1000x500, and you want to rerender a 100x100 square starting 100 pixels from the left and 400 pixels from the bottom (note that the pixel dimensions need to be an even dimension in both x and y, but the placement can be arbitrary, although that makes figuring out VS and VL tricky):

  • VH = (orig vh)/10
  • VV = (orig vv)/5 (note that in this case given we want a 100x100 output, VH == VV)
  • VS = -3.5 (with 10 divisions this ranges from -4.5 on the left to 4.5 on the right, 0 would render the center of the image)
  • VL = 2
  • X = 300 (100*3)
  • Y = 300 (100*3)

then run pfilt and pcompos on tile:

pfilt [get pfilt options from orig.hdr with getinfo] tile.hdr | pcompos orig.hdr 0 0 - 100 400 > combined.hdr

#5

Thanks for the help @Stephen_Wasilewski and @Greg_Ward!

I have decided rather than saving a saved.opt file, to simply create a new .rif file and run it through rad instead of using rpict or rpiece. I’ve chosen to do this because this allows me to take advantage of the -N option to use multiple CPU cores. This also hopefully preserves all of the render options.

I’ve followed your guidance on calculating the view options. I’m not entirely sure that the relationship suggested by VH = (orig vh)/10 and VV = (orig vv)/5 is correct. I’ve instead calculated my partial render dimensions as a fraction of the original sensor size of my virtual camera, and used that to recalculate VH and VV, like so:

partial_width_ratio = partial_width / original_width
vh2 = 2*atan(sensor_width*(partial_width_ratio)/(2*focal_length)))
vv2 = 2*atan(sensor_width*(partial_width_ratio)*(partial_height/partial_width)/(2*focal_length)))

This seems to calculate it properly, I think. However, due to rounding errors it can mean that the resulting patch can be a pixel or two squashed, as shown in the below image. For instance, my original image’s VH and VV give an output (aspect ratio) resolution of 1920x1080. I specified a region of 458x259 pixels to partially render and calculated VH2 and VV2 as above. When it actually rendered, however, despite my RESOLUTION=458 259 option in my .rif file, it created a 456x259 image, i.e., the width was 2 pixels less. When I rendered it I got this output:

rpiece: warning - resolution changed from 1374x777 to 1356x768

Another issue shown in the image is that obviously the partial render does not blend in completely seamlessly. Some can be explained due to the change in global illumination due to the added objects: for instance the orange glow on the wall caused by the new orange object.

However, this does not explain why the white wall and table does not blend in perfectly. Here is getinfo of the original render:

scene_v3.hdr:
        #?RADIANCE
        rpiece -F scene_v3_rpsync.txt -PP pf1vSUQY -t 15 -vh 71.07535558394876 -vv 43.7791135398094 -vp 0.28506553173065186 -2.0509257316589355 0.4600725769996643 -vd 0.5700837969779968 0.8215847015380859 0.0017081499099731445 -vu -0.0009908974170684814 -0.001391477882862091 0.9999985098838806 -x 5760 -y 3240 -dp 4096 -ar 128 -ms 0.14 -ds .2 -dt .05 -dc .75 -dr 3 -ss 16 -st .01 -ab 3 -af scene.amb -aa .1 -ad 1536 -as 768 -av 10 10 10 -lr 12 -lw 1e-5 -av 0 0 0 -ds .01 -dj .8 -dt 0 -aE exclude.txt -ps 3 -pt .04 -o scene_v3.unf scene.oct
        SOFTWARE= RADIANCE 4.2a lastmod Mon May 11 13:27:51 PDT 2015 by rgugliel on ubuntu
        VIEW= -vtv -vp 0.285066 -2.05093 0.460073 -vd 0.570084 0.821585 0.00170815 -vu -0.000990897 -0.00139148 0.999999 -vh 71.0754 -vv 43.7791 -vo 0 -va 0 -vs 0 -vl 0
        CAPDATE= 2018:12:07 22:02:14
        GMT= 2018:12:07 11:02:14
        FORMAT=32-bit_rle_rgbe
        pfilt -m .25 -x 1920 -y 1080 -p 1.000
        EXPOSURE=3.587490e-01

And here is the getinfo of the tile. As you can see the pfilt options are the same. So I’m not sure why there is a difference.

scene_tile2.hdr:
        #?RADIANCE
        rpiece -F scene_tile2_rpsync.txt -PP pfol0oHx -t 15 -vp 0.28506553173065186 -2.0509257316589355 0.4600725769996643 -vd 0.5700837969779968 0.8215847015380859 0.0017081499099731445 -vu -0.0009908974170684814 -0.001391477882862091 0.9999985098838806 -vh 19.34194228806581 -vv 11.00898690157091 -vs -0.31609599445167297 -vl -0.7955405384852003 -x 1374 -y 777 -dp 4096 -ar 128 -ms 0.14 -ds .2 -dt .05 -dc .75 -dr 3 -ss 16 -st .01 -ab 3 -af scene.amb -aa .1 -ad 1536 -as 768 -av 10 10 10 -lr 12 -lw 1e-5 -av 0 0 0 -ds .01 -dj .8 -dt 0 -aE exclude.txt -ps 3 -pt .04 -o scene_tile2.unf scene.oct
        SOFTWARE= RADIANCE 4.2a lastmod Mon May 11 13:27:51 PDT 2015 by rgugliel on ubuntu
        VIEW= -vtv -vp 0.285066 -2.05093 0.460073 -vd 0.570084 0.821585 0.00170815 -vu -0.000990897 -0.00139148 0.999999 -vh 19.3419 -vv 11.009 -vo 0 -va 0 -vs -0.316096 -vl -0.795541
        CAPDATE= 2018:12:23 00:08:05
        GMT= 2018:12:22 13:08:05
        FORMAT=32-bit_rle_rgbe
        pfilt -m .25 -x 458 -y 259 -p 1.000
        EXPOSURE=3.368380e-01

Finally you can notice a few new dots of dappled sunlight. Perhaps this is due to a bit of random sampling of the ray tracing, where some light have got through the leaves, I’m not sure.

Any help in explaining these anomalies would be much appreciated!