image - 如何将 {UINT16, 2} 数组保存到 Julia 中的图像

标签 image julia hdf5 image-size ijulia-notebook

我在 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

关于image - 如何将 {UINT16, 2} 数组保存到 Julia 中的图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62846275/

相关文章:

java - 如何使用 NetBeans 在 Windows Java 项目中使用 HDF5

image - Webpack4 : Moving/Importing Image Folder from "SRC folder" to "DIST folder"

image - 在matlab中显示多个图像,并将补丁叠加在同一图中

listbox - 当前的 Julia Gtk.jl 包中没有实现 GtkListbox 吗?

if-statement - 没有 `else` 的 Julia 三元运算符

c++ - HDF5 C++ : write a string in a compound data set

python - 如何使用 h5py 导入 .mat-v7.3 文件

ruby-on-rails - 当您不想使用图像标签时如何获取 Rails 图像路径

java - 查找并消除轮廓opencv

julia - 在 Julia 中使用 `Symbol` 或 `String` 更改复合类型字段的值