4

I'm trying to recreate the function

max(array, [], 3)

From MatLab, which can take my 300x300px image stack of N images (I'm saying "Image" here because I'm processing images, really this is just a big double array), 300x300xN, and create a 300x300 array. What I think is happening in this function, if it were to operate inefficiently, is that it is parsing through each (x,y) point, then taking the maximum value from that point across the z-axis, then normalizing with maximum and minimum values of the entire array.

I've tried recreating this in python with

# Shape of dataset: (300, 300, 181)
# Type of dataset: <type 'numpy.ndarray'>
for x in range(numpy.size(self.dataset, 0)):
    for y in range(numpy.size(self.dataset, 1)):
        print "Point is", x, y
        # more would go here to find the maximum (x,y) value over Z axis in self.dataset

A very simple X,Y iterator. -- but not only does my IDE crash after a few milliseconds of running this code, but also it feels gross and inefficient.

Is there something I'm missing? I'm new to Python, and therefore the answer here isn't clear to me. Is there an existing function that does this operation?

4
  • You should post in the question a small sample dataset, say of dimensions 10*10*3, which will help others to give suggestions. Commented Jan 10, 2018 at 1:27
  • I thought your problem with return self.dataset array size. can you try this, please? dim1 = len(self.dataset) dim2 = len(self.dataset[0]) dim3 = len(self.dataset[0][0]) to get right array dimintions. Commented Jan 10, 2018 at 1:38
  • MATLAB's max does not normalize. It just takes the maximum, in this case, of array(i,j,:) for each combination of i and j. Commented Jan 10, 2018 at 1:58
  • 2
    The Numpy equivalent of max(array, [], 3) would be np.amax(array, axis=2). There's no normalization in either function. Commented Jan 10, 2018 at 11:00

1 Answer 1

13
import numpy as np
import matplotlib.pyplot as plt
from skimage import io

path = "test.tif"
IM = io.imread(path)
IM_MAX= np.max(IM, axis=0)
plt.imshow(IM_MAX)
Sign up to request clarification or add additional context in comments.

1 Comment

@kai no, the original answer is correct. skimage reads the image axis as (plane, row, column) so axis=0 is the plane which is the z-axis.

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.