Plotting an HSV array and also saving the image as a jpeg file

The following code, with a small array, generates an HSV array. I have been unable to find out how to display the image represented by the array. Later I want to save the images as a jpeg file and then use FFMPEG to make a mp4 movie. I have a beautifully working version in Python but it’s painfully slow. Some of my runs to generate about 4000 frames can take a couple of days on my fairly high end Win 10 machine. A single 1800x1200 frame can take up to a minute to compute depending on the situation.
using Images, ImageView, ColorTypes
x_size = 2
y_size = 3
step = 360.0 / (x_size * y_size - 1)
points = Array{HSV{Float64},2}(undef, x_size, y_size)
for x in 1:x_size, y in 1:y_size
m = step * (y_size * (x - 1) + y) - step
val = HSV(m, 1.0, 1.0)
points[x, y] = val
println(“points = $points”)

I would like to display the image
and also save it as a jpeg.

julia> function HSV_array(x_size, y_size)
           step = 360 / (x_size * y_size - 1)
           map(Iterators.product(1:x_size, 1:y_size)) do (x, y)
               m = step * (y_size * (x - 1) + y) - step
               HSV(m, 1.0, 1.0)

julia> @time points = HSV_array(1800, 1200);
  0.009032 seconds (2 allocations: 49.439 MiB)

julia> imshow(RGB.(points));

julia> save("test.jpeg", points)

You should be able to use iterative encoding from VideoIO.jl to write each frame directly to a FFMPEG buffer without needing to make a bunch of temporary files.

Fantastical and a big thanks to you stillyslalom.
All your suggestions worked. The Imshow & save commands solved my issues. I like your function but will need to study it more to understand it. (I’m an ancient programmer but relatively new to Julia, but love it. I’m retired and playing with math like Mandelbrot Set plotting and zooms, etc.)
Question: It greatly bothers me that I was unable to solve my plotting issue myself. I spent hours trying to find documentation and/or examples online. How can I find a reference to the imshow(RGB … command?

I’ll also follow up on the FFMPEG suggestion. Thanks.

Documentation discoverability is definitely harder for Julia than for Python - with a smaller userbase, there just aren’t as many tutorials. The best entry point for a given package’s documentation is its GitHub page. Simple packages will often just have a with the syntax and a few examples (that’s the case for ImageView.jl), while more complicated packages like Images.jl will have a link to a documentation website (often built with Documenter.jl). Julia Computing has an ecosystem-wide search page here that’s worth trying, but it’s fairly new, and doesn’t return rock-solid results just yet.

It’s really valuable to know what’s hard for a Julia beginner to find - the rest of us are used to navigating the ecosystem, but please keep taking note of where you hit dead ends so better signage can be provided for future learners.

1 Like