3

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?

3 Answers 3

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Using array comprehension:

dat2 = UInt8[k==1 ? (dat[i,j]*2)%UInt8 : zero(UInt8)
             for i=1:size(dat,1),j=1:size(dat,2),k=1:3]

Comments

2

Another approach could be:

dat2=zeros(UInt8,(size(dat)...,3))
dat2[:,:,1]=2*dat1

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.