I want to use the plotting functionality of Plots.jl with an image loaded using the load_image()
function of ArrayFire.
What I have is :
AFArray: 1000×300×3 Array{Float32,3}
What I want is :
300×1000 Array{RGB{Any},2} with eltype RGB
I couldn't be able to find direct conversion in documentations. Is there any efficient way to do this?
I don't know specifically about ArrayFire arrays, but in general you can use
reinterpret
for operations like this. If you want the new array to reside on the cpu, then copy it over.Then, ideally, you could just do
Unfortunately, MxNx3 is not the optimal layout for RGB arrays, since you want the 3-values to be located sequentially. So you should either make sure that the array has 3xMxN-layout, or you can do
permutedims(A, (3, 1, 2))
.Finally, to get a matrix, you must drop the leading singleton dimension, otherwise you get a 1xMxN array.
So,
I assumed that you actually want
RGB{Float32}
instead ofRGB{Any}
.BTW, I'm not sure how this will work if you want to keep the final array on the GPU.
Edit: You might consider
reshape
instead ofdropdims
, it seems slightly faster on my pc.