This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#required packages: | |
require(raster) | |
require(maptools) | |
require(Grid2Polygons) | |
#define breaks for the contour lines: | |
breaks <- seq(80, 200, length.out = 15) | |
#first convert the volcano matrix to a raster | |
poly_volcano <- raster(volcano) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create a slightly larger matrix and fill with relatively small values (60): | |
volcano2 <- matrix(60, nrow(volcano) + 2, ncol(volcano) + 2) | |
#copy the original matrix into the center of the new matrix: | |
volcano2[-nrow(volcano2),][,-ncol(volcano2)][-1,][,-1] <- volcano | |
#repeat the previous conversion steps and plot: | |
poly_volcano <- raster(volcano2) | |
poly_volcano <- rasterToContour(poly_volcano, levels = breaks) | |
poly_volcano <- SpatialLines2PolySet(poly_volcano) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
for (i in 1:length(poly_volcano)) | |
{ | |
temp <- poly_volcano@polygons[[i]]@Polygons | |
for (j in 1:length(temp)) | |
{ | |
if (length(temp) > 1) | |
{ | |
for (k in 1:length(temp)) | |
{ | |
if (j != k) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#create bounding box to which the final polygons needs to be clipped: | |
CP <- as(extent(0 + 2/ncol(volcano2), 1 - 2/ncol(volcano2), 0 + 2/nrow(volcano2), 1 - 2/nrow(volcano2)), "SpatialPolygons") | |
#clip polygons and plot: | |
final_volcano <- gIntersection(poly_volcano, CP, byid=TRUE) | |
png("volcano04.png", 200, 200) | |
par(oma = c(0,0,0,0), mar = c(0,0,0,0)) | |
plot(final_volcano, col = terrain.colors(length(poly_volcano)), border = NA) | |
dev.off() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#required packages: | |
require(jpeg) | |
#Read a jpeg from a website and store as matrix "mat_clown" | |
con <- file("http://4.bp.blogspot.com/-uObQLjPG8Xg/VceaZNyI-NI/AAAAAAAAx0o/ZlcTTB1pomU/s1600/fourier_efteling.jpg", "rb") | |
#make sure 'n' is big enough to hold your entire file: | |
jpg_clown <- readBin(con, "raw", n = 3e4) | |
close(con) | |
rm(con) | |
mat_clown <- readJPEG(jpg_clown) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#checker board pattern used to centre the Fourier spectrum: | |
checkerboard <- (-1)^(row(mat_clown) + col(mat_clown)) | |
#modify matrix with checkerboard pattern: | |
mat_checker <- mat_clown*checkerboard | |
#Discrete fast Fourier transform: | |
mat_fft <- fft(mat_checker) | |
#magnitude in frequency domain |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#select peaks in spectrum to filter out | |
#click on each peak, then end the locator | |
peaks <- data.frame(locator()) | |
#function to create a filter for circle shaped peaks in the spectrum | |
#dimensions: dimensions of the spectrum matrix | |
#x: x position of the centre of the circle to be filtered out | |
#y: y position of ... | |
#r: radius of circle to be filtered out of the spectrum | |
#gaussian: flag that indicates whether the circle should have a Gaussian density or not |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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)) / |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# required packages | |
require(rgdal) | |
require(OpenStreetMap) | |
# select files for which geotags need to | |
# be extracted and store filenames in data.frame | |
file_info <- data.frame(file.name = choose.files(filters = Filters["jpeg",])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# function to get a parameter value from EXIF code, | |
# x = a vector of character strings representing the EXIF codes of a file | |
# parameter = character string representing the parameter | |
# for which you want to extract the value | |
# the literal character string is returned for the requested parameter | |
get_EXIF_value <- function(x, parameter) | |
{ | |
line <- x[grepl(paste("EXIF_", parameter, "=", sep = ""), x)] | |
if (!is.null(line) && length(line) > 0) | |
{ |
OlderNewer