yt.data_objects.image_array.ImageArray.add_background_color

ImageArray.add_background_color(background='black', inline=True)[source]

Adds a background color to a 4-channel ImageArray

This adds a background color to a 4-channel ImageArray, by default doing so inline. The ImageArray must already be normalized to the [0,1] range.

Parameters:

background: :

This can be used to set a background color for the image, and can take several types of values:

  • white: white background, opaque
  • black: black background, opaque
  • None: transparent background
  • 4-element array [r,g,b,a]: arbitrary rgba setting.

Default: ‘black’

inline: boolean, optional :

If True, original ImageArray is modified. If False, a copy is first created, then modified. Default: True

Returns:

out: ImageArray :

The modified ImageArray with a background color added.

Examples

>>> im = np.zeros([64,128,4])
>>> for i in range(im.shape[0]):
...     for k in range(im.shape[2]):
...         im[i,:,k] = np.linspace(0.,10.*k, im.shape[1])
>>> im_arr = ImageArray(im)
>>> im_arr.rescale()
>>> new_im = im_arr.add_background_color([1.,0.,0.,1.], inline=False)
>>> new_im.write_png('red_bg.png')
>>> im_arr.add_background_color('black')
>>> im_arr.write_png('black_bg.png')