I recently asked how to convert Float32 or Uint8 arrays to images in the Images package. I got an answer for the Float32 case, but it's still hard for me to figure out how to save a Uint8 array.
As an example, let's create a random Uint8 array using the traditional Matlab scheme, where the sizes are (m,n,3) :
array = rand(Uint8, 50, 50, 3); img = convert(Image, array);
Using the same approach as for the case of Float32 ,
imwrite(img, "out.png")
ends with a message
ERROR: the mapinfo method does not have a method corresponding to mapinfo (:: Type {ImageMagick}, :: Image {Uint8, 3, Image {Uint8, 3, Array {Uint8, 3}}}).
I checked the documentation and it says
If the data encodes color information along one of the array sizes (as opposed to using the ColorValue array from the Color.jl package), be sure to specify the "colordim" and "colorspace" properties in the properties.
However, checking a previously created img object shows that it has already set colordim = 3 and colorspace = RGB , so this may not be a problem.
Then I looked at the documentation for all instances of MapInfo . There is one event in core.md :
scalei: a property that controls the default scaling on display. This should be the MapInfo value, which should be used to set the contrast for display. In the absence of this property, a range from 0 to 1 will be used.
But there was no information about what the MapInfo object is, so I looked further, and the function_reference.md says:
Here's how to directly build the basic concrete types of MapInfo:
MapNone (T), indicating that the only form of scaling is converting to type T. This is not very safe because the values โโare "wrapped": for example, converting 258 to Uint8 results in 0x02, which will look darker than 255 = 0xff.
...
and some other examples. So I tried to specify scalei = MapNone(Uint8) as follows:
img2 = Image(img, colordim = 3, colorspace = "RGB", scalei = MapNone(Uint8)); imwrite(img, "out.png")
but got the same error again.
How do you encode Uint8 image data using Images in Julia?