Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finding the value of the min and max pixel

I computed the smallest and largest pixel values for pixel in a grayscale image as follows:

smallest = numpy.amin(image)
biggest = numpy.amax(image)

but this will only works in grayscale.

How can I do the same for a color image (RGB)?

like image 760
Mumfordwiz Avatar asked Jan 14 '14 15:01

Mumfordwiz


2 Answers

You can access each channel with the slices as follows:

# red
image[..., 0].min()
image[..., 0].max()
# green
image[..., 1].min()
image[..., 1].max()
# blue
image[..., 2].min()
image[..., 2].max()
like image 112
YXD Avatar answered Sep 17 '22 18:09

YXD


You can test it quickly in python script.

import numpy
img = numpy.zeros((10,10,3), dtype=numpy.int)  # Black RGB image (10x10)
img[5,2] = [255, 255, 255]
print img.reshape((img.shape[0]*img.shape[1], 3)).max(axis=0)

array([255, 255, 255])

like image 42
double_g Avatar answered Sep 19 '22 18:09

double_g