<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;"># -*- coding: utf-8 -*-
"""
Created on Wed Sep 26 15:40:00 2018

@author: George Lu
"""

#WARNING: CODE VERY UNOPTIMZED, RUNTIME &gt;&gt;1 HOUR

import gyration
from os import listdir
import numpy as np
import pylab as pl

# load all images of directory:
path_to_image_folder = './'   #  a string specifying the path to the folder that will contain the input image
					 		# folder and all the new folders with the processed images.

image_folder_name = 'foldername'  # the name of the folder with the input images.
file_list = listdir(path_to_image_folder+image_folder_name)  
file_list = sorted([name for name in file_list if (name.endswith('.tif') and not name.startswith('.'))])  
areas = []
radii = []

for image_file_name in file_list:
    area, radius = gyration.Area_and_Radius(path_to_image_folder+image_folder_name+'/'+image_file_name)
    areas.append(area)
    radii.append(radius)
    

np.savetxt(path_to_image_folder+image_folder_name + '_area + radius data', (areas, radii))

# linear fit, polynomial of degree 1 --&gt; a line
coeffs=np.polyfit(np.log(area), np.log(radii), 1)
D = 1/coeffs[0]

print("The Haussdorf dimension of the growing fractal is " + str(D))

pl.plot(np.log(areas),np.log(radii), 'o', mfc='none', label='data')
pl.plot(np.log(areas), np.polyval(coeffs,np.log(area)),label='fit')
pl.xlabel('log A$')
pl.ylabel('log R_g')
pl.title(image_folder_name +' D = '+str(D))
pl.legend()
pl.savefig(image_folder_name+'_Rg_powerlaw.pdf')</pre></body></html>