如何设置像素的RGB值

时间:2015-10-21 10:02:46

标签: image-processing julia

到目前为止,我有这个:

enter image description here

using Images, Colors
a = Array{UInt8}(5, 5, 3)
imOutput = colorim(a)

如何为像素分配三个值:

imOutput[1,1] = 

2 个答案:

答案 0 :(得分:2)

我认为你的意思是(注意a

的尺寸
a = Array{UInt8}(3,5,5)
imOutput = colorim(a)
imOutput[1,1] = RGB(0,0,0)
imOutput

tests for Images.jl让我意识到了这一点。

答案 1 :(得分:1)

我不知道有data()函数,我实际上是通过dump(imOutput)找到解决方案:

Images.Image{FixedPointNumbers.UfixedBase{UInt8,8},3,Array{FixedPointNumbers.UfixedBase{UInt8,8},3}} 
  data: Array(FixedPointNumbers.UfixedBase{UInt8,8},(5,5,3)) 5x5x3 Array{FixedPointNumbers.UfixedBase{UInt8,8},3}:
[:, :, 1] =
 0.314  0.498  0.337  0.0    0.102
 0.584  0.0    0.549  0.565  0.498
 0.337  0.0    0.102  0.212  0.0  
 0.549  0.816  0.498  0.906  0.0  
 0.102  0.584  0.0    0.545  0.188

[:, :, 2] =
 0.588  0.0  0.0  0.0  0.0
 0.337  0.0  0.0  0.0  0.0
 0.549  0.0  0.0  0.0  0.0
 0.102  0.0  0.0  0.0  0.0
 0.498  0.0  0.0  0.0  0.0

[:, :, 3] =
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
 0.0  0.0  0.0  0.0  0.0
  properties: Dict{ASCIIString,Any} len 3
    colorspace: ASCIIString "RGB"
    colordim: Int64 3
    spatialorder: Array(ASCIIString,(2,)) ASCIIString["y","x"]

输出显示您可以使用imOutput.data来访问数据。 是的,这与data()函数完全相同,请看一下line

从输出中,我们可以看到imOutput的颜色空间为RGB,因此如果我们的颜色来自HSL,我们应该将该颜色转换为RGB空间在我们将这种颜色传递给imOutput.data之前。例如,

a = convert(RGB, HSL(270, 0.5, 0.5))
imOutput.data[1,1,:] = [a.r, a.g, a.b]
相关问题