我在 Julia 中有一个 Array{UInt16,2},大小为 5328×3040。我想将其保存为 png 图像。
我尝试了以下方法:
save("gray.png", colorview(Gray, img))
但得到以下错误:ERROR: TypeError: in Gray, in T, expected T<:Union{Bool, AbstractFloat, FixedPoint}, got Type{UInt16}
Stacktrace:
[1] ccolor_number at C:\Users\ankushar\.julia\packages\ImageCore\KbJyT\src\convert_reinterpret.jl:60 [inlined]
[2] ccolor_number at C:\Users\ankushar\.julia\packages\ImageCore\KbJyT\src\convert_reinterpret.jl:57 [inlined]
[3] colorview(::Type{Gray}, ::Array{UInt16,2}) at C:\Users\ankushar\.julia\packages\ImageCore\KbJyT\src\colorchannels.jl:104
[4] top-level scope at REPL[16]:1
caused by [exception 3]
IOError: symlink: operation not permitted (EPERM)
我正在使用 Julia 1.4.2你能提出一种在 Julia 中将这些数组存储为图像的好方法吗?
蒂亚!
最佳答案
您可以在保存之前对像素值进行标准化。
using Images
img = rand(UInt16, 10, 20)
img[1:3]
# => 3-element Array{UInt16,1}:
0x7fc2
0x057e
0xae79
gimg = colorview(Gray, img ./ typemax(UInt16))
gimg[1:3] |> channelview
# => 3-element reinterpret(Float64, ::Array{Gray{Float64},1}):
0.4990615701533532
0.02145418478675517
0.6815442130159457
save("gray.png", gimg)
关于image - 如何将 {UINT16, 2} 数组保存到 Julia 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62846275/