def unpadding(signal, dim): y, x = dim sy, sx = signal.shape y0 = int(np.trunc((sy-y) / 2)) x0 = int(np.trunc((sx-x) / 2)) yt = int(y0 + y) xt = int(x0 + x) return signal[y0:yt, x0:xt]
def unpadding(signal, dim): y, x = dim sy, sx = signal.shape y0 = np.trunc((sy-y) / 2) x0 = np.trunc((sx-x) / 2) yt = y0 + y xt = x0 + x return signal[y0:yt,x0:xt]
def zero_padding(signal, squared=True): """Creates a new ndarray that """ check_dim(signal, 2) rows, cols = signal.shape pow_rows = int(np.ceil(np.log2(rows))) pow_cols = int(np.ceil(np.log2(cols))) if squared: if pow_cols > pow_rows: pow_rows = pow_cols else: pow_cols = pow_rows padded_signal = np.zeros((2 ** pow_rows, 2 ** pow_cols), dtype=signal.dtype) y_0 = np.trunc((2 ** pow_rows - rows) / 2) y_t = y_0 + signal.shape[0] x_0 = np.trunc((2 ** pow_cols - cols) / 2) x_t = x_0 + signal.shape[1] padded_signal[y_0:y_t, x_0:x_t] = signal return padded_signal