Dct error when using Images

Hello everyone,
I have the following code

using TestImages, ImageView
img = testimage("cameraman")
pixels = img[1:8,1:8]
pixels = convert(Array{Float32}, pixels)
freqs = dct(pixels)
round(freqs)
pixels2 = idct(freqs)

but i can not find dct function so i got the following error
UndefVarError: dct not defined
Thanks in advanced

Hello,
Try loading the FFTW package: using FFTW

https://juliamath.github.io/FFTW.jl/latest/fft.html

1 Like

Thanks a lot.
It works now. But my question is that pixels == pixels2 should be true but it is false. can U help me with this?
Here is the full code

pixels = img[1:8,1:8]
pixels = convert(Array{Float32}, pixels)
freqs = dct(pixels)
round(freqs)
pixels2 = idct(freqs)
pixels == pixels2```

Thanks

Floating-point rounding errors will make them slightly unequal. If you do:

using LinearAlgebra
norm(pixels - pixels2) / norm(pixels2)

you should see that the relative difference is extremely small. More succinctly, you could check pixels ≈ pixels2, which calls isapprox.

so how to solve this problem?

You should always expect small rounding errors in any nontrivial floating-point calculation. Why is it a problem for you?

3 Likes