索引3D numpy数组

时间:2016-02-27 01:48:25

标签: python arrays numpy indexing

我的图像有7个波段,每个波段有6938x752像素。我想对它进行一些处理,所以我使用一个名为RIOS的python模块来处理图像的读写,让用户专注于处理。它以块为单位读取图像,因此处理比读取整个图像更有效。

它将图像读取为具有形状(7,200,200)的numpy数组。我希望按像素处理数据,以便我获得每个像素的每个波段的信息。有没有办法索引数组,以便我可以处理图像中每个像素的7个值(每个波段一个)?

我在这里提供的唯一一个小代码是我用来读入,处理和写入数据的函数。

def MASKimage(info, inputs, outputs):

    inputs.image1 = inputs.image1.astype(numpy.float32) # Read the image in as an array with shape (7, 200, 200)

    process = * Do some processing on the array which is the 7 values pixel by pixel * # has shape (1,7)

    outputs.outimage = process

1 个答案:

答案 0 :(得分:1)

您可以尝试使用np.transposenp.reshape

inputs.image1 = input.images1.transpose((1,2,0)).reshape(200*200,7)

您可以使用单个循环迭代图像来进行处理,因为每个元素代表一个带有7个波段的像素。

相关问题