slmsuite.holography.toolbox.unpad#

unpad(matrix, shape)[source]#

Helper function to unpad data. The padding is assumed to be centered. This is used to get higher resolution in the \(k\)-space upon Fourier transform.

Parameters:
  • matrix (numpy.ndarray OR (int, int)) – Data to unpad, if this is a matrix. If this is a shape in numpy (h, w) form, returns the four slicing integers used to unpad that shape [pad_b:pad_t, pad_l:pad_r].

  • shape ((int, int) OR None) – The desired shape of the matrix in numpy (h, w) form. If None, the matrix is returned unchanged.

Returns:

Either the unpadded matrix or the four slicing integers used to unpad such a matrix, depending what is passed as matrix.

Return type:

numpy.ndarray OR (int, int, int, int)