forked from bnsreenu/python_for_microscopists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
021-scratch_assay_using_scikit_image.py
47 lines (36 loc) · 1.32 KB
/
021-scratch_assay_using_scikit_image.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
__author__ = "Sreenivas Bhattiprolu"
__license__ = "Feel free to copy, I appreciate if you acknowledge Python for Microscopists"
# https://www.youtube.com/watch?v=jcUx-TQpcM8
#Scratch Assay on time series images
import matplotlib.pyplot as plt
from skimage import io
from skimage.filters.rank import entropy
from skimage.morphology import disk
import numpy as np
from skimage.filters import threshold_otsu
import glob
time = 0
time_list=[]
area_list=[]
path = "images/scratch_assay/*.*"
for file in glob.glob(path):
dict={}
img=io.imread(file)
entropy_img = entropy(img, disk(3))
thresh = threshold_otsu(entropy_img)
binary = entropy_img <= thresh
scratch_area = np.sum(binary == 1)
print("time=", time, "hr ", "Scratch area=", scratch_area, "pix\N{SUPERSCRIPT TWO}")
time_list.append(time)
area_list.append(scratch_area)
time += 1
#print(time_list, area_list)
plt.plot(time_list, area_list, 'bo') #Print blue dots scatter plot
#Print slope, intercept
from scipy.stats import linregress
#print(linregress(time_list, area_list))
slope, intercept, r_value, p_value, std_err = linregress(time_list, area_list)
print("y = ",slope, "x", " + ", intercept )
print("R\N{SUPERSCRIPT TWO} = ", r_value**2)
#print("r-squared: %f" % r_value**2)