Error in Images (FFTW.dct)

Hello
I have the following code

using  FFTW
using TestImages, ImageView, Random
using Plots

module Codec1
    function blockdct6(img::Matrix{Float32})
        y, x = size(img)
        outx = div(x, 8)
        outy = div(y, 8)
        
        bx = 1:8:outx*8
        by = 1:8:outy*8
        
        mask = zeros(8,8)
        mask[1:3,1:3] = [1 1 1; 1 1 0; 1 0 0]
        
        freqs = Array{Float32}(undef, outy*8, outx*8)
        for i in bx, j in by
            freqs[j:j+7,i:i+7] = dct(img[j:j+7,i:i+7])
            freqs[j:j+7,i:i+7] .*= mask
        end
        return freqs
    end

    function blockidct(freqs::Matrix{Float32})
        y, x = size(freqs)
        bx = 1:8:x
        by = 1:8:y
        
        pixels = Array{Float32}(undef, y, x)
        for i in bx, j in by
            pixels[j:j+7,i:i+7] = idct(freqs[j:j+7,i:i+7])
        end
        
        return pixels
    end

    function add_noise_to_frequencies(freqs::Matrix{Float32}, scale::Float32)
        noisy_freqs = freqs .+ scale * randn(size(freqs))
        return noisy_freqs
    end
end

In REPL i do the following

img = testimage("cameraman")  
img_float = Float32.(img)   
freqs = Codec.blockdct6(img_float)
noisy_freqs = Codec.add_noise_to_frequencies(freqs, 10.0)
img_noisy_float = Codec.blockidct(noisy_freqs)
img_noisy = Gray.(img_noisy_float)


plot(1:2, [Gray.(img_float), img_noisy], seriestype=:heatmap, title=["Original Image" "Noisy Image"], color=:grays)

when I run freqs = Codec.blockdct6(img_float)
I got the error
UndefVarError: dct not defined
Stacktrace:
[1] blockdct6(img::Matrix{Float32})
@ Main.Codec1 ~/Documents/Linkoping Research/PhD Courses/Current Programming Languages and Paradigms/Julia Lang /Day3_2_Easy.jl:26
[2] top-level scope
@ REPL[5]:1
even if I use FFTW.dct
Any solution?

Did you forget to add using FFTW?

not working in both cases

One more question I used 3 single quotes to start writre code
how to exit from them and start to write plain text

The three backquotes should be on a line by themselves, either to start or to end the code block.

1 Like

Try FFTW.dct?

I’m on my phone right now so I can’t check this; I can’t remember whether dct is exported?

You need to put the appropriate using statements into the module as well.

1 Like

not work. I don’t think it’s depricated. It runs on REPL well

What do U mean?
Can U explain more?

You use dct inside your module called Codec1. So you need to have the corresponding using statement also inside the module’s block:

using TestImages, ImageView, Random
using Plots
# using FFTW  # don't think you need it here

module Codec1
    using FFTW # import it into this module because here you use the dct function
    
    function blockdct6(img::Matrix{Float32})
        # rest of code