torchimage.cfa.bayer_conv package

Submodules

torchimage.cfa.bayer_conv.bayer_conv_2d module

Customized neural network layer for bayer array convolution 4 distinct filter groups for R, B, GR, and GB

class torchimage.cfa.bayer_conv.bayer_conv_2d.BayerConv2d(in_channels, out_channels, kernel_size, bias)

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor, sensor_alignment: str)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

forward_unshuffle(x: torch.Tensor, sensor_alignment: str)
training: bool
class torchimage.cfa.bayer_conv.bayer_conv_2d.BayerConv2dUnshuffle(in_channels, out_channels, kernel_size, bias)

Bases: torchimage.cfa.bayer_conv.bayer_conv_2d.BayerConv2d

forward(x: torch.Tensor, sensor_alignment: str)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class torchimage.cfa.bayer_conv.bayer_conv_2d.PreTrainedBilinearInterpolator(weight_dict: dict)

Bases: torch.nn.modules.module.Module

forward(x, sensor_alignment, clamp=1.0)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
torchimage.cfa.bayer_conv.bayer_conv_2d.get_padding_layer(kernel_size, beg_row, beg_col)
The padding layer accepts a batch of unsqueezed bayer arrays of shape (n_samples, c, height, width)

and returns the batch where the bayer arrays are padded (n_samples, c, height + kernel_size - 2, width + kernel_size - 2)

The padding layer serves 2 purposes: 1. Align the center of the convolutional kernel to the target pixels in the 2D bayer array.

Because the convolutional kernel always starts “sliding” at top left, we can control the offset (where the center is/where the kernel begins)

  1. Deal with borders elegantly. The intuition of bilinear interpolation stems from “taking the average of nearby

pixels” of nearest neighbor algorithms, so when the only available neighbors are on on side, taking just that neighbor’s value is equivalent to taking the average of two copies.

torchimage.cfa.bayer_conv.bayer_conv_2d.get_sensor_beg_index(sensor_alignment)

Input: sensor alignment specification (str) such as “GRBG” Output: dict that maps pixel type (i.e. GR for G at R row) to its starting index (i.e. (0, 0)) at mod 2

torchimage.cfa.bayer_conv.bayer_conv_2d.last_step_demosaic(x: torch.Tensor, y: torch.Tensor, sensor_alignment: str)

torchimage.cfa.bayer_conv.gradient_corrected module

Gradient-corrected bilinear interpolation, the algorithm in MATLAB’s demosaic function. Implemented as a collection of (5, 5) filters

Module contents

class torchimage.cfa.bayer_conv.BayerConv2d(in_channels, out_channels, kernel_size, bias)

Bases: torch.nn.modules.module.Module

forward(x: torch.Tensor, sensor_alignment: str)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

forward_unshuffle(x: torch.Tensor, sensor_alignment: str)
training: bool
class torchimage.cfa.bayer_conv.BayerConv2dUnshuffle(in_channels, out_channels, kernel_size, bias)

Bases: torchimage.cfa.bayer_conv.bayer_conv_2d.BayerConv2d

forward(x: torch.Tensor, sensor_alignment: str)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
torchimage.cfa.bayer_conv.last_step_demosaic(x: torch.Tensor, y: torch.Tensor, sensor_alignment: str)