0

I have an image that has 7 bands with 6938x752 pixels in each band. 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. It reads the image in as a numpy array in blocks so that the processing is more efficient than reading in the whole image.

It reads the image in as a numpy array with the shape (7, 200, 200). 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?

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
1
  • 1
    It is no clear what you are asking. Can you give an example of the type of processing you want to do. To get the corresponding pixel in each image you would do inputs.image1[:,0,0] for the 0th row 0th column and so on. Commented Feb 27, 2016 at 5:29

1 Answer 1

1

You can try using np.transpose and np.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.

Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I needed! After some processing I am get a single pixel value. Imagine for example I want the mean of the 7 values. I want to write this to a new image but it requires a 3d array. Can you show me how to reshape this so I can write it back in the same shape as I read it (with 1 band and not 7)?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.