# conv_via_fft.jl 2D FFT for filtering using MIRT: jim using Plots; default(titlefontsize=6, labelfontsize=6, legendfontsize=6, tickfontsize=5,) # adjust these as needed to for your plot using LaTeXStrings using FFTW: fft, ifft, fftshift, ifftshift rect(x) = abs(x) < 1/2 # convenient function nx = ?; ny = ? # sampling parameters dx = ?; dy = ? x = (-nx/2:nx/2-1) * dx # sample locations in x y = ? fxy = ? # (samples of) the image f(x,y) pl = Array{Any}(nothing, 3,3) pl[1] = jim(x, y, fxy, title=L"f(x,y)", xlabel=L"x", ylabel=L"y") # find the 2D FFT of the image # hint: fftshift() will be important somewhere near here! F = ? u = ? # frequency sample positions (ν_X) v = ? # frequency sample positions (ν_Y) # display spectrum F of f(x,y) pl[4] = jim(u, v, abs.(F), title=L"|F(\nu_X,\nu_Y)|", xlabel=L"\nu_X", ylabel=L"\nu_Y") pl[5] = jim(u, v, real.(F), title=L"F_R(\nu_X,\nu_Y)", xlabel=L"\nu_X", ylabel=L"\nu_Y") pl[6] = jim(u, v, imag.(F)*1e17, title=L"F_I(\nu_X,\nu_Y) \cdot 10^{17}", xlabel=L"\nu_X", ylabel=L"\nu_Y") # Create (samples of) filter frequency response, and display H = ? pl[3] = jim(u, v, H, title=L"H(\nu_X,\nu_Y)", xlabel=L"\nu_X", ylabel=L"\nu_Y") # Find spectrum of output image using convolution property of 2D FT G = ? # Find final image by returning to image domain # Watch out for fftshift() again! g = ? # display real and imaginary parts of g(x,y) # Hint: does your imaginary part make sense? pl[7] = jim(x, y, real.(g), title=L"g_R(x,y)", xlabel=L"x", ylabel=L"y") pl[8] = jim(x, y, imag.(g), title=L"g_I(x,y)", clim = (-1,1), xlabel=L"x", ylabel=L"y") pl[9] = jim(x, y, abs.(g), title=L"|g(x,y)|", xlabel=L"x", ylabel=L"y") maximum(abs.(imag.(g))) / maximum(abs.(g)) # check imaginary part pl[2] = plot(legend=false, grid=false, foreground_color_subplot=:white) # blank plot(pl...) #savefig("conv_via_fft.pdf")