How to convert an array to Matrrix of ColorTypes.Gray

using Flux, Flux.Data.MNIST, Statistics
using Flux: onehotbatch, onecold, crossentropy, throttle
using Base.Iterators: repeated, partition

# load the images
imgs = MNIST.images()
# average the values in the image
imgs0 = imgs[raw_labels .== 0]
avg_imgs0 = reduce(+, float.(imgs0))./length(imgs0)

I see that eltype(imgs[1]) is ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}} and imgs[1] is a 28x28 matrix. But I can’t seem to convert avg_imgs0 which has eltype of Float back to imgs[1]'s eltype

I tried

#import Base.ColorTypes

How do I convert avg_imgs0 back to a matrix containing ColorTypes.Gray{FixedPointNumbers.Normed{UInt8,8}}?

Please try run your code.

What is raw_labels. What is Base.ColorTypes?

1 Like

Anyway, you can do Gray.(avg_imgs0).



I’ve fixed my code, but

Gives error UnderVarError: Gray not defined.

I am using Julia v1.1

This seems to work

]add ColorTypes
using ColorTypes