I recently asked how to convert Float32
or Uint8
arrays into images im Images
Paket. Ich habe eine Antwort für den Float32
Fall, aber habe noch Probleme herauszufinden, wie man ein Uint8
Array speichern.Exportieren Sie ein Uint8-Array als Bild mit Hilfe von Bildern in Julia
Als Beispiel nehmen wir eine zufällige Uint8
Array erstellen, die traditionelle Matlab-Schema verwendet, wo die Dimensionen sind (m,n,3)
:
array = rand(Uint8, 50, 50, 3);
img = convert(Image, array);
den gleichen Ansatz wie Werke Verwendung für die Float32
Fall
imwrite(img, "out.png")
schlägt mit der Nachricht fehl
ERROR: method 'mapinfo' has no method matching mapinfo(::Type{ImageMagick}, ::Image{Uint8, 3, Image{Uint8, 3, Array{Uint8, 3}}}).
ich die Dokumentation geprüft, and it says
If data encodes color information along one of the dimensions of the array (as opposed to using a ColorValue array, from the Color.jl package), be sure to specify the "colordim" and "colorspace" in properties.
jedoch zuvor erstellte das img
Objekt Inspektion zeigt, dass es colordim = 3
und colorspace = RGB
bereits eingerichtet hat, so kann dies das Problem nicht sein.
Ich suchte dann die Dokumentation für alle Instanzen von MapInfo
. In core.md gibt es ein Vorkommen:
scalei: a property that controls default contrast scaling upon display. This should be a MapInfo value, to be used for setting the contrast upon display. In the absence of this property, the range 0 to 1 will be used.
Aber es gab keine Informationen darüber, was genau ein MapInfo
Objekt ist, so sah ich weiter, und in function_reference.md heißt es:
Here is how to directly construct the major concrete MapInfo types:
MapNone(T), indicating that the only form of scaling is conversion to type T. This is not very safe, as values "wrap around": for example, converting 258 to a Uint8 results in 0x02, which would look dimmer than 255 = 0xff.
...
und einige andere Beispiele. Also habe ich versucht scalei = MapNone(Uint8)
angeben wie folgt:
img2 = Image(img, colordim = 3, colorspace = "RGB", scalei = MapNone(Uint8));
imwrite(img, "out.png")
bekam aber wieder den gleichen Fehler.
Wie codiert man Uint8
Bilddaten mit Images
in Julia?
ich eigentlich einen Kommentar in der alten Ausgabe verlassen hast du verknüpft. Aber die Antwort von Juliohm ist richtig. – tholy