I wish to show an image from CIFAR-10 loaded from the matlab files available here: CIFAR-10 and CIFAR-100 datasets
I had hoped to show the first image with the following code, but have not been able to make it work.
using MAT
using Flux
using Plots
using Images
using Colors
function loadfile(filename)
all = matread(filename)
all["data"]
end
x = loadfile("../cifar10/data_batch_1.mat")[1, :] # load the array and get the first image
println(size(x)) # prints (3072, ). Each image is 32x32 pixels and has 3 channels.
ximg = (reshape(x, (32, 32, 3)) .% Int) ./ 255 # The type is now 32Ă—32Ă—3 Array{Float64,3}. Hopefully perfect for showing
# Now, plotting the image is tricky.
colorview(RGB, ximg) # crashes with ERROR: LoadError: DimensionMismatch("indices Base.OneTo(32) are not consistent with color type ColorTypes.RGB{Float64}")
# Both of these plots are empty:
plot(channelview(ximg))
plot(ximg)
I expected this to be as easy as plot(colorview(RGB, ximg))
, but I am clearly missing something.
I can not use MLDatasets for this as it is a school assignment, I have to use the linked matlab files.