Save Matrix of RGB values as image

Viewed 213

let's say I have

c = RGB{Normed{UInt8,8}}[
        RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(1.0,0.0,0.0);
        RGB{N0f8}(1.0,0.0,0.0) RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.0,0.0);
        RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.502,0.0)]

How can I save this as a image in e.g. PNG or JPG format?

Note that I don't just need 9 pixels of those colors but like a bigger picture. Like:

enter image description here

1 Answers

You can use save function from Images.jlpackage (you should also install FileIO.jl and ImageMagick.jl for necessary transformations). To save it as a bigger picture you should manually resize the array to the required size with the help of repeat function

using Images

c = RGB{Normed{UInt8,8}}[
        RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(1.0,0.0,0.0);
        RGB{N0f8}(1.0,0.0,0.0) RGB{N0f8}(1.0,1.0,1.0) RGB{N0f8}(0.0,0.0,0.0);
        RGB{N0f8}(0.0,0.502,0.0) RGB{N0f8}(0.0,0.0,0.0) RGB{N0f8}(0.0,0.502,0.0)]

c2 = repeat(c, inner = (50, 50))

save("/tmp/test.png", c2)

Here 50x50 in c2 definition is the size of a single cell in pixels.

Related