plenpy.cameras package

Subpackages

Submodules

plenpy.cameras.abstract_camera module

Module defining the AbstractCamera base class.

This is the base class that all implemented cameras are derived from. The derived camera classes are defined in their respective modules.

class plenpy.cameras.abstract_camera.AbstractCamera(path)[source]

Bases: abc.ABC

AbstractCamera base class.

This is the base class that all actual camera classes are derived from. This class is abstract and objects cannot be initialized directly from it. Implements an API for all the basic functions needed by a camera model.

The structure of a camera folder has to be:

<camera-folder>

├── Images/

├── Calibration/

└── Reference/ [optional]

Variables
  • ~AbstractCamera.path (Path) – Absolute system path the main camera folder.

  • ~AbstractCamera.imageFolderPath (Path) – Relative path to image folder.

  • ~AbstractCamera.calibrationFolderPath (Path) – Relative path to calibration folder.

  • ~AbstractCamera.referenceFolderPath (Path) – Relative path to reference folder.

  • ~AbstractCamera._sensorImages (Dict[int, SensorImage]) – Dict of raw sensor images.

  • ~AbstractCamera._decodedImages (Dict[int, Union[ndarray, LightField]]) – Dict of decoded sensor images.

  • ~AbstractCamera._isCalibrated (bool) – Flag indicating camera’s calibration status.

AbstractCamera base class initialization.

Parameters

path (Any) – System path to the main camera folder.

_add_decoded_image(img, num)[source]

Add decoded image to dictionary of decoded images.

The dictionary of decoded images collects all decoded images. The function adds an image to that dictionary using the key which is specified by num.

Parameters
  • img (Union[ndarray, LightField]) – Decoded image to add.

  • num (int) – Number of the sensor image that the image is decoded from.

abstract calibrate()[source]

Calibrate the camera.

Calibrates the camera using the calibration metadata and/or the files provided in the Calibration/ subfolder. The implementation depends on the camera in use.

abstract decode_sensor_image(num)[source]

Decode a sensor image.

The implementation depends on the camera in use.

Parameters

num (int) – Number of the sensor image that is to be decoded.

get_decoded_image(num)[source]

Get decoded image.

Parameters

num (int) – Number of the sensor image that the image is decoded from.

Return type

Union[ndarray, LightField]

Returns

Decoded image decoded from sensor image of number num.

get_image_metadata(num)[source]

Get the metadata of a raw sensor image.

Parameters

num (int) – Specifies the number of the image to load the metadata from.

Return type

dict

Returns

Metadata of the raw sensor image specified by num.

get_sensor_image(num)[source]

Get a raw sensor image.

Parameters

num (int) – Specifies the number of the image to load.

Return type

ndarray

Returns

Sensor image of number num.

list_sensor_images()[source]

Print a list of sensor images.

Prints all sensor images found in the camera’s image subfolder. Denotes which images have been loaded.

load_sensor_image(num, format=None)[source]

Load a sensor image.

Parameters
  • num (Union[int, List[int], str]) – Specifies the number of the image to load. If a list is passed, multiple images are loaded. If “all” is specified, all images in the Images folder are loaded.

  • format (Optional[str]) – The image format to be used to read the file. By default, imageio selects an appropriate one based on the filename and its contents. Use plenpy.utilities.misc.get_avail_extensions() to get a list of available formats.

load_sensor_image_from_path(path, format=None)[source]

Load a sensor image from a system path image.

Parameters
abstract show_decoded_image(num)[source]

Show a decoded sensor image.

Shows the image decoded from sensor image num using matplotlib This can be a regular RGB image as well as a hyperspectral image or a plenpy.lightfields.LightField object.

Parameters

num (int) – Number of the sensor image that the image is decoded from.

show_image_metadata(num)[source]

Print the metadata of a raw sensor image.

Prints the metadata of the sensor image specified by num on the standard output.

Parameters

num (int) – Number of the sensor image.

show_sensor_image(num)[source]

Plot a raw sensor image.

Plots the sensor image specified by num using matplotlib.

Parameters

num (int) – Number of the sensor image to be plotted.

unload_sensor_image(num)[source]

Unload a sensor image.

Parameters

num (Union[int, List[int], str]) – Specifies the number of the image to load. If a list is passed, multiple images are loaded. If “all” is specified, all images in the Images folder are loaded.

plenpy.cameras.abstract_lightfield_camera module

Module defining the AbstractLightFieldCamera base class.

This bass class, derived from the AbstractCamera base class, implements methods that all microlens based light field cameras share. In particular, this class implements the estimation of an ideal grid from (a collection of) whiteimages.

class plenpy.cameras.abstract_lightfield_camera.AbstractLightFieldCamera(path, microlens_size, grid_type, ml_focal_length=None)[source]

Bases: plenpy.cameras.abstract_camera.AbstractCamera

AbstractLightFieldCamera base class.

This is the base class that all micro lens based light field camera classes are derived from. This class is abstract and objects cannot be initialized directly from it. Implements the basic functions needed by a light field camera model.

The abstract methods AbstractCamera.calibrate() and AbstractCamera.decode_sensor_image() are left undefined and have to be implemented by derived light field camera classes.

The camera inherits all attributes from the AbstractCamera class. Additional attributes are:

Variables
  • ~AbstractLightFieldCamera._microlensSize (float) – The microlens diameter in pixels.

  • ~AbstractLightFieldCamera._microlensRadius (float) – The microlens radius in pixels, derived from the microlens diameter.

  • ~AbstractLightFieldCamera._microlensFocalLength (float) – The (ideal) microlens focal length in meters (optional).

  • ~AbstractLightFieldCamera._calDataFilename (str) – The name of the calibration data file placed in the Calibration subfolder of the camera. Default is: cal_data.npz

AbstractLightFieldCamera base class initialization.

Parameters
  • path (Any) – System path to the main camera folder.

  • microlens_size (float) –

    Estimated size of the microlens diameter in pixels. For example:

    • Lytro Illum: 14

    • Lytro F01: 11

  • grid_type (str) – Grid type of the underlying microlens array. Either ‘hex’ or ‘rect’.

  • ml_focal_length (Optional[float]) – Focal length of the micro lenses in meters (optional).

_align_image(img, wi_idx)[source]

Align to sensor image with the microlens array.

Image is rotated, scaled and translated, so that all microlens centers fall onto pixel centers and rotation is compensated. Bicubic itnerpolation is performed by default.

Parameters
  • img (ndarray) – Input sensor image to be aligned.

  • wi_idx (int) – Index of the white image with zoom and focus parameters closest to input image.

Return type

ndarray

Returns

The aligned output image.

static _calc_grid_params_helper(x, im, f_mat, hires)[source]

Helper function to calculate spacing and rotation from a white image using different hyperparameters.

Parameters
  • x – Hyperparameter vector. x = [x_q, x_gamma, x_exponent], where - q is pixel value lower bound used for contrast stretching - gamma is gamma correction factor used for value stretching - exponent is the exponent used in the center of mass calculation Note that x is normalized in [0, 1]^3

  • im – Input white image.

  • f_mat – Pre-calculated basis frequency vectors.

  • hires – Whether to use hires FFT (zero padding) and return full grid values.

  • show – Whether to show intermediate results for debugging.

Return type

Union[Tuple[float, float, float, float], float]

Returns

spacing_std [if hires == False] or Tuple (spacing, spacing_std, rot, rot_std) [if hires == True]

_create_wi_db()[source]

Create the white image database and save to self._whiteImageDb.

static _crop_ml_centers(ml_centers, size, crop)[source]

Crop ml center coordinates by crop amount to get rid of edge defects

_est_grid(method='own')[source]

Estimate regular grid(s) that best fits the white image(s). For every white image in the Calibration folder, a regular grid is estimated.

Parameters

method (str) – Method for grid estimation. Choices are: - ‘own’: Proposed method [ref] - ‘dans’: Dansereau et al.

static _est_grid_offset_dans(wi, ml_centers, spacing_est, rotation_est, grid_type, show=False)[source]

Estimate overall grid offset.

Parameters
  • wi (ndarray) – White image

  • show (bool) – Whether to show results for debugging.

Return type

float

Returns

Estimated grid offset

static _est_grid_offset_prop(wi, lam_est, spacing_est, rotation_est, grid_type)[source]

Estimate overall grid offset.

Parameters
  • wi (ndarray) – White image

  • lam_est (float) – Estimated magnification factor lam = (F +f) / F

  • show – Whether to show results for debugging.

Return type

float

Returns

Estimated grid offset

static _est_grid_params_prop_hex(wi)[source]

Estimate the grid parameters of a hex grid in the Fourier domain.

This algorithm follows the presentation in [PAPER]. The white image is fourier transformed and peaks are detected corresponding to the frequencies of the spatial basis vectors. From these, spacing and rotation are estimtaed.

Return type

Tuple[float, float, float, float]

Returns

spacing, alpha Spacing vector and rotation of the grid in radians.

static _est_offset(grid_type, ml_centers, size, spacing_est, rotation_est, offset_init=None, window=None)[source]

Estimate a grid offset from estimated ml_centers of a white image.

Parameters

Returns:

static _get_align_transform(ideal_grid_params)[source]

Calculate transformation that is used to align the images.

Return type

Tuple[GridParameters, AffineTransform]

_get_calibration_db_entry(path, method, ideal_grid_params, align_grid_params, align_transform)[source]

Get a single entry for the calibration database.

Parameters
  • path (Path) – Path to the corresponding white image.

  • method (str) – Method used for calibration.

  • ideal_grid_params (GridParameters) – The ideal grid parameters.

  • align_grid_params (GridParameters) – The aligned grid parameters.

  • align_transform (AffineTransform) – The transformation needed for alignment.

Return type

ndarray

Returns

A structured numpy array with the needed data.

static _get_fourier_peaks(wi_fft, constrained, exponent=2.0)[source]

Find peaks in absolute value of a Fourier transform of an image.

Parameters
  • wi_fft (ndarray) – Input, FFT of an image. Should be of uneven shape, so that conversion to frequency units 1/px is correct.

  • constrained (bool) – Whether to constrain the number of returned peaks.

  • exponent (float) – Exponent of the center of mass calculation around each peak.

Return type

ndarray

Returns

Peak coordinates (p_x, p_y) as Numpy array of shape (N, 2) in units 1/px.

static _get_grid_params_dans_hex(ml_centers, spacing_guess, rot_guess, wi, show=False)[source]

Grid parameter estimation as implemented by Dansereau in the MATLAB Light Field Toolbox v0.4.

The grid is traversed horizontally and vertically, performing line fits to estimate the grid rotation. For this a prior spacing and rotation estimate is necessary.

Spacing is calculated as the mean distance of grid neighbors in the corresponding grid direction.

Parameters
  • ml_centers (ndarray) – Estimated micro lens centers to be used for grid estimate.

  • spacing_guess (float) – A prior estimation of the grid spacing in y-direction.

  • rot_guess (float) – A prior estimation of the grid rotation in radians.

  • show (bool) – Boolean flag indicating whether to plot results for debugging.

  • white_img – White image. Only used for plotting.

Return type

Tuple[ndarray, float]

Returns

Estimated spacing (2D array) and rotation (in radians) of the grid. If not estimate is possible, returns nans.

_get_ideal_grid_params(method, wi, args)[source]

Estimate a regular grid from a white image using the specified method.

Parameters
  • method (str) – Method used for estimation. One of “prop”, “dans”.

  • wi (ndarray) – White image used for estimation in range [0, 1]

  • args (dict) – Dictionary of arguments passed to the respective method.

Return type

GridParameters

Returns

Ideal grid parameters estimated from the white image.

static _get_ml_centers_dans(wi)[source]

Calculat ML centers from WI, method proposed by Dansereau et al. in Matlab LightField Toolbox.

Parameters

wi (ndarray) – White image used for estimate.

Return type

ndarray

Returns

Estimated ml center coordinates in shape (N, 2).

static _get_ml_centers_prop(wi, lam_est)[source]

Estimate ml centers in only central part of the white image

Parameters
  • wi (ndarray) – White image.

  • lam_est (float) – Estimated magnification factor lambda.

Return type

Tuple[ndarray, ndarray]

Returns

Microlens center coordinates as ndarray of shape (N, 2).

abstract _get_wi(path, process=True)[source]

Read the white image from path and perform preprocessing such as contrast stretching, normalization, etc., if desired.

Parameters
  • path (Path) – Path to the white image, relative to Calibration folder.

  • process (bool) – Whether to perform preprocessing such as contrast stretching.

Returns

White image as float in range [0, 1].

abstract _get_wi_db_entry(path)[source]

Get a single entry for the white image database.

The type of entry depends on the actual camera. Must contain a ‘focal_length’ entry. This could for example be focus and zoom settings of the white image or gamma settings etc.

Parameters

path (Path) – path: Path to the white image, relative to Camera main folder. Used as database identfication

Return type

Optional[ndarray]

Returns

A ndarray (best a structured array) with the needed infos from the whiteimage. If no metadata is available for the camera, should return None.

_load_cal_data(filename=None)[source]

Load the calibration data from the calibration data file.

Parameters

filename (Optional[Any]) – Calibration data filename. Specify only if it deviates from the default value.

_resample_lf(lf, method)[source]

Resample from a hexagonally sampled to rectangular sampled image.

Parameters
  • lf (LightField) – Light field to resample.

  • method (str) – Resampling method. Available: - ‘guided’: Perform gradient guided interpolation (recommended) - ‘bilinear’ : Perform bilinear interpolation. - ‘horizontal’: Only use horizontal 1D-interpolation - ‘vertical’: Only use vertical 1D-interpolation

Returns:

_save_cal_data(filename=None)[source]

Save the calibration data.

The calibration data is saved as a compressed numpy array file in the camera’s Calibration folder.

_slice_image(img, wi_idx)[source]

Slice image into a light field.

Parameters
  • img (ndarray) – Input raw image.

  • wi_idx (int) – Index of the white image with zoom and focus parameters closest to input image.

Return type

LightField

Returns

Decoded light field.

_update_wi_db()[source]

Update the white image database and save to self._whiteImageDb.

get_ml_centers(wi_idx)[source]
show_decoded_image(num)[source]

Show the decoded light field using plenpy.lightfields.lightfield.LightField.show_interactive() .

Parameters

num (int) – Number of the sensor image that the image is decoded from.

show_microlens_centers(wi_idx, grid=False, plt_show=True)[source]

Show the calculated microlens centers on top of the whiteimage.

Parameters
  • wi_idx (int) – Index of the corresponding white image.

  • grid (bool) – Whether to also show the estimated ideal grid on top

  • plt_show (bool) – Whether matplotlib.pyplot.show() is called at the end of the function

plenpy.cameras.generic_lightfield_camera module

plenpy.cameras.lytro_illum module

Module defining the LytroIllum camera class.

This camera class, derived from the AbstractLightFieldCamera base class, implements the Lytro Illum camera.

class plenpy.cameras.lytro_illum.LytroIllum(path, format='LYTRO-ILLUM-RAW')[source]

Bases: plenpy.cameras.abstract_lightfield_camera.AbstractLightFieldCamera

Lytro Illum light field camera.

The class does not add any attributes to the AbstractLightFieldCamera base class.

Parameters
  • path (Any) – Folder path of camera.

  • format – The imageio format of the white images. Default: LYTRO-ILLUM-RAW.

_crop_raw(im)[source]

Crop original raw sensor image to specified slices

static _get_focal_length(zoom_step)[source]

Calculate focal length in meter from zoom_step setting.

Uses a cubic function obtained via least squares fit of data measured with a Lytro Illum Camera.

_get_wi(path, process=False, meta_only=False)[source]

Read the white image from path and perform preprocessing such as contrast stretching, normalization, etc.

Parameters
  • path (Path) – Path to the white image, relative to camera folder.

  • process (bool) – Whether to perform preprocessing such as contras stretching.

Returns

White image as float in range [0, 1].

_get_wi_db_entry(path)[source]

Get the database entry for a white image. Entries include the zoomStep and focusStep setting of the white image to be used for decoding.

Parameters
  • path (Path) – Path to the white image, relative to Camera main folder. Used as database identfication

  • metadata – The metadata to the whiteimage

Return type

ndarray

Returns

A structured array containing the path, focal_length, zoomStep and focusStep setting of the white image.

_validate_crop()[source]

Check whether set crop slice are valid.

calibrate(filename=None, method='own', force=False)[source]

Calibrate the Lytro Illum camera.

The calibration estimates the microlens centers from the provided white images. Based on the chosen method, this will yield ml centers with (det_method='own') or without (det_method='dans') subpixel precision. Using the estimated ML centers, an ideal grid is estimated that best approximates the ML centers. This grid is used in the decoding of every light field (depending on the zoom and focus settings).

Parameters
  • filename (Optional[str]) – System path to calibration filename withoout extension. If None, the standard path is used.

  • method (str) – Method used for grid estimation. - ‘own’: Own method, proposed in [ref] - ‘dans’: Method by Dansereau et al.

  • force (bool) – If True forces the recalibration, even if a calibration file is found. This can be useful when recalibrating with different parameters.

decode_sensor_image(num, demosaic_method='malvar2004', resample_method='guided')[source]

Decode the specified sensor image.

The decoding yields a plenpy.lightfields.lightfield.LightField object that is added the objects dictionary of decoded images.

Parameters
  • num (int) – Number of the sensor image that is to be decoded.

  • demosaic_method (str) – Method used to calculate the demosaiced image. If None is specified, no demosaicing is performed. For available methods and default value, see plenpy.utilities.demosaic.get_demosaiced().

  • resample_method (str) – Method used to resample the light field from a hex to rect grid. Available: - ‘guided’: Perform gradient guided interpolation (recommended) - ‘bilinear’ : Perform bilinear interpolation. - ‘horizontal’: Only use horizontal 1D-interpolation - ‘vertical’: Only use vertical 1D-interpolation

static unique_exposure_gen(db, paths_processed)[source]

Generator to yield unique exposure and iso values from a raw database together with the correpsoning current database and paths.

Parameters
  • db – Raw image database to process.

  • paths_processed – Paths of raw images that have already been processed

Yields

tmp_db, paths_curr, exposure, iso

static unique_geometry_exposure_gen(db, paths_processed)[source]

Generator to yield unique zoom, focus, exposure and iso values from a raw database together with the correpsoning current database and paths.

Parameters
  • db – Raw image database to process.

  • paths_processed – Paths of raw images that have already been processed

Yields

tmp_db, paths_curr, exposure, iso, focus_step, zoom_step

plenpy.cameras.ms_lytro module

Module defining the MsLytro camera class.

This camera class, derived from the AbstractLightFieldCamera base class, implements a prototype multispectral Lytro Illum camera.

class plenpy.cameras.ms_lytro.MsLytro(path, num_channels=13, format='LYTRO-ILLUM-RAW')[source]

Bases: plenpy.cameras.lytro_illum.LytroIllum

Multispectral Lytro Illum light field camera.

Parameters
  • path (Any) – Folder path of camera.

  • num_channels (int) – Number of spectral channels.

  • format – The imageio format of the white images. Default: LYTRO-ILLUM-RAW.

_create_ms_wi_db()[source]

Returns:

_get_ms_wi(folder, dtype=<class 'numpy.float64'>, process=False, multi_exposure=False, return_meta=False, meta_only=False)[source]

Read a multispectral white image from a folder and perform preprocessing such as contrast stretching, normalization, etc.

Parameters
  • folder (Path) – Folder path to the multispectral white image, relative to camera folder.

  • dtype – Which dtype to convert to after loading. Defaults to float64.

  • process (bool) – Whether to perform preprocessing such as contrast stretching.

  • return_meta – Whether to return the metadata dict.

Returns

Multispectral white image as ndarray and metadata.

_get_ms_wi_db_entry(folder)[source]

Get the database entry for a white image. Entries include the zoomStep and focusStep setting of the white image to be used for decoding.

Parameters

folder (Path) – Folder path containing the multispectral white image.

Return type

ndarray

Returns

A structured array containing the folder, focal_length, zoomStep and focusStep setting of the white image.

_load_cal_data(filename=None)[source]

Load the calibration data from the calibration data file.

Parameters

filename (Optional[Any]) – Calibration data filename. Specify only if it deviates from the default value.

_read_ms_raw(folder, dtype=<class 'numpy.float64'>, multi_exposure=False, meta_only=False)[source]

Reads a single multispectral raw light field. All raw data must be contained in a single folder with alphanumerically sorted filenames according to the corresponding spectral channel index order.

Checks data for consistency regarding the camera serial number, the ISO setting and the exposure time.

Parameters
  • folder (Path) – Folder containing the raw measurements per channel. The folder is searched recursively.

  • dtype – Dtype used for loading.

  • multi_exposure – Whether to allow multi-exposure series.

  • meta_only – Whether to only read the metadata.

Return type

Tuple[ndarray, dict]

Returns

Spectral raw data of shape (num_channels, x, y)

_save_cal_data(filename=None)[source]

Save the calibration data.

The calibration data is saved as a compressed numpy array file in the camera’s Calibration folder.

decode_image(folder, resample_method='guided')[source]

Decode a multispectral light field

The decoding returns a plenpy.lightfields.lightfield.LightField object.

Parameters
  • folder (str) – Path to multispectral raw data folder.

  • resample_method (str) – Method used to resample the light field from a hex to rect grid. Available: - ‘guided’: Perform gradient guided interpolation (recommended) - ‘bilinear’ : Perform bilinear interpolation. - ‘horizontal’: Only use horizontal 1D-interpolation - ‘vertical’: Only use vertical 1D-interpolation

static fit_linear_full(data, exposures, dark_current, dark_offset, epochs=2000, learning_rate=0.01, **kwargs)[source]
Parameters
  • data (List[ndarray]) – List of Numpy arrays (possibly with ‘r’ memmap) of shape (x, y) or (ch, x, y) with list length T.

  • exposures (ndarray) – Numpy array with reference exposures of shape (T, ).

  • method – Either “numpy” using CPU or “torch” using GPU acceleration.

  • **kwargs

Return type

Tuple[ndarray, ndarray]

Returns

responsivity, offset

static fit_linear_pixel_wise(data, exposures, dark_current, dark_offset, **kwargs)[source]
Parameters
  • data (List[ndarray]) – List of Numpy arrays (possibly with ‘r’ memmap) of shape (x, y) or (ch, x, y) with list length T.

  • exposures (ndarray) – Numpy array with reference exposures of shape (T, ).

  • method – Either “numpy” using CPU or “torch” using GPU acceleration.

  • **kwargs

Return type

Tuple[ndarray, ndarray]

Returns

responsivity, offset

static unique_ms_wi_gen(db, paths_processed)[source]

Generator to yield unique zoom, focus, and iso values from the multispectral white image database together with the corresponding current database and paths.

Parameters
  • db – Raw image database to process.

  • paths_processed – Paths of raw images that have already been processed

Yields

tmp_db, paths_curr, exposure, iso, focus_step, zoom_step

plenpy.cameras.raytracer_lightfield_camera module

Module defining the RayTracerLF camera class.

This camera class, derived from the AbstractLightFieldCamera base class, implements a MLA based light field camera synthesized by the IIIT-RayTracer.

class plenpy.cameras.raytracer_lightfield_camera.RayTracerLF(path, grid_type='hex', ml_size=14, ml_focal_length=4e-05, format='PNG-FI')[source]

Bases: plenpy.cameras.abstract_lightfield_camera.AbstractLightFieldCamera

Raytracer implementation of MLA based LF camera.

The class does not add any attributes to the AbstractLightFieldCamera base class.

AbstractLightFieldCamera base class initialization.

Parameters
  • path (Any) – System path to the main camera folder.

  • microlens_size

    Estimated size of the microlens diameter in pixels. For example:

    • Lytro Illum: 14

    • Lytro F01: 11

  • grid_type (str) – Grid type of the underlying microlens array. Either ‘hex’ or ‘rect’.

  • ml_focal_length (float) – Focal length of the micro lenses in meters (optional).

_create_wi_db()[source]

Create the white image database and save to self._whiteImageDB.

_get_metadata(path)[source]

Get the metadata from a raytracer image using its JSON file.

Parameters

path (Path) – Path to the white image, relative to Calibration folder.

_get_wi(path, process=True)[source]

Read the white image from path and perform preprocessing such as contrast stretching, normalization, etc.

Parameters
  • path (Path) – Path to the white image, relative to Calibration folder.

  • process (bool) – Whether to perform preprocessing such as contras stretching.

Returns

White image as float in range [0, 1].

_get_wi_db_entry(path)[source]

Get the database entry for a white image. Entries include the focal_length and focus_distance setting of the white image to be used for decoding.

Parameters

path (Path) – Path to the white image, relative to Camera main folder. Used as database identfication

Return type

ndarray

Returns

A structured array containing the path, focal_length and focus_distance.

calibrate(filename=None, method='own', force=False)[source]

Calibrate the RayTracer camera.

See Also: :func:LytroIllum.calibrate()

Parameters
  • filename (Optional[Any]) – System path to calibration filename withoout extension. If None, the standard path is used.

  • method (str) – Method used for grid estimation. - ‘own’: Own method, proposed in [ref] - ‘dans’: Method by Dansereau et al.

  • force (bool) – If True forces the recalibration, even if a calibration file is found. This can be useful when recalibrating with different parameters.

decode_sensor_image(num, resample_method='guided')[source]

Decode the specified sensor image.

The decoding yields a plenpy.lightfields.lightfield.LightField object that is added the objects dictionary of decoded images.

Parameters
  • num (int) – Number of the sensor image that is to be decoded.

  • resample_method (str) – Method used to resample the light field from a hex to rect grid. Available: - ‘guided’: Perform gradient guided interpolation (recommended) - ‘bilinear’ : Perform bilinear interpolation. - ‘horizontal’: Only use horizontal 1D-interpolation - ‘vertical’: Only use vertical 1D-interpolation

plenpy.cameras.rgb_camera module

Module defining the RgbCamera class.

class plenpy.cameras.rgb_camera.RgbCamera(path, bayer_pattern)[source]

Bases: plenpy.cameras.abstract_camera.AbstractCamera

Basic RGB camera.

This class is a very basic camera class illustrating the implementation of the necessary class methods such as calibration and decoding. The RGB camera decoding process is in this case just a simple demosaicing of the raw sensor image.

Todo: Implement the calibration of a camera model, e.g. to do rectification of the images.

Variables

~RgbCamera._bayerPattern (str) – The camera’s mosaicing Bayer pattern.

RgbCamera class initialization.

Parameters
calibrate()[source]

Calibrate the camera.

Calibrates the camera using the calibration metadata and/or the files provided in the Calibration/ subfolder. The implementation depends on the camera in use.

decode_sensor_image(num, method='malvar2004')[source]

Decode the sensor image of the RGB Camera.

This is just a demosaicing of the monochromatic sensor image to obtain a RGB color image.

Parameters
show_decoded_image(num, plt_show=True)[source]

Show the decoded image using matplotlib.

Parameters
  • num (int) – Number of the sensor image that the image is decoded from.

  • plt_show (bool) – Flag indicating whether to call matplotlib.pyplot.show() at the end.

Module contents

The camera package of plenpy.

The package provides a framework to implement camera models as well as pre developed cameras such as a basic plenpy.cameras.rgb_camera.RgbCamera or light field cameras such as the plenpy.cameras.lytro_illum.LytroIllum camera.

The framework provides an API to implement own camera modules (or classes).