prysm.bayer#

Basic operations for bayer data.

prysm.bayer.wb_prescale(mosaic, wr, wg1, wg2, wb, cfa='rggb', safe=False, saturation=None)#

Apply white-balance prescaling in-place to mosaic.

Parameters:
  • mosaic (ndarray) – ndarray of shape (m, n), a float dtype

  • wr (float) – red white balance prescalar

  • wg1 (float) – G1 white balance prescalar

  • wg2 (float) – G2 white balance prescalar

  • wb (float) – blue white balance prescalar

  • cfa (str, optional, {'rggb', 'bggr'}) – color filter arrangement

prysm.bayer.wb_postscale(rgb, wr, wg, wb, safe=False, saturation=None)#

Apply white balance post scaling in place.

Parameters:
  • rgb (ndarray) – ndarray of shape (m, n, 3), a float dtype

  • wr (float) – red white balance gain

  • wg (float) – green white balance gain

  • wb (float) – blue white balance gain

  • safe (bool, optional) – if True, clamps the gain of each color plane independently such that output <= saturation

  • saturation (float, optional) – saturation level, to be used when safe=True

prysm.bayer.composite_bayer(r, g1, g2, b, cfa='rggb', output=None)#

Composite an interleaved image from densely sampled bayer color planes.

Parameters:
  • r (ndarray) – ndarray of shape (m, n)

  • g1 (ndarray) – ndarray of shape (m, n)

  • g2 (ndarray) – ndarray of shape (m, n)

  • b (ndarray) – ndarray of shape (m, n)

  • cfa (str, optional, {'rggb', 'bggr'}) – color filter arangement

  • output (ndarray, optional) – output array, of shape (m, n) and same dtype as r, g1, g2, b

Returns:

array of interleaved data

Return type:

ndarray

prysm.bayer.decomposite_bayer(img, cfa='rggb')#

Decomposite an interleaved image into densely sampled color planes.

Parameters:
  • img (ndarray) – composited ndarray of shape (m, n)

  • cfa (str, optional, {'rggb', 'bggr'}) – color filter arangement

Returns:

  • r (ndarray) – ndarray of shape (m//2, n//2)

  • g1 (ndarray) – ndarray of shape (m//2, n//2)

  • g2 (ndarray) – ndarray of shape (m//2, n//2)

  • b (ndarray) – ndarray of shape (m//2, n//2)

prysm.bayer.recomposite_bayer(r, g1, g2, b, cfa='rggb', output=None)#

Recomposite raw color planes back into a mosaic.

This function is the reciprocal of decomposite_bayer

Parameters:
  • r (ndarray) – ndarray of shape (m, n)

  • g1 (ndarray) – ndarray of shape (m, n)

  • g2 (ndarray) – ndarray of shape (m, n)

  • b (ndarray) – ndarray of shape (m, n)

  • cfa (str, optional, {'rggb', 'bggr'}) – color filter arangement

  • output (ndarray, optional) – output array, of shape (2m, 2n) and same dtype as r, g1, g2, b

Returns:

array containing the re-composited color planes

Return type:

ndarray

prysm.bayer.demosaic_deinterlace(img, cfa='rggb')#

Demosaic an image by de-interlacing the channels.

This is the lowest quality of demosaicing, cutting image resolution by 2x in exchange for having no crosstalk between color channels. It is equivalent to decomposite_bayer, except the two green bands are averaged.

Parameters:
  • img (ndarray) – composited ndarray of shape (m, n)

  • cfa (str, optional, {'rggb', 'bggr'}) – color filter arangement

Returns:

shape (m//2, n//2, 3) trichromatic image

Return type:

ndarray

prysm.bayer.assemble_superresolved(r, g1, g2, b, zoomfactor, cfa='rggb', out=None)#

Assemble a trichromatic image from super-resolved color planes.

Parameters:
  • r (ndarray) – ndarray of shape (m, n) representing the R bayer color channel

  • g1 (ndarray) – ndarray of shape (m, n) representing the G1 bayer color channel

  • g2 (ndarray) – ndarray of shape (m, n) representing the G2 bayer color channel

  • b (ndarray) – ndarray of shape (m, n) representing the B bayer color channel

  • zoomfactor (float) – amount of upsampling applied, e.g. 500 => 1500; zoomfactor = 3

  • cfa (str, {'rggb', 'bggr'}) – color filter arrangement

  • out (ndarray) – array to place the output in, shape of (m,n,3) if None, freshly allocated

Returns:

array of shape (m, n, 3) containing the trichromatic image

Return type:

ndarray

prysm.bayer.demosaic_malvar(img, cfa='rggb')#

Demosaic an image using the Malvar algorithm.

Parameters:
  • img (ndarray) – ndarray of shape (m, n) containing mosaiced (interleaved) pixel data, as from a raw file

  • cfa (str, optional, {'rggb', 'bggr'}) – color filter arrangement

Returns:

ndarray of shape (m, n, 3) that has been demosaiced. Final dimension is ordered R, G, B. Is of the same dtype as img and has the same energy content and sense of z scaling

Return type:

ndarray