使用导出图像在朱莉娅的图像 [英] Export an image using Images in Julia

查看:95
本文介绍了使用导出图像在朱莉娅的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个 M -by - N -by - 3 UINT8 从而重新$ p $阵列psents的图像,在假定的RGB色彩。我想使用图片包,将其导出为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的没有方法MapInfo的......

However, this gave an error saying "mapinfo has no method mapinfo...".

同样,使用

imwrite(rand(Float32,300,300,3),"test.png")

给了一个错误,指出它无法推断色彩,那我应该使用 AbstractImage 键入代替。所以presumably的图片包不舒服假设一个 M -by - ñ -by - 3 阵列自动为RGB图像(图片文件引用的并发症由于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?

推荐答案

有关BW:

   imwrite(grayim(rand(300,300)),"test.png")

颜色:

   imwrite(convert(Image,rand(300,300,3)),"test.png")

工作对我来说(我有朱莉娅V0.4和Images.jl V0.4.0)

worked for me (I have Julia v0.4 and Images.jl v0.4.0)

这篇关于使用导出图像在朱莉娅的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆