如何在python中对numpy.array类型的图像进行灰度处理

时间:2019-05-20 17:47:43

标签: python image numpy grayscale

我有一张图片。该图像由numpy.array类型表示。

int sum = 0;
for (int i = 0; i < rows; i++)
{ 
    int[] numbers = Console.ReadLine()
        .Split(", ", StringSplitOptions.RemoveEmptyEntries)
        .Select(int.Parse)
        .ToArray();
    sum += numbers.Sum(); //Calculate sum of all numbers in a row and add it to existing sum variable.
//I do not know how to add the elements here
}

Console.WriteLine("Sum of all numbers" + sum); //print sum of all numbers i.e. 76

如何将数组表示的图像转换为如下所示的灰度。

array([[[165, 173, 184],
        [170, 178, 189],
        [171, 179, 190],
        ...,


       [[  4,  12,   1],
        [  3,  11,   0],
        [  6,  14,   1],
        ...,
        [ 36,  32,  21],
        [ 27,  23,  12],
        [ 22,  18,   7]]], dtype=uint8)

0 个答案:

没有答案