# import raster image
data(normforest)
normforest <- terra::unwrap(normforest)
# convert to matrix form
M <- ncol(normforest)
N <- nrow(normforest)
zmat <- matrix(terra::values(normforest), ncol = M, nrow = N, byrow = TRUE)
# calculate fourier transform and shift
ftmat <- fft(zmat)
ftshift <- fftshift(ftmat)
# plot real component
r <- terra::setValues(normforest, Re(ftshift))
terra::plot(r)
Run the code above in your browser using DataLab