Skip to content

Commit 7550a15

Browse files
author
Corentin
committed
bug fix atp
1 parent 98c0837 commit 7550a15

File tree

4 files changed

+38
-12
lines changed

4 files changed

+38
-12
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,4 +170,5 @@ debug_data/
170170
!cytoplasm.tif
171171
!binary_mask_sdh.tif
172172
data/*
173-
*intensity_plot.png
173+
*intensity_plot.png
174+
*.idea

myoquant/commands/run_atp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def atp_analysis(
166166
if channel_first:
167167
# Put the channel as third dimension instead of first
168168
image_ndarray = np.moveaxis(image_ndarray, 0, -1)
169-
image_ndarray = image_ndarray[:, :, channel]
169+
image_ndarray = image_ndarray[:, :, channel]
170170
if rescale_exposure:
171171
image_ndarray = rescale_intensity(
172172
image_ndarray,

myoquant/src/ATP_analysis.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_all_intensity(
3333

3434
def estimate_threshold(intensity_list, n_classes=2):
3535
density = gaussian_kde(intensity_list)
36-
density.covariance_factor = lambda: 0.25
36+
density.covariance_factor = lambda: 0.05
3737
density._compute_covariance()
3838

3939
# Create a vector of 256 values going from 0 to 256:
@@ -64,13 +64,16 @@ def plot_density(all_cell_median_intensity, intensity_threshold, n_classes=2):
6464
intensity_threshold = estimate_threshold(all_cell_median_intensity, n_classes)
6565
fig, ax = plt.subplots(figsize=(10, 5))
6666
density = gaussian_kde(all_cell_median_intensity)
67-
density.covariance_factor = lambda: 0.25
67+
density.covariance_factor = lambda: 0.1
6868
density._compute_covariance()
6969

70-
# Create a vector of 256 values going from 0 to 256:
70+
# Create a vector of 256 values going from 0 to 25
7171
xs = np.linspace(0, 255, 256)
7272
density_xs_values = density(xs)
73-
ax.plot(xs, density_xs_values, label="Estimated Density")
73+
ax.hist(
74+
all_cell_median_intensity, bins=255, density=True, alpha=0.5, label="Histogram"
75+
)
76+
ax.plot(xs, density_xs_values, label="Estimated Density", linewidth=3)
7477
for values in intensity_threshold:
7578
ax.axvline(x=values, color="red", label="Threshold")
7679
ax.set_xlabel("Pixel Intensity")

notebooks/atp_exploration.ipynb

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@
1818
"metadata": {},
1919
"outputs": [],
2020
"source": [
21-
"ATP_IMAGE_DF = df[df[\"Staining method\"] == \"ATP 9.4\"]\n",
22-
"ATP_IMAGE_NAME = ATP_IMAGE_DF[\"Number\"].tolist()\n",
2321
"IMAGE_INDEX = 189\n",
2422
"# show the first image in the list using the image name\n",
2523
"from IPython.display import Image\n",
26-
"Image(filename='../data/muscle_atlas/images/' + ATP_IMAGE_NAME[IMAGE_INDEX])"
24+
"Image(filename='../sample_img/sample_atp.jpg')"
2725
]
2826
},
2927
{
@@ -39,7 +37,7 @@
3937
"except ImportError:\n",
4038
" from imageio import imread\n",
4139
"\n",
42-
"image_array = imread('../data/muscle_atlas/images/' + ATP_IMAGE_NAME[IMAGE_INDEX])\n",
40+
"image_array = imread('../sample_img/sample_atp.jpg')\n",
4341
"model_cellpose = load_cellpose()\n",
4442
"mask_cellpose = run_cellpose(image_array, model_cellpose)\n",
4543
"plt.imshow(mask_cellpose)"
@@ -92,6 +90,19 @@
9290
" all_cell_median_intensity.append(single_cell_median_intensity)\n"
9391
]
9492
},
93+
{
94+
"cell_type": "code",
95+
"execution_count": null,
96+
"metadata": {},
97+
"outputs": [],
98+
"source": [
99+
"# Histogram plot of the median pixel intensity of all cells\n",
100+
"plt.hist(all_cell_median_intensity, bins=255, density=True, alpha=0.5)\n",
101+
"plt.plot(xs,density(xs))\n",
102+
"plt.xlim(50,220)\n",
103+
"plt.show()"
104+
]
105+
},
95106
{
96107
"cell_type": "code",
97108
"execution_count": null,
@@ -103,7 +114,7 @@
103114
"# Build a \"density\" function based on the dataset\n",
104115
"# When you give a value from the X axis to this function, it returns the according value on the Y axis\n",
105116
"density = gaussian_kde(all_cell_median_intensity)\n",
106-
"density.covariance_factor = lambda : .25\n",
117+
"density.covariance_factor = lambda : .05\n",
107118
"density._compute_covariance()\n",
108119
"\n",
109120
"# Create a vector of 256 values going from 0 to 256:\n",
@@ -115,10 +126,19 @@
115126
"# Make the chart\n",
116127
"# We're actually building a line chart where x values are set all along the axis and y value are\n",
117128
"# the corresponding values from the density function\n",
129+
"\n",
118130
"plt.plot(xs,density(xs))\n",
131+
"plt.xlim(50,220)\n",
119132
"plt.show()"
120133
]
121134
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"metadata": {},
139+
"outputs": [],
140+
"source": []
141+
},
122142
{
123143
"cell_type": "code",
124144
"execution_count": null,
@@ -179,7 +199,9 @@
179199
"threshold = sorted_peaks[0]+xs[min_index]\n",
180200
"print(threshold)\n",
181201
"# Plot the data\n",
182-
"plt.plot(xs, density(xs), label='Density')\n",
202+
"plt.hist(all_cell_median_intensity, bins=255, density=True, alpha=0.5, label='Histogram')\n",
203+
"plt.plot(xs,density(xs), label='Density', linewidth=3)\n",
204+
"plt.xlim(50,220)\n",
183205
"plt.axvline(threshold, color='r', label='Threshold')\n",
184206
"plt.legend()\n",
185207
"plt.show()"

0 commit comments

Comments
 (0)