Skip to content

Instantly share code, notes, and snippets.

@pepijn-devries
Last active August 29, 2015 14:27
Show Gist options
  • Save pepijn-devries/f22e762ab98f5bfb209d to your computer and use it in GitHub Desktop.
Save pepijn-devries/f22e762ab98f5bfb209d to your computer and use it in GitHub Desktop.
#reconstruct fourier transformed image from filtered spectrum:
re_construct <- cos(phase)*magni_filter
im_construct <- sin(phase)*magni_filter
mat_fft_construct <- matrix(complex(real = re_construct, imaginary = im_construct), nrow(mat_clown), ncol(mat_clown))
#Apply inversed Fourier transform to obtain the filtered image:
mat_clown_constr <- Re(fft(mat_fft_construct, inv = T))*checkerboard/prod(dim(mat_clown))
#normalize the resulting matrix between 0 and 1
mat_clown_constr <- (mat_clown_constr - min(mat_clown_constr)) /
(max(mat_clown_constr) - min(mat_clown_constr))
#save image after filtering:
con <- file("clown_filtered.jpg", "wb")
clown_raw <- writeJPEG(rotate(rotate(rotate(mat_clown_constr))), raw(), quality = 0.7)
writeBin(clown_raw, con)
close(con)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment