Hello Julia plotting experts, I want to annotate images by drawing text over the pixels of an image. This is to generate a lossless video where each frame shows an animated grid of tiles, each output by a different super-resolution algorithms (using VideoIO.jl). The pixels must remain accurate, i.e. they shouldn’t get blurred, change dimensions, subpixel-shift, etc. Ideally I’d like this to run my script as headless command-line tool so I’d like to avoid dealing with OpenGL windows, and/or saving temporary images to disk.
I’m easily able to load the uncompressed images, extract the section that will become tiles, and composite them through Array manipulation, then feed them frame-by-frame to VIdeoIO. The issue I have is with adding text labels above or ideally overlaid on top of each tile, without messing up the tiles’ pixels.
The closest I’ve gotten to a solution so far is:
using Plots
#... load the image tile into `img`... e.g. 320x320 pixels
plot(section, title="bla",
#xformatter=x->2x, yformatter=y->2y,
axis=nothing,
border=:none, fmt=:png,
size=(320+40*2, 320+40*2), # try to guess how much padding is still left on the edges
xaxis=false, ticks=false,
padding=(0, 0))
This approach suffers from many issues:
- The tile pixels aren’t aligned to the rendered pixels. There is a subpixel shift (half a pixel I guess).
- There remains a white border in the resulting png
- I couldn’t find an easy way to extract a pixel array from the png image, without saving it to disk and reloading it.
- I couldn’t find an easy way to reposition the title within the tile, e.g. bottom-left corner within the tile. But I could work-around this if I get an array.
Worst case, if problem 3 is resolved, I could use Plots.jl as an overly-complex text renderer, and manually composite the title over the tiles’ array. But surely there’s a more elegant way. And I sure would like to take advantage of Plots.jl other features down the line, e.g. to overlay graphs over the tile.
Thanks a lot!
Christian
PS: I confirmed gr is the default back-end. I don’t mind using other back-ends if that helps.