Source code for ecpi.common.num.extrapolate_image

'''
Created on 12 jul. 2019

@author: Bacon Philippe, APC/IN2P3/CNRS
'''

import numpy as np
from scipy.interpolate import interp2d


[docs]def extrapolate_edge(image): """Extrapolate edges of an image so as to find the image value at the edge of outer pixels. :param image: image to process of size MxN. :type image: array2D(float) :return: image of size (M+2)x(N+2). :rtype: array2D(float) """ # interpolate original image. x = np.linspace(0,image.shape[0]-1,image.shape[0]) y = np.linspace(0,image.shape[1]-1,image.shape[1]) f = interp2d(x,y,image.T,kind='cubic') # create extrapolated image. x_new = np.linspace(-1,image.shape[0],image.shape[0]+2) y_new = np.linspace(-1,image.shape[1],image.shape[1]+2) img_new = f(x_new, y_new) return img_new.T