相关疑难解决方法(0)

用于确定RGB颜色亮度的公式

我正在寻找某种公式或算法来确定给定RGB值的颜色的亮度.我知道它不能像将RGB值一起添加并且具有更高的总和更简单一样简单,但我有点不知道从哪里开始.

rgb image colors

366
推荐指数
11
解决办法
28万
查看次数

如何在Python中将RGB图像转换为灰度?

我正在尝试使用matplotlibRGB图像读取并将其转换为灰度.

在matlab中我用这个:

img = rgb2gray(imread('image.png'));
Run Code Online (Sandbox Code Playgroud)

matplotlib教程中,他们没有涵盖它.他们只是读入图像

import matplotlib.image as mpimg
img = mpimg.imread('image.png')
Run Code Online (Sandbox Code Playgroud)

然后他们切割数组,但这与我理解的将RGB转换为灰度不同.

lum_img = img[:,:,0]
Run Code Online (Sandbox Code Playgroud)

我发现很难相信numpy或matplotlib没有内置函数可以将rgb转换为灰色.这不是图像处理中的常见操作吗?

我写了一个非常简单的函数,可以imread在5分钟内使用导入的图像.这是非常低效的,但这就是为什么我希望内置的专业实现.

塞巴斯蒂安已经改善了我的功能,但我仍然希望找到内置的功能.

matlab的(NTSC/PAL)实现:

import numpy as np

def rgb2gray(rgb):

    r, g, b = rgb[:,:,0], rgb[:,:,1], rgb[:,:,2]
    gray = 0.2989 * r + 0.5870 * g + 0.1140 * b

    return gray
Run Code Online (Sandbox Code Playgroud)

python matplotlib

170
推荐指数
11
解决办法
41万
查看次数

我如何在Freeglut中画彩虹?

我正试图在openGL中绘制一个彩虹色的情节传奇.这是我到目前为止所得到的:

glBegin(GL_QUADS);
for (int i = 0; i != legendElements; ++i)
{
    GLfloat const cellColorIntensity = (GLfloat) i / (GLfloat) legendElements;
    OpenGL::pSetHSV(cellColorIntensity*360.0f, 1.0f, 1.0f);

    // draw the ith legend element
    GLdouble const xLeft = xBeginRight - legendWidth;
    GLdouble const xRight = xBeginRight;
    GLdouble const yBottom = (GLdouble)i * legendHeight /
    (GLdouble)legendElements + legendHeight;
    GLdouble const yTop = yBottom + legendHeight;

    glVertex2d(xLeft, yTop); // top-left
    glVertex2d(xRight, yTop); // top-right
    glVertex2d(xRight, yBottom); // bottom-right
    glVertex2d(xLeft, yBottom); // bottom-left
}

glEnd();
Run Code Online (Sandbox Code Playgroud)

legendElements是构成"彩虹"的离散方块的数量. …

c++ opengl freeglut

7
推荐指数
1
解决办法
3572
查看次数

标签 统计

c++ ×1

colors ×1

freeglut ×1

image ×1

matplotlib ×1

opengl ×1

python ×1

rgb ×1