简体   繁体   English

索引3D numpy数组

[英]Index a 3D numpy array

I have an image that has 7 bands with 6938x752 pixels in each band. 我有一个图像,该图像具有7个带,每个带6938x752像素。 I want to do some processing on it so am using a python module called RIOS that deals with the reading and writing of the image to let the user focus on the processing. 我想对其进行一些处理,因此我使用一个称为RIOS的python模块,该模块处理图像的读写,以使用户专注于处理。 It reads the image in as a numpy array in blocks so that the processing is more efficient than reading in the whole image. 它以块为numpy数组的形式读取图像,因此处理比读取整个图像更有效。

It reads the image in as a numpy array with the shape (7, 200, 200). 它以形状为(7,200,200)的numpy数组形式读取图像。 I want to process the data by pixel so that I have the information from each band for each pixel. 我想按像素处理数据,以便获得每个像素的每个波段的信息。 Is there a way to index the array so that for I can process just the 7 values (one for each band) for each pixel within image? 有没有一种方法可以索引数组,以便对图像中的每个像素只处理7个值(每个波段一个)?

The only little code I can provide here is the function I use to read in, process and write the data. 我在这里只能提供的小代码是用于读入,处理和写入数据的功能。

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

You can try using np.transpose and np.reshape : 您可以尝试使用np.transposenp.reshape

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

You can just iterate through the image with a single loop to do your processing as each element represents a pixel with 7 bands. 您可以只用一个循环就可以遍历整个图像来进行处理,因为每个元素代表一个具有7个波段的像素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM