偏振图像-如何找到每个RGB值的平均值 [英] Polarizing an image--how to find the average of each RGB value

查看:77
本文介绍了偏振图像-如何找到每个RGB值的平均值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要进行图像处理练习,我必须编写一个对图像应用各种效果的程序.效果之一是灰度,可以找到RGB值的平均值((红色+绿色+蓝色)/3).但是,要使图像偏振,我需要首先找到每个单独分量的平均值(即所有红色值/红色像素数).然后遍历行和列(使用像素,红色值,绿色值和蓝色值的计数器)作为查找平均值的方式是否合适?有没有更有效的方法?

For an exercise in image processing, I have to write a program that applies various effects to images. One of the effects was grayscale, which was done find the average of RGB values ((red+green+blue)/3). To polarize an image, however, I need to first find the averages of each individual component (i.e. all red values/number of red pixels). Would it be appropriate to then loop through the rows and columns (with a counter for pixels, red values, green values, and blue values) as a way to find the average? Is there a more efficient way?

此外,像素基于平均像素值极化.如果平均R为100,平均G为200,平均B为300,并且像素的R为150,G 150,而B为100,则极化像素将为255、0和0."我不明白这种关系吗?是不是如果当前值小于平均值,则极化为0/大于平均值,极化为255?

Also, pixels are polarized based on the average pixel value. "If average R is 100, average G is 200, and average B is 300 and a pixel has R 150, G 150, and B, 100, the polarized pixel would be 255, 0, and 0." I don't understand the relationship? Is it if the current value is less than the average, then it would be polarized to 0/more than the average, polarized to 255?

推荐答案

计算图像的平均RGB值:

Calculate average RGB value of an image:

    import numpy as np

    # load your image in a variable named `im`, then calculate average RGB value
    np.array(im).mean(axis=(0,1))

    # It gives a tuple like (71.710743801652896, 103.11570247933884, 64.165289256198349)

您不需要进行迭代,numpy可以满足所有需求:)

You don't need to iterate, numpy has it all :)

这篇关于偏振图像-如何找到每个RGB值的平均值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆