Export images using images in Julia

Suppose I have an m -by- n -by- 3 Uint8 array that represents an image where RGB color space is assumed. I would like to export it as a 24-bit pixel PNG image using the Images package. How can i do this?

I naively tried applying imwrite to a randomly generated source array as follows:

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

However, this gave an error: "Mapinfo does not have a mapinfo method ...".

Similarly using

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

gave an error stating that it cannot output the color space, and instead I should use the AbstractImage type. Thus, the Images package is presumably inconvenient, assuming that the m -by- n -by- 3 array is automatically an RGB image (the Images documentation leads to complications due to the existence of 3D and 4D image types as a reason that this is not automatically output )

How can I export a numeric array as an image? Can this be done directly or do I need to create a wrapper for the array?

+1
source share
1 answer

UPDATE

imwrite (and imread ) are deprecated from version 0.5 of the Images package (October 2015). They are replaced by save (and load ).

ORIGINAL RESPONSE:

for BW:

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

for color:

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

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

+1
source

Source: https://habr.com/ru/post/1202035/


All Articles