【问题标题】:Plot a gamut in cie1931 colour space Python 2.7在 cie1931 颜色空间 Python 2.7 中绘制色域
【发布时间】:2019-04-11 21:52:37
【问题描述】:

我想在 CIE1931 空间中绘制色域:https://www.google.co.uk/search?biw=1337&bih=1257&tbm=isch&sa=1&ei=9x3kW7rqBo3ygQb-8aWYBw&q=viewpixx+gamut&oq=viewpixx+gamut&gs_l=img.3...2319.2828.0.3036.5.5.0.0.0.0.76.270.5.5.0....0...1c.1.64.img..0.0.0....0.KT8w80tcZik#imgrc=77Ufw31S6UVlYM

我想在这些坐标内创建一个 ciexyY 颜色的三角形图: (.119,.113),(.162,.723),(.695,.304) 如图所示 - 带有一组亮度 Y 为 30.0。

我创建了一个 0-1 之间的 xy 值的 3d 数组。 然后我创建了一个矩阵,三角形内部为 1,三角形外部为 0。 我将三角形矩阵乘以 xyY ndarray。 然后我遍历 xyY ndarray 并将 xyY 值转换为 rgb,并显示它们。

结果有点接近但不正确。当我转换为 rgb 时,我认为错误出现在最后一部分,但我不知道为什么。这是当前图像:https://imgur.com/a/7cWY0FI。任何建议都将不胜感激。

from __future__ import division
import numpy as np
from colormath.color_objects import sRGBColor, xyYColor
from colormath.color_conversions import convert_color
import matplotlib.pyplot as plt

def frange(x,y,jump):
    while x < y:
        yield x
        x += jump

def onSameSide(p1,p2, A,B):
    cp1 = np.cross(B-A, p1-A)
    cp2 = np.cross(B-A, p2-A)
    if(np.dot(cp1, cp2) >= 0):
        return True
    else:
        return False

def isPointInTriangle(p,A,B,C):
    if(onSameSide(p,A,B,C) and onSameSide(p,B,A,C) and onSameSide(p,C,A,B)):
        return True
    else:
        return False

xlen = 400
ylen = 400

#CIExyY colour space
#Make an array (1,1,3) with each plane representing how x,y,Y vary in the coordinate space
ciexyY = np.zeros((3,xlen,ylen))
ciexyY[2,:,:]=30.0
for x in frange(0,1,1/xlen):
    ciexyY[0,:,int(xlen*x)]=x
    for y in frange(0,1,1/xlen):
        ciexyY[1,int(ylen*y),:]=y

#coordinates from Viewpixx gamut, scaled up to 100
blue=np.array((.119,.113,30.0))
green=np.array((.162,.723,30.0))
red=np.array((.695,.304,30.0))
#scale up to size of image
blue = np.multiply(blue,xlen)
green = np.multiply(green,xlen)
red = np.multiply(red,xlen)

#make an array of zeros and ones to plot the shape of Viewpixx triangle
triangleZeros = np.zeros((xlen,ylen))
for x in frange(0,xlen,1):
    for y in frange(0,ylen,1):
        if(isPointInTriangle((x,y,0),blue,green,red)):
            triangleZeros[x,y]=1
        else:
            triangleZeros[x,y]=0

#cieTriangle
cieTriangle = np.multiply(ciexyY,triangleZeros)

#convert cieTriangle xyY to rgb
rgbTriangle = np.zeros((3,xlen,ylen))
for x in frange(0,xlen,1):
    for y in range(0,ylen,1):
        xyYcolour = xyYColor(cieTriangle[0,x,y],cieTriangle[1,x,y],cieTriangle[2,x,y])
        rgbColour = convert_color(xyYcolour,sRGBColor)
        rgbTriangle[0,x,y] = rgbColour.rgb_r
        rgbTriangle[1,x,y] = rgbColour.rgb_g
        rgbTriangle[2,x,y] = rgbColour.rgb_b

rgbTriangle = np.transpose(rgbTriangle)
plt.imshow(rgbTriangle)
plt.show()

【问题讨论】:

    标签: python python-2.7 color-space


    【解决方案1】:
    from colour.plotting import plot_chromaticity_diagram_CIE1931
    plot_chromaticity_diagram_CIE1931()
    

    【讨论】:

      【解决方案2】:

      我们在Colour 中有所有常见的色度图,我会推荐它而不是 python-colormath,因为颜色是矢量化的,因此速度更快。

      您有当前图像的渲染图要分享吗?

      【讨论】:

      • 指向当前图像 imgur.com/a/7cWY0FI 的链接。我正在努力使用 colour.plotting 中的色度图,因为对于我的程序,我需要操纵该图并跟踪每个像素的颜色值。我尝试使用 Color 从 xy 转换为 XYZ 到 sRGB,但输出 RGB 值超出 0-1 范围,我不知道为什么。
      猜你喜欢
      • 2015-08-22
      • 1970-01-01
      • 2013-07-26
      • 1970-01-01
      • 2016-08-09
      • 1970-01-01
      • 2018-05-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多