Processor
This module provides tools for processing and analyzing device matrices in nanofabrication prediction tasks. It includes functionality for image binarization, contour generation, and prediction uncertainty computation.
binarize
binarize(device, eta=0.5, beta=np.inf)
Applies soft binarization to a device image using a sigmoid function.
The binarization process can be controlled by adjusting the thresholding level (eta
) and the steepness of the sigmoid function (beta
). eta
influences the threshold level for binarization, simulating under-etching for smaller values and over-etching for larger values. beta
controls the steepness of the sigmoid function, thereby determining the degree of binarization.
Parameters
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the grayscale device image to be binarized.
- Name
eta
- Type
- float, optional
- Description
Threshold level for binarization, with values between 0 and 1. Default is 0.5.
- Name
beta
- Type
- float, optional
- Description
Controls the steepness of the sigmoid function and thereby the degree of binarization. Default is infinity, resulting in maximum binarization.
Returns
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the binarized device image.
binarize_hard
binarize_hard(device, eta=0.5)
Applies hard binarization to a device image using a step function.
The binarization process depends solely on the threshold level (eta
), which controls the demarcation point for determining the binary values in the output image. Smaller eta
values simulate under-etching (more pixels are turned off), while larger eta
values simulate over-etching (more pixels are turned on). Compared to the sigmoid binarization function, this hard binarization method is less likely to produce NaN values and may sometimes yield better results.
Parameters
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the grayscale device image to be binarized.
- Name
eta
- Type
- float, optional
- Description
Threshold level for binarization, with values between 0 and 1. Default is 0.5.
Returns
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the binarized device image.
ternarize
ternarize(device, eta1=0.33, eta2=0.66)
Applies ternarization to a device image using two thresholds.
This function performs a ternarization process on a given device image, dividing it into three distinct regions based on two threshold values (eta1 and eta2). It assigns three different values (0, 1, or 2) to each pixel based on its intensity in relation to the thresholds. Pixels with intensity less than eta1 are assigned 0, pixels with intensity greater than or equal to eta2 are assigned 2, and pixels with intensity between eta1 and eta2 are assigned 1. This function can be useful for categorizing different regions in a device image.
Parameters
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the grayscale device image to be ternarized.
- Name
eta1
- Type
- float, optional
- Description
First threshold level for ternarization, with values between 0 and 1. Default is 0.33.
- Name
eta2
- Type
- float, optional
- Description
Second threshold level for ternarization, with values between 0 and 1. Default is 0.66.
Returns
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the ternarized device image.
remove_padding
remove_padding(device)
Removes the empty padding from the edges of a device.
This function eliminates rows and columns from the edges of the device matrix that are entirely zeros, effectively removing any unnecessary padding present in the device representation.
Parameters
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the shape of a binary device.
Returns
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the shape of a device without any extraneous padding, of equal or smaller size compared to the input device.
zero_boundary
zero_boundary(device, margin)
Sets the boundaries of a device matrix to zero up to a specified margin.
This function zeroes the outermost rows and columns of the device matrix up to a distance (margin) from the boundaries, effectively creating a "zeroed" frame around the device representation.
Parameters
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the shape of a device.
- Name
margin
- Type
- int
- Description
The distance (in pixels) from the boundaries that should be zeroed.
Returns
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the shape of the device with its outermost rows and columns up to 'margin' distance set to zero.
generate_device_contour
generate_device_contour(device, linewidth=None)
Generates a contour of a device for visualization purposes.
This function generates a binary contour of a device's shape which can be overlaid on top of the device's image for better visualization. The thickness of the contour line can be specified, with a default value calculated as 1% of the device's height.
Parameters
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the device's shape.
- Name
linewidth
- Type
- int, optional
- Description
The width of the contour line. If not provided, the linewidth is set to 1% of the device's height.
Returns
- Name
device_contour
- Type
- np.ndarray
- Description
A 2D numpy array (same shape as the input device) representing the device's contour.
calculate_prediction_uncertainty
calculate_prediction_uncertainty(prediction)
Computes the uncertainty profile of a non-binary prediction matrix.
This function quantifies the level of uncertainty in a given prediction matrix by identifying the areas between the core (value 1) and cladding (value 0). These regions often correspond to the boundaries of the predicted structure and are represented by pixel values ranging between 0 and 1 in the prediction matrix. The function calculates the uncertainty as the distance from the pixel value to the nearest extreme (0 or 1), highlighting regions of maximum uncertainty.
Parameters
- Name
prediction
- Type
- np.ndarray
- Description
A 2D numpy array representing the non-binary prediction matrix of a device shape.
Returns
- Name
uncertainty
- Type
- np.ndarray
- Description
A 2D numpy array (same shape as the input prediction matrix) representing the uncertainty profile of the prediction. Higher values correspond to areas of higher uncertainty.
mse
mse(prediction, device)
Computes the mean squared error (MSE) between a prediction and a device matrix.
Parameters
- Name
prediction
- Type
- np.ndarray
- Description
A 2D numpy array representing the non-binary prediction matrix of a device shape.
- Name
device
- Type
- np.ndarray
- Description
A 2D numpy array representing the non-binary device matrix of a device shape.
Returns
- Name
mse
- Type
- float
- Description
The mean squared error between the prediction and device matrices.