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?