【发布时间】:2015-08-22 05:59:33
【问题描述】:
我一直在尝试打开一些 RGB 图像,将数据视为 HSL 像素的 2D 数组,在 HSL 空间中操作像素,转换回 RGB 并将操作后的图像写入文件。但是我不太明白(很棒的)julia 包Color 和Images 中的转换是如何工作的。
例如,我希望下面的代码(部分按照this SO question 中的示例编写)编写非常类似于此图像文件的内容(如 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")
更新
感谢@rickhg12hs 在 Color.jl 模块中发现错误,经过以下步骤后,我从上面的代码中得到了预期的输出:
- 在 github 上 fork source repository for Color.jl
- 更正转换函数(如下),将更改推送到我的 Color.jl 分支
- 移除 julia 自带的默认 Color.jl 模块
- 使用 Julia 的 git 机制安装我的分叉包。
- 重启朱莉娅
我无法弄清楚如何与以前的版本并行安装模块的分叉版本,但执行以下操作(然后重新启动 julia)应该可以暂时修复错误:
Pkg.rm("Color")
Pkg.clone("https://github.com/CnrLwlss/Color.jl.git","Color")
Pkg.checkout("Color","master")
一旦拉取请求通过,将需要切换回原始颜色模块。
【问题讨论】:
-
在我看来就像
Color.jl中的 RGB 到 HSL 转换错误。 Github pull request 已提交修复。
标签: image colors type-conversion julia color-space