setwd(".../Project/R/Workspace/Task1")
library("EBImage" , lib.loc="~/R/win-library/3.2")
# Image
img
display(img, title='Image')
# Grayscaled
img_gray
# FFT
img_ff
###################################################
###################################################
# FFT SHIFT
fftshift
rows
cols
swap_up_down
rows_half
return(rbind(img_ff[((rows_half+1):rows), (1:cols)], img_ff[(1:rows_half), (1:cols)]))
}
swap_left_right
cols_half
return(cbind(img_ff[1:rows, ((cols_half+1):cols)], img_ff[1:rows, 1:cols_half]))
}
if (dim == -1) {
img_ff
return(swap_left_right(img_ff))
}
else if (dim == 1) {
return(swap_up_down(img_ff))
}
else if (dim == 2) {
return(swap_left_right(img_ff))
}
else {
stop("Invalid dimension parameter")
}
}
ifftshift
rows
cols
swap_up_down
rows_half
return(rbind(img_ff[((rows_half+1):rows), (1:cols)], img_ff[(1:rows_half), (1:cols)]))
}
swap_left_right
cols_half
return(cbind(img_ff[1:rows, ((cols_half+1):cols)], img_ff[1:rows, 1:cols_half]))
}
if (dim == -1) {
img_ff
return(swap_up_down(img_ff))
}
else if (dim == 1) {
return(swap_up_down(img_ff))
}
else if (dim == 2) {
return(swap_left_right(img_ff))
}
else {
stop("Invalid dimension parameter")
}
}
###################################################
###################################################
# FFT SHIFT
# Magnitude and Phase
magntd
phase
img_fftsh
display(log(img_fftsh),title="FFT")