-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmain_image_analysis.py
More file actions
125 lines (106 loc) · 5.55 KB
/
main_image_analysis.py
File metadata and controls
125 lines (106 loc) · 5.55 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"""
Given an image captured for a % PEO / % DEX
mixture, try to automatically determine
the (average?) diameter of droplets present
in the image, as a proxy for phase separation.
Presumably, we'll use a diameter of `0` to indicate
absence of relevant droplets.
Part of the purpose here is to avoid human bias
in the generation of the response variables for
our downstream ML work.
"""
from neat_ml import lib
import glob
import numpy as np
def main():
# Of course the image data is too large to
# commit to the repo, so it is downloaded from Google Drive
# by the user independently, before running this code
data_root_path = "/Users/treddy/LANL/LDRD_DR_NEAT_data/Images"
# let's find all the % PEO / % DEX .tiff filepaths and do
# a few sanity checks
img_filepaths = glob.glob(f"{data_root_path}/**/*.tiff",
recursive=True)
assert len(img_filepaths) == 46
# check that images all have the same pixel dims
# (2456 x 2052 at the time of writing)
lib.check_image_dim_consistency(img_filepaths)
# Parse out the (WT % DEX, WT % PEO) information
# from the image filepaths, and start building relevant
# information into a DataFrame
df = lib.build_df_from_exp_img_paths(img_filepaths)
assert df.shape == (46, 3)
# had a bug where PEO/DEX columns were accidentally
# the same, so rule that out:
diff = df["WT% PEO"] - df["WT% DEX"]
assert not np.allclose(diff, np.zeros(df.shape[0]))
# Produce a standard plot of the binary phase system
# points (we don't have phase "labels" yet)
# TODO: should rename this function to something more generic
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_",
)
# there are a variety of ways we could try to estimate
# the droplet sizes (diameters); perhaps it makes sense to try a few
# and compare them
# 1) Using the Hough Transform
df = lib.skimage_hough_transform(df=df, debug=True)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_hough_",
title_addition="(labels from median Hough radii)",
y_pred=df["median_radii_skimage_hough"],
cbar_label="median Hough radii",
)
# 2) Using Blob Detection Techniques
df = lib.blob_detection(df=df, debug=True)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_DoH_sigma",
title_addition="(labels from median DoH sigma/radii)",
y_pred=df["median_radii_DoH"],
cbar_label="median DoH sigma",
)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_DoH_num_blobs",
title_addition="(labels from DoH num blobs)",
y_pred=df["num_blobs_DoH"],
norm="symlog",
cbar_label="symlog scaled blob count",
)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_LoG_num_blobs",
title_addition="(labels from LoG num blobs)",
y_pred=df["num_blobs_LoG"],
norm="symlog",
cbar_label="symlog scaled blob count",
)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_LoG_radii",
title_addition="(labels from median LoG radii)",
y_pred=df["median_radii_LoG"],
cbar_label="median LoG radii",
)
# try with OpenCV as well:
df = lib.opencv_blob_detection(df=df, debug=True)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_OpenCV_num_blobs",
title_addition="(labels from OpenCV num blobs)",
y_pred=df["num_blobs_opencv"],
norm="symlog",
cbar_label="symlog scaled blob count",
)
lib.plot_input_data_cesar_MD(df=df,
title="Plate Reader Image Data for PEO/DEX\n",
fig_name="plate_reader_image_points_OpenCV_radii",
title_addition="(labels from OpenCV median radii)",
y_pred=df["median_radii_opencv"],
cbar_label="median OpenCV radii",
)
if __name__ == "__main__":
main()