Besides the case when is provided the source
, the trace image
can display exclusively an Array(UInt8, 3)
of size equal (3, nrows, ncolumns)
or (4, nrows, ncolumns).
In the former case we are setting colormodel="rgb"
, while in the latter one, colormodel="rgba"
.
Since Julia arrays are column major ordered, and the json serialization of an array, myarr
, of size (d, nrows, ncolumns), d=3, 4,
performed by PlotlyJS, has a bug, it is necessary to permute nrows and ncolumns.
More precisely we have to pass to image
definition z=permutedims(myarr, (1, 3, 2))
.
using NPZ, PlotlyJS
function displayArray3(arr:: Array{UInt8, 3})
Plot(image(z=permutedims(arr, (1, 3, 2)),
colormodel= size(arr, 1) == 3 ? "rgb" : size(arr, 1) ==4 ?
"rgba" : error("the array should be of size (d, rows, cols), d=3, 4")))
end
The WebIO Jupyter extension was not detected. See the WebIO Jupyter integration documentation for more information.
displayArray3 (generic function with 1 method)
arr3c = npzread("images/arr3channels.npy")
println("the type of array is $(typeof(arr3c))"*" and size: $(size(arr3c))")
pl=displayArray3(arr3c)
the type of array is Array{UInt8, 3} and size: (3, 300, 300)
arr4c = npzread("images/arr4channels.npy")
println("the type of array is $(typeof(arr4c))"*" and size: $(size(arr4c))")
pl=displayArray3(arr4c)
relayout!(pl, xaxis_visible=false, yaxis_visible=false)
display(pl)
Let us compare the first two plots with Julia images, from which the above arrays, arr3c
, and arr4c
, have been derived:
using Images
img1=load("images/sun-flower.jpg")
img2 =load("images/circular-image.png")
img = load("images/camera.png");#https://github.com/scikit-image/scikit-image/blob/main/skimage/data/camera.png
typeof(img), size(img)
pl = Plot(heatmap(z=reinterpret(UInt8, img), colorscale=colors.grays1, showscale=false),
Layout(width=500, height=500, yaxis_autorange="reversed"))
plotly.express.imshow
likewise displays a gray image (1-channel image) as a heatmap.
For comparison see this example:
https://plotly.com/python/imshow/#hiding-the-colorbar-and-axis-labels,
and inspect:
fig.data[0]