pysilcam.background module

Moving background correction

use the backgrounder function!

acquire() must produce a float64 np array

pysilcam.background.backgrounder(av_window, acquire, bad_lighting_limit=None, real_time_stats=False)

Generator which interacts with acquire to return a corrected image given av_window number of frame to use in creating a moving background

Parameters
  • av_window (int) – number of images to use in creating the background

  • acquire (generator object) – acquire generator object created by the Acquire class

  • bad_lighting_limit=None (int) – if a number is supplied it is used for throwing away raw images that have a standard deviation in colour which exceeds the given value

Yields

timestamp (timestamp) – timestamp of when raw image was acquired imc (uint8) : corrected image ready for analysis or plotting imraw (uint8) : raw image

Useage:

avwind = 10 # number of images used for background imgen = backgrounder(avwind,acquire,bad_lighting_limit) # setup generator

n = 10 # acquire 10 images and correct them with a sliding background: for i in range(n):

imc = next(imgen) print(i)

pysilcam.background.correct_im_accurate(imbg, imraw)

Corrects raw image by subtracting the background and scaling the output

There is a small chance of clipping of imc in both crushed blacks an blown highlights if the background or raw images are very poorly obtained

Parameters
  • imbg (uint8) – background averaged image

  • imraw (uint8) – raw image

Returns

corrected image

Return type

imc (uint8)

pysilcam.background.correct_im_fast(imbg, imraw)

Corrects raw image by subtracting the background and clipping the ouput without scaling

There is high potential for clipping of imc in both crushed blacks an blown highlights, especially if the background or raw images are not properly obtained

Parameters
  • imbg (uint8) – background averaged image

  • imraw (uint8) – raw image

Returns

corrected image

Return type

imc (uint8)

pysilcam.background.ini_background(av_window, acquire)

Create and initial background stack and average image

Parameters
  • av_window (int) – number of images to use in creating the background

  • acquire (generator object) – acquire generator object created by the Acquire class

Returns

list of all images in the background stack imbg (uint8) : background image

Return type

bgstack (list)

pysilcam.background.shift_and_correct(bgstack, imbg, imraw, stacklength, real_time_stats=False)

Shifts the background stack and averaged image and corrects the new raw image.

This is a wrapper for shift_bgstack and correct_im

Parameters
  • bgstack (list) – list of all images in the background stack

  • imbg (uint8) – background image

  • imraw (uint8) – raw image

  • stacklength (int) – unsed int here - just there to maintain the same behaviour as shift_bgstack_fast()

  • real_time_stats=False (Bool) – if True use fast functions, if False use accurate functions

Returns

list of all images in the background stack imbg (uint8) : background averaged image imc (uint8) : corrected image

Return type

bgstack (list)

pysilcam.background.shift_bgstack_accurate(bgstack, imbg, imnew, stacklength)

Shifts the background by popping the oldest and added a new image

The new background is calculated slowly by computing the mean of all images in the background stack.

Parameters
  • bgstack (list) – list of all images in the background stack

  • imbg (uint8) – background image

  • imnew (unit8) – new image to be added to stack

  • stacklength (int) – unsed here - it is just there to maintain the same behaviour as shift_bgstack_fast()

Returns

bgstack (updated list of all background images) imbg (updated actual background image)

pysilcam.background.shift_bgstack_fast(bgstack, imbg, imnew, stacklength)

Shifts the background by popping the oldest and added a new image

The new background is appoximated quickly by subtracting the old image and adding the new image (both scaled by the stacklength). This is close to a running mean, but not quite.

Parameters
  • bgstack (list) – list of all images in the background stack

  • imbg (uint8) – background image

  • imnew (unit8) – new image to be added to stack

  • stacklength (int) – unsed int here - just there to maintain the same behaviour as shift_bgstack_fast()

Returns

bgstack (updated list of all background images) imbg (updated actual background image)