Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/amazon-web-services/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python中的数组/图像插值_Python_Arrays_Numpy_Pixel_Interpolation - Fatal编程技术网

python中的数组/图像插值

python中的数组/图像插值,python,arrays,numpy,pixel,interpolation,Python,Arrays,Numpy,Pixel,Interpolation,我一年中每天都有365个2dnumpy阵列,显示如下图像: 我把它们都堆成了一个3d小数组。像素的值表示我要去除的云,我要搜索前7天或后7天(前7层,后7层)以查找云以外的值,然后用该像素的其他可能值(其他天/层中对应像素的值)替换云值 我是python新手,有点迷路了 有什么想法吗 谢谢我想你可以做如下事情: data = somehow_get_your_3d_data() #indexed as [day_of_year,y,x] for i,dat in enumerate(data)

我一年中每天都有365个2d
numpy
阵列,显示如下图像:

我把它们都堆成了一个3d小数组。像素的值表示我要去除的云,我要搜索前7天或后7天(前7层,后7层)以查找云以外的值,然后用该像素的其他可能值(其他天/层中对应像素的值)替换云值

我是python新手,有点迷路了

有什么想法吗


谢谢

我想你可以做如下事情:

data = somehow_get_your_3d_data() #indexed as [day_of_year,y,x]
for i,dat in enumerate(data):
    weeks2 = data[max(i-7,i):min(i+7,len(data)), ... ]
    new_value = get_new_value(weeks2) #get value from weeks2 here somehow
    dat[dat == cloud_value] = new_value

实际上,您正试图为数组编写一个过滤器

首先,您需要编写一个函数,当给定一个值数组(中间一个是当前检查的元素)时,该函数将返回这些值的一些计算结果。在您的情况下,函数将使用1-d数组并返回最靠近中间索引的元素,该索引不是云:

import numpy as np
from scipy.ndimage.filters import generic_filter

_cloud = -1

def findNearestNonCloud(elements):
    middleIndex = len(elements) / 2
    if elements[middleIndex] != _cloud:
        return elements[middleIndex] # middle value is not cloud

    nonCloudIndices, = np.where(elements != _cloud)
    if len(nonCloudIndices) == 0:
        return elements[middleIndex] # all values were cloud

    prevNonCloudIndex = np.where(nonCloudIndices < middleIndex, 
            nonCloudIndices, -1).max()
    nextNonCloudIndex = -np.where(nonCloudIndices > middleIndex, 
            -nonCloudIndices, 1).min()
    # -1 means no non-cloud index

    # pick index closest to middle index    
    if (abs(prevNonCloudIndex - middleIndex) 
            <= abs(nextNonCloudIndex - middleIndex)):
        return elements[prevNonCloudIndex]
    else:
        return elements[nextNonCloudIndex]
我解决了这个问题:

interpdata = []
j = 0
for i in stack:
    try:
        temp = np.where( stack[j] == 50, stack[j-1], modis[j] )
        temp = np.where( temp == 50, stack[j+1], temp )
        temp = np.where( temp == 50, stack[j-2], temp )
        temp = np.where( temp == 50, stack[j+2], temp )
        temp = np.where( temp == 50, stack[j-3], temp )
        temp = np.where( temp == 50, stack[j+3], temp ) 
        temp = np.where( temp == 50, stack[j-4], temp )
        temp = np.where( temp == 50, stack[j+4], temp )
    except IndexError:
        print 'IndexError Passed'       
        pass
    else:
        pass
    interpdata [j, :, :] = temp
    j = j + 1   

“用另一个找到的值替换云值”——这个定义有太多的歧义。请更详细地描述算法。未来/过去的日子和材料的优先顺序是什么?我想应该是
max(I-7,0)
。好的,但我该如何从相关像素中提取值,即“获取新值”?谢谢,明天早上我会试一试。我会回复你的。再次感谢。我把我的尺寸标注为[z,y,x]。你的可能不一样。
interpdata = []
j = 0
for i in stack:
    try:
        temp = np.where( stack[j] == 50, stack[j-1], modis[j] )
        temp = np.where( temp == 50, stack[j+1], temp )
        temp = np.where( temp == 50, stack[j-2], temp )
        temp = np.where( temp == 50, stack[j+2], temp )
        temp = np.where( temp == 50, stack[j-3], temp )
        temp = np.where( temp == 50, stack[j+3], temp ) 
        temp = np.where( temp == 50, stack[j-4], temp )
        temp = np.where( temp == 50, stack[j+4], temp )
    except IndexError:
        print 'IndexError Passed'       
        pass
    else:
        pass
    interpdata [j, :, :] = temp
    j = j + 1