forked from bnsreenu/python_for_image_processing_APEER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tutorial54-scratch_assay_in_python.py
48 lines (38 loc) · 1.53 KB
/
tutorial54-scratch_assay_in_python.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
48
#Video Playlist: https://www.youtube.com/playlist?list=PLHae9ggVvqPgyRQQOtENr6hK0m1UquGaG
#Scratch Assay on time series images
# https://www.ncbi.nlm.nih.gov/pmc/articles/PMC5154238/
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
#Use glob to extract image names and load them.
import glob
time = 0
scale = 0.45 # microns/pixel
time_list=[]
area_list=[]
path = "images/scratch_assay/*.*"
#Put the code from single image segmentation in af for loop
# to apply segmentaion to all images
for file in glob.glob(path):
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)
scratch_area = scratch_area*((scale)**2) #Convert to microns from pixel units
print("time=", time, "hr ", "Scratch area=", scratch_area, "um\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 #Linear regression
#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)