问题描述
假设我有一个 m
-by-n
-by-3
数组 Uint8
代表一个图像,其中假定为 RGB 颜色空间.我想使用 Images
包将其导出为每像素 24 位的 PNG 图像.我该怎么做?
Suppose I have an m
-by-n
-by-3
array of Uint8
which represents an image, where an RGB colorspace is assumed. I would like to export it as a 24-bit-per-pixel PNG image using the Images
package. How can I do this?
我天真地尝试将 imwrite
应用于随机生成的原始数组,如下:
I naively tried to apply imwrite
to a randomly-generated raw array, as follows:
imwrite(rand(Uint8,300,300,3),"test.png")
但是,这给出了一个错误提示mapinfo has no method mapinfo...".
However, this gave an error saying "mapinfo has no method mapinfo...".
同样,使用
imwrite(rand(Float32,300,300,3),"test.png")
给出一个错误,说它无法推断色彩空间,我应该改用 AbstractImage
类型.因此,假设 m
-by-n
-by-3
数组可能是 Images
包不舒服自动生成 RGB 图像(Images
文档引用了由于存在 3D 和 4D 图像类型而导致的复杂性,作为不自动推断这一点的原因).
gave an error saying that it can't infer the colorspace, and that I should use an AbstractImage
type instead. So presumably the Images
package is not comfortable assuming that an m
-by-n
-by-3
array is automatically an RGB image (the Images
documentation cites complications due to the existence of 3D and 4D image types as the reason for not automatically inferring this).
如何将数值数组导出为图像?可以直接做,还是需要为数组创建一个包装器?
How can I export a numeric array as an image? Can it be done directly, or do I need to create a wrapper for the array?
推荐答案
更新
imwrite
(和 imread
)自 Images 包的 0.5 版(2015 年 10 月)起已被弃用.它们被 save
(和 load
)替换.
imwrite
(and imread
) are have been deprecated since version 0.5 of Images package (October 2015). They are replaced by save
(and load
).
原始答案:
对于体重:
imwrite(grayim(rand(300,300)),"test.png")
颜色:
imwrite(convert(Image,rand(300,300,3)),"test.png")
为我工作(我有 Julia v0.4 和 Images.jl v0.4.0)
worked for me (I have Julia v0.4 and Images.jl v0.4.0)
这篇关于使用 Julia 中的图像导出图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!