Cnr*_*nrL 5 image colors type-conversion color-space julia
我一直在尝试打开一些 RGB 图像,将数据视为 HSL 像素的 2D 数组,操作 HSL 空间中的像素,转换回 RGB 并将操作后的图像写入文件。但是我不太明白(很棒的)julia 包“颜色”和“图像”中的转换是如何工作的。
例如,我希望下面的代码(部分是按照这个SO问题的示例编写的)编写非常类似于此图像文件的内容(如test_1.png和test_2.png):

然而,下面的代码实际上会产生更暗的图像:

我应该如何重新排列数组或图像以获得我期望的输出?
using Color, Images
# Download file, read it in, convert colourspace to HSL and recast as array
fname=download("https://farm9.staticflickr.com/8725/17074451907_2381037c7d_m_d.jpg")
rgb=imread(fname)
hsl=convert(Image{HSL},float32(rgb))
hslArr=reinterpret(data(hsl))
# I would like to manipulate HSL data here...
# Two ways to convert manipulated array back to HSL image
hsl_1=Image(hslArr; colorspace="HSL", colordim=1, spatialorder=["x","y"])
hsl_2=reinterpret(HSL{Float32},hslArr)
# Two ways to convert HSL image to RGB image
rgb_1=convert(Image{RGB},hsl_1)
rgb_2=convert(Array{RGB{Float32}},hsl_2)
# Finally, write images to file
imwrite(rgb_1,"test_1.png")
imwrite(rgb_2,"test_2.png")
Run Code Online (Sandbox Code Playgroud)
感谢 @rickhg12hs 在 Color.jl 模块中发现错误,我在执行以下步骤后从上面的代码中获得了预期的输出:
我无法弄清楚如何与以前的版本并行安装模块的分叉版本,但执行以下命令(然后重新启动 julia)应该暂时修复该错误:
Pkg.rm("Color")
Pkg.clone("https://github.com/CnrLwlss/Color.jl.git","Color")
Pkg.checkout("Color","master")
Run Code Online (Sandbox Code Playgroud)
一旦拉取请求通过,将需要切换回原始颜色模块。
在Color.jl获得更新并实施/通过更多测试之前,您可以进行单个字符更改Color/src/conversions.jl以最有可能解决此特定问题。更改-为+第 156 行。
150 # Everything to HSL
151 # -----------------
152
153 function convert{T}(::Type{HSL{T}}, c::AbstractRGB)
154 c_min = min(c.r, c.g, c.b)
155 c_max = max(c.r, c.g, c.b)
156 l = (c_max + c_min) / 2 # <-- Changed '-' to '+'
Run Code Online (Sandbox Code Playgroud)
在我的机器上,你的 HSL 转换后的小鸟现在看起来很棒!
| 归档时间: |
|
| 查看次数: |
1603 次 |
| 最近记录: |