Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert a nested array to a multidimensional array in Julia

Tags:

arrays

julia

I want to make Array{UInt8,3} (color image data) from Array{UInt8,2} (grayscale image data) in Julia 0.4 like the following:

using Images
dat = data(img)
dat2 = map(x -> (v = x*2 % UInt8; [v,0,0]), dat)
img2 = colorim(dat2)

However, the code above makes Array{Array{UInt8,1},2} instead. How can I make a "flatten" multidimensional array?

like image 890
Hiro Avatar asked Sep 01 '26 13:09

Hiro


1 Answers

You can also use

z = zeros(UInt8, size(A))
colorim(cat(3, A, z, z))

where A is whatever you want in the red channel.

like image 68
tholy Avatar answered Sep 03 '26 07:09

tholy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!