找到最小和最大像素的值

时间:2022-09-27 08:41:52

I figured out that to find the smallest and largest value for a pixel is

我发现要找到像素的最小和最大值是

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

but this will only work in a grey photo how do i find the smallest value for each of the coloros red,green,blue?

但这只适用于灰色照片我如何找到每个颜色红色,绿色,蓝色的最小值?

Thank you

3 个解决方案

#1


5  

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()

#2


3  

You can test it quickly in python script.

你可以在python脚本中快速测试它。

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])

数组([255,255,255])

#3


1  

Assuming you have a BGR image (loaded using OpenCV), I found a simple way to do this:

假设你有一个BGR图像(使用OpenCV加载),我发现了一种简单的方法:

import numpy as np

max_channels = np.amax([np.amax(img[:,:,0]), np.amax(img[:,:,1]), np.amax(img[:,:,2])])

print(max_channels)

#1


5  

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()

#2


3  

You can test it quickly in python script.

你可以在python脚本中快速测试它。

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])

数组([255,255,255])

#3


1  

Assuming you have a BGR image (loaded using OpenCV), I found a simple way to do this:

假设你有一个BGR图像(使用OpenCV加载),我发现了一种简单的方法:

import numpy as np

max_channels = np.amax([np.amax(img[:,:,0]), np.amax(img[:,:,1]), np.amax(img[:,:,2])])

print(max_channels)