Learn R Programming

rayimage (version 0.2.3)

render_bokeh: Render Bokeh

Description

Takes an image and a depth map to render the image with depth of field (i.e. similar to "Portrait Mode" in an iPhone). User can specify a custom bokeh shape, or use one of the built-in bokeh types.

Usage

render_bokeh(
  image,
  depthmap,
  focus = 0.5,
  focallength = 100,
  fstop = 4,
  filename = NULL,
  preview = TRUE,
  preview_focus = FALSE,
  bokehshape = "circle",
  bokehintensity = 1,
  bokehlimit = 0.8,
  rotation = 0,
  gamma_correction = TRUE,
  progress = interactive()
)

Arguments

image

Image filename or 3-layer RGB array.

depthmap

Depth map filename or 1d array.

focus

Defaults 0.5. Depth in which to blur. Minimum 0, maximum 1.

focallength

Default 100. Focal length of the virtual camera.

fstop

Default 4. F-stop of the virtual camera.

filename

Default NULL. The filename of the image to be saved. If this is not given, the image will be plotted instead.

preview

Default TRUE. If FALSE, it will not display the image and just return the RGB array.

preview_focus

Default FALSE. If TRUE, a red line will be drawn across the image showing where the camera will be focused.

bokehshape

Default circle. Also built-in: hex. The shape of the bokeh. If the user passes in a 2D matrix, that matrix will control the shape of the bokeh.

bokehintensity

Default 1. Intensity of the bokeh when the pixel intensity is greater than bokehlimit.

bokehlimit

Default 0.8. Limit after which the bokeh intensity is increased by bokehintensity.

rotation

Default 0. Number of degrees to rotate the hexagonal bokeh shape.

gamma_correction

Default TRUE. Controls gamma correction when adding colors. Default exponent of 2.2.

progress

Default TRUE. Whether to display a progress bar.

Value

3-layer RGB array of the processed image.

Examples

Run this code
# NOT RUN {
#Plot the dragon
plot_image(dragon)

#Plot the depth map
image(dragondepth, asp = 1, col = grDevices::heat.colors(256))

#Preview the focal plane:
# }
# NOT RUN {
render_bokeh(dragon, dragondepth, focus=950, preview_focus = TRUE)
# }
# NOT RUN {
#Change the focal length:
# }
# NOT RUN {
render_bokeh(dragon, dragondepth, focus=950, focallength=300)
# }
# NOT RUN {
#Change the focal distance:
# }
# NOT RUN {
render_bokeh(dragon, dragondepth, focus=600, focallength=300)
render_bokeh(dragon, dragondepth, focus=1300, focallength=300)
# }
# NOT RUN {
#Change the bokeh shape to a hexagon:
# }
# NOT RUN {
render_bokeh(dragon, dragondepth, bokehshape = "hex",
            focallength=300, focus=600)
# }
# NOT RUN {
#Change the bokeh intensity:
# }
# NOT RUN {
render_bokeh(dragon, dragondepth,
            focallength=400, focus=900, bokehintensity = 1)
render_bokeh(dragon, dragondepth,
            focallength=400, focus=900, bokehintensity = 3)
# }
# NOT RUN {
#Rotate the hexagonal shape:
# }
# NOT RUN {
render_bokeh(dragon, dragondepth, bokehshape = "hex", rotation=15,
            focallength=300, focus=600)
# }

Run the code above in your browser using DataLab