def compute_offset_ncc(dem1, dem2, pad=(<NUM_LIT:9>,<NUM_LIT:9>), prefilter=False, plot=False):
<EOL>if prefilter:<EOL><INDENT>print("<STR_LIT>")<EOL>sigma = <NUM_LIT:1><EOL>import scipy.ndimage<EOL>dem1 = malib.nanfill(dem1, scipy.ndimage.filters.gaussian_laplace, sigma) <EOL>dem2 = malib.nanfill(dem2, scipy.ndimage.filters.gaussian_laplace, sigma) <EOL><DEDENT>import scipy.signal<EOL>stride = <NUM_LIT:1><EOL>ref = dem1[::stride,::stride]<EOL>kernel = dem2[pad[<NUM_LIT:0>]:-pad[<NUM_LIT:1>]:stride, pad[<NUM_LIT:0>]:-pad[<NUM_LIT:1>]:stride]<EOL>ref = (ref - ref.mean()) / ref.std()<EOL>kernel = (kernel - kernel.mean()) / kernel.std()<EOL>print("<STR_LIT>")<EOL>ref_noise = ref.mask * (np.random.randn(*ref.shape))<EOL>kernel_noise = kernel.mask * (np.random.randn(*kernel.shape))<EOL>ref = ref.filled(<NUM_LIT:0>) + ref_noise<EOL>kernel = kernel.filled(<NUM_LIT:0>) + kernel_noise<EOL>print("<STR_LIT>" % (pad[<NUM_LIT:1>], pad[<NUM_LIT:0>]))<EOL>m = scipy.signal.correlate2d(ref, kernel, '<STR_LIT>')<EOL>print("<STR_LIT>")<EOL>int_argmax = np.array(np.unravel_index(m.argmax(), m.shape))<EOL>int_offset = int_argmax*stride - pad<EOL>print(m.argmax())<EOL>print(m.shape)<EOL>print(int_argmax)<EOL>print(int_offset)<EOL>sp_argmax = np.array(find_subpixel_peak_position(m, '<STR_LIT>'))<EOL>sp_offset = sp_argmax - pad<EOL>print(sp_argmax)<EOL>print(sp_offset)<EOL>if plot: <EOL><INDENT>fig, ax = plt.subplots()<EOL>ax.set_title('<STR_LIT>')<EOL>ax.imshow(m)<EOL>ax.scatter(*sp_argmax[::-<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>fig = None<EOL><DEDENT>return m, int_offset, sp_offset, fig<EOL>
Compute horizontal offset between input rasters using normalized cross-correlation (NCC) method