I have a matrix of colors of the type RGB{float 64}. I’d like to export this matrix from julia to a file and then import it back to julia to do further analysis. I tried using DelimitedFiles this way:
writedlm(“colors.txt”, colors) to export the file and then
Array(readdlm(“colors.txt”)) to import it.
The problem is this has the data in a text form and I wanna convert to colors. Is there a way to convert it to colors? or should I have used a different package than Delimited Files?
Thanks for help!
I think JLD2.jl might be a good option:
julia> using Colors, JLD2
julia> x = rand(RGB, 3, 2)
3×2 Array{RGB{Float64},2} with eltype RGB{Float64}:
RGB{Float64}(0.8795,0.997088,0.0300252) RGB{Float64}(0.0860507,0.487816,0.772049)
RGB{Float64}(0.507044,0.239653,0.166532) RGB{Float64}(0.815468,0.1354,0.230995)
RGB{Float64}(0.847003,0.0561504,0.165049) RGB{Float64}(0.712974,0.591226,0.854261)
julia> save_object("color_file.jld2", x)
julia> x2 = load_object("color_file.jld2")
3×2 Array{RGB{Float64},2} with eltype RGB{Float64}:
RGB{Float64}(0.8795,0.997088,0.0300252) RGB{Float64}(0.0860507,0.487816,0.772049)
RGB{Float64}(0.507044,0.239653,0.166532) RGB{Float64}(0.815468,0.1354,0.230995)
RGB{Float64}(0.847003,0.0561504,0.165049) RGB{Float64}(0.712974,0.591226,0.854261)
julia> x == x2
true
There should also be more ways to save/load your data here: Basics · Julia Data Format