Makie consistency problem in iteratively saved png resolution

Hi all,

In the following MWE there is a problem of resolution consistency when saving iteratively png from a Makie scene:

using GLMakie,AbstractPlotting,ImageCore
function save_png(img, i)
    fn=string(i)*".png"
    scene = AbstractPlotting.image(rotr90(img), show_axis = false);
    AbstractPlotting.save(fn, scene; resolution = (1920,1088), px_per_unit = 72)
    close(GLMakie.global_gl_screen())
    nothing
end

function res_png(nf)
    nx,ny=1920,1088

    for i=1:nf
        img = rand(RGB{N0f8}, nx, ny)
        save_png(img,i)
        println("Saved png resolution :", size(load(string(i,".png"))))
    end
end
res_png(100)

I would like all the saved png to have the same resolution: 1920,1088 as specified when calling the save function. Any ideas?

Thanks in advance for the time you will take to help me.

I suspect you have some other packages loaded, the set of packages in your using statement does not provide a load method. Replacing ImageCore with Images produces:

Saved png resolution :(1088, 1920)
Saved png resolution :(1088, 1920)
Saved png resolution :(1088, 1920)
Saved png resolution :(1088, 1920)
Saved png resolution :(1088, 1920)
.
.
.

Which looks like it is working to me.

@contradict, I though it was resolved… But actually it’s not the case. I rewrote a MWE, this time with a video as it’s closer to what I would like to do.

using VideoIO, FileIO
using GLMakie,AbstractPlotting


function save_png(img, i,rota)
    fn=string(i)*".png"
    scene = AbstractPlotting.image(rotr90(img), show_axis = false);
    AbstractPlotting.rotate!(scene,-rota)
    AbstractPlotting.save(fn, scene; resolution = (1920,1088), px_per_unit = 72)
    close(GLMakie.global_gl_screen())
    nothing
end


function ext_frames(vid_name::String, rota)
    io = VideoIO.testvideo(vid_name) # for testing purposes
    f = VideoIO.openvideo(io); ## Open the video
    img = read(f); ## Take the first frame
    n = 1
    save_png(img,n,rota)

    while !eof(f) ## While the video is not finished
        next_img = read!(f, img); ## Take the next frame
        n = n + 1
        save_png(next_img,n,rota)
        println("Saved png resolution :", size(load(string(n,".png"))))
    end
    close(f)
end

ext_frames("annie_oakley", pi/67)

I tried 3 times in a row, each time destroying my REPL in between. The first time it worked well until the 611th frames, at this time 16 consecutive frames were saved with a resolution of 2176, 3840 (my screen). This happened again at the 704th frames. The 2nd try worked properly. However, the third time I had again the same problems, after the 524th, 618th and 611th frames the 16 next were saved with a different resolution than the 1088,1920 asked.

Why I have this changes in resolution and how to fix it? And how to speed up the process ? And why this is so random?

Thanks in advance for the time you will take to look into it.

What OS is this? This is likely some weird OS window manager problem. Do you get an open window? Is this in the VSCode/Atom repl?

I’m working on macOS Big Sur 11.1. Indeed when the script is running I have an open window (exe).
It’s on VSCode v1.52.1.

Sigh, MacOS of course…
Open window + MacOS + VSCode is probably the worst combination for this kind of problem :smiley:
Can you try a clean REPL, with a hidden window?
AbstractPlotting.inline!(true) in the beginning of the script should make save(scene, "..") not open any window.

Ohh that’s a bad news then…

Where exactly you want me to add AbstractPlotting.inline!(true) ?
I tried right after the using, but also as the first line of the save_png(), it’s not solving the problem at all. The window is still opening and the resolution problem is still there…

Like this:

using GLMakie,AbstractPlotting,ImageCore, FileIO
AbstractPlotting.inline!(true)

function save_png(img, i)
    fn="test/$(i).png"
    scene = AbstractPlotting.image(rotr90(img), show_axis = false);
    AbstractPlotting.save(fn, scene; resolution = (1920,1088), px_per_unit = 72)
    close(GLMakie.global_gl_screen())
    nothing
end
mkdir("test")
function res_png(nf)
    nx,ny=1920,1088

    for i=1:nf
        img = rand(RGB{N0f8}, nx, ny)
        save_png(img,i)
        println("Saved png resolution :", size(load("test/$(i).png")))
    end
end
res_png(100)

Just tried this, and window is hidden & resolutions stay the same… Sigh, looks like another unexplainable osx bug…
On what AbstractPlotting version are you?

Nop, I still have the same problem… The resolution changed at the 59th image and that for the 16 following ones and then come back to the asked resolution. That’s really weird !

I’m with AbstractPlotting v0.14.4