Cannot load image and do fftshift inside the same function

Ah, yeah, it looks like the image loading code inside testimage (which I think uses ImageIO.jl internally) does some magic to lazily load different packages to handle different image types.

I can think of two different ways to avoid this issue:

  1. Use invokelatest to run functions that depend on img within the context of your function:
julia> using TestImages

julia> function f()
         img = testimage("mandrill")
         Base.invokelatest(size, img)
       end
f (generic function with 1 method)

julia> f()
(512, 512)

You can learn more about invokelatest here: Essentials · The Julia Language

  1. Ensure that TiffImages is already loaded so that testimage doesn’t need to do its lazy loading in the background:
julia> using TestImages, TiffImages

julia> function f()
         img = testimage("mandrill")
         size(img)
       end
f (generic function with 1 method)

julia> f()
(512, 512)

I would also consider creating an issue over at GitHub - JuliaImages/TestImages.jl: commonly used test images , since I’m sure you’re not the only person to have had this problem.

2 Likes