(src, dsize, ndValue)
return dst
Bilinear resizing with sparing out not defined parts of the depth map
        :param src: source depth map
        :param dsize: new size of resized depth map
        :param ndValue: value of not defined depth
        :return:resized depth map
Bilinear resizing with sparing out not defined parts of the depth map
        :param src: source depth map
        :param dsize: new size of resized depth map
        :param ndValue: value of not defined depth
        :return:resized depth map
Bilinear resizing with sparing out not defined parts of the depth map : param src : source depth map : param dsize : new size of resized depth map : param ndValue : value of not defined depth : return : resized depth map
def bilinearResize(src, dsize, ndValue):
        """
        Bilinear resizing with sparing out not defined parts of the depth map
        :param src: source depth map
        :param dsize: new size of resized depth map
        :param ndValue: value of not defined depth
        :return:resized depth map
        """

        dst = numpy.zeros((dsize[1], dsize[0]), dtype=numpy.float32)

        x_ratio = float(src.shape[1] - 1) / dst.shape[1]
        y_ratio = float(src.shape[0] - 1) / dst.shape[0]
        for row in range(dst.shape[0]):
            y = int(row * y_ratio)
            y_diff = (row * y_ratio) - y  # distance of the nearest pixel(y axis)
            y_diff_2 = 1 - y_diff
            for col in range(dst.shape[1]):
                x = int(col * x_ratio)
                x_diff = (col * x_ratio) - x  # distance of the nearest pixel(x axis)
                x_diff_2 = 1 - x_diff
                y2_cross_x2 = y_diff_2 * x_diff_2
                y2_cross_x = y_diff_2 * x_diff
                y_cross_x2 = y_diff * x_diff_2
                y_cross_x = y_diff * x_diff

                # mathematically impossible, but just to be sure...
                if(x+1 >= src.shape[1]) | (y+1 >= src.shape[0]):
                    raise UserWarning("Shape mismatch")

                # set value to ND if there are more than two values ND
                numND = int(src[y, x] == ndValue) + int(src[y, x + 1] == ndValue) + int(src[y + 1, x] == ndValue) + int(
                    src[y + 1, x + 1] == ndValue)
                if numND > 2:
                    dst[row, col] = ndValue
                    continue
                # print y2_cross_x2, y2_cross_x, y_cross_x2, y_cross_x
                # interpolate only over known values, switch to linear interpolation
                if src[y, x] == ndValue:
                    y2_cross_x2 = 0.
                    y2_cross_x = 1. - y_cross_x - y_cross_x2
                if src[y, x + 1] == ndValue:
                    y2_cross_x = 0.
                    if y2_cross_x2 != 0.:
                        y2_cross_x2 = 1. - y_cross_x - y_cross_x2
                if src[y + 1, x] == ndValue:
                    y_cross_x2 = 0.
                    y_cross_x = 1. - y2_cross_x - y2_cross_x2
                if src[y + 1, x + 1] == ndValue:
                    y_cross_x = 0.
                    if y_cross_x2 != 0.:
                        y_cross_x2 = 1. - y2_cross_x - y2_cross_x2

                # print src[y, x], src[y, x+1],src[y+1, x],src[y+1, x+1]
                # normalize weights
                if not ((y2_cross_x2 == 0.) & (y2_cross_x == 0.) & (y_cross_x2 == 0.) & (y_cross_x == 0.)):
                    sc = 1. / (y_cross_x + y_cross_x2 + y2_cross_x + y2_cross_x2)
                    y2_cross_x2 *= sc
                    y2_cross_x *= sc
                    y_cross_x2 *= sc
                    y_cross_x *= sc
                # print y2_cross_x2, y2_cross_x, y_cross_x2, y_cross_x

                if (y2_cross_x2 == 0.) & (y2_cross_x == 0.) & (y_cross_x2 == 0.) & (y_cross_x == 0.):
                    dst[row, col] = ndValue
                else:
                    dst[row, col] = y2_cross_x2 * src[y, x] + y2_cross_x * src[y, x + 1] + y_cross_x2 * src[
                        y + 1, x] + y_cross_x * src[y + 1, x + 1]

        return dst
def bilinearResize ( src , dsize , ndValue ) : dst = numpy . zeros ( ( dsize [ 1 ] , dsize [ 0 ] ) , dtype = numpy . float32 ) x_ratio = float ( src . shape [ 1 ] - 1 ) / dst . shape [ 1 ] y_ratio = float ( src . shape [ 0 ] - 1 ) / dst . shape [ 0 ] for row in range ( dst . shape [ 0 ] ) : y = int ( row * y_ratio ) y_diff = ( row * y_ratio ) - y # distance of the nearest pixel(y axis) y_diff_2 = 1 - y_diff for col in range ( dst . shape [ 1 ] ) : x = int ( col * x_ratio ) x_diff = ( col * x_ratio ) - x # distance of the nearest pixel(x axis) x_diff_2 = 1 - x_diff y2_cross_x2 = y_diff_2 * x_diff_2 y2_cross_x = y_diff_2 * x_diff y_cross_x2 = y_diff * x_diff_2 y_cross_x = y_diff * x_diff # mathematically impossible, but just to be sure... if ( x + 1 >= src . shape [ 1 ] ) | ( y + 1 >= src . shape [ 0 ] ) : raise UserWarning ( "Shape mismatch" ) # set value to ND if there are more than two values ND numND = int ( src [ y , x ] == ndValue ) + int ( src [ y , x + 1 ] == ndValue ) + int ( src [ y + 1 , x ] == ndValue ) + int ( src [ y + 1 , x + 1 ] == ndValue ) if numND > 2 : dst [ row , col ] = ndValue continue # print y2_cross_x2, y2_cross_x, y_cross_x2, y_cross_x # interpolate only over known values, switch to linear interpolation if src [ y , x ] == ndValue : y2_cross_x2 = 0. y2_cross_x = 1. - y_cross_x - y_cross_x2 if src [ y , x + 1 ] == ndValue : y2_cross_x = 0. if y2_cross_x2 != 0. : y2_cross_x2 = 1. - y_cross_x - y_cross_x2 if src [ y + 1 , x ] == ndValue : y_cross_x2 = 0. y_cross_x = 1. - y2_cross_x - y2_cross_x2 if src [ y + 1 , x + 1 ] == ndValue : y_cross_x = 0. if y_cross_x2 != 0. : y_cross_x2 = 1. - y2_cross_x - y2_cross_x2 # print src[y, x], src[y, x+1],src[y+1, x],src[y+1, x+1] # normalize weights if not ( ( y2_cross_x2 == 0. ) & ( y2_cross_x == 0. ) & ( y_cross_x2 == 0. ) & ( y_cross_x == 0. ) ) : sc = 1. / ( y_cross_x + y_cross_x2 + y2_cross_x + y2_cross_x2 ) y2_cross_x2 *= sc y2_cross_x *= sc y_cross_x2 *= sc y_cross_x *= sc # print y2_cross_x2, y2_cross_x, y_cross_x2, y_cross_x if ( y2_cross_x2 == 0. ) & ( y2_cross_x == 0. ) & ( y_cross_x2 == 0. ) & ( y_cross_x == 0. ) : dst [ row , col ] = ndValue else : dst [ row , col ] = y2_cross_x2 * src [ y , x ] + y2_cross_x * src [ y , x + 1 ] + y_cross_x2 * src [ y + 1 , x ] + y_cross_x * src [ y + 1 , x + 1 ] return dst