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
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?
4 Likes
I am so sorry
but when I tried it again now. It is not work. I don’t know why even if I write FFTW.dct
Any Suggestions?
Broadcast round()
when applied to the matrix of floats freqs
, as follows:
round.(freqs)
yhuang
9
Actually, pixels
and pixels2
should not even be close since you applied the round
step, which brings you some loss.