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)?
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()
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])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With