Skip to content

Calculating the fractal dimension of borders #7

@ThomasWinning

Description

@ThomasWinning

Hi Kyrcha,

I am attempting to conduct research where I calculate fractal dimensions of borders. I came across your previous work on calculating the fractal dimension of the Greek coastline on your blog (https://kyrcha.info/2013/04/19/calculating-the-fractal-dimension-of-the-greek-coastline-1-25) which I found extremely fascinating. I would like to know how I can adapt your code as a part of my investigation as I am simply a beginner/novice in R. I have used my own .jpeg image to form the basis of my trials:
Coastline

However, when inputting the following code:

library(jpeg) rm(list=ls()) img <- readJPEG(normalizePath('Coastline.jpeg')) # filter out mainland img[img > 0.5] = 1 # divisors of 1600 # 1,2,4,5,8,10,16,20,25,32,40,50,64,80,100,160,200,320,400,800,1600 boxSizes = c(50, 40, 32, 25, 20, 16, 10, 8, 5, 4) h = img[,,1] data = data.frame() for(k in 1:length(boxSizes)) { b = boxSizes[k] x = dim(img[,,1])[1] ratio = x/b # https://stat.ethz.ch/pipermail/r-help/2012-February/303163.html k = kronecker(matrix(1:(ratio^2), ratio, byrow = TRUE), matrix(1,b,b)) g = lapply(split(h,k), matrix, nr = b) counter = 0; for(i in 1:length(g)) { counter = counter + any(g[[i]] < 0.999) } data = rbind(data,c(log(counter),log(1/b))) } names(data) = c("Y", "X") model = lm(Y~., data=data) cat(coef(model), "\n")

The output is 9.704228 1.220103

I would like to know what I have done wrong or how I can adapt the code in order to not only be outputted with the fractal dimension but also, a plot of both the logarithmic graph (much like the one in your blog) as well as a mapped plot of the .jpeg image with the boxes on it (if possible).

Many thanks,
Thomas

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions