1

I want to get the max (and min) pixel value in an array.

Imagine I have the next numpy array:

image = np.array([
          [150, 160, 200],
          [80, 120, 90],
          [220, 200, 180]
        ])

I want to get that the maximum pixel value is the [220, 200, 180] value, because the sum of all BGR channels is greater than the others.

I know that I can use np.max(image, axis=0) to get [220, 200, 200], but that's not what I am looking for.

Any idea on how to do that? I could iterate over all the numpy array, sum the values and get the index of the greater, but there must be a better way to perform this.

juan carlos
  • 184
  • 1
  • 11

1 Answers1

3

IIUC, you want to get the index of the max sum?

image[np.argmax(image.sum(1))]

output: array([220, 200, 180])

mozway
  • 194,879
  • 13
  • 39
  • 75