Skip to content

Commit

Permalink
bug fix atp
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin committed Feb 27, 2023
1 parent 98c0837 commit 7550a15
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,5 @@ debug_data/
!cytoplasm.tif
!binary_mask_sdh.tif
data/*
*intensity_plot.png
*intensity_plot.png
*.idea
2 changes: 1 addition & 1 deletion myoquant/commands/run_atp.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def atp_analysis(
if channel_first:
# Put the channel as third dimension instead of first
image_ndarray = np.moveaxis(image_ndarray, 0, -1)
image_ndarray = image_ndarray[:, :, channel]
image_ndarray = image_ndarray[:, :, channel]
if rescale_exposure:
image_ndarray = rescale_intensity(
image_ndarray,
Expand Down
11 changes: 7 additions & 4 deletions myoquant/src/ATP_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def get_all_intensity(

def estimate_threshold(intensity_list, n_classes=2):
density = gaussian_kde(intensity_list)
density.covariance_factor = lambda: 0.25
density.covariance_factor = lambda: 0.05
density._compute_covariance()

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

# Create a vector of 256 values going from 0 to 256:
# Create a vector of 256 values going from 0 to 25
xs = np.linspace(0, 255, 256)
density_xs_values = density(xs)
ax.plot(xs, density_xs_values, label="Estimated Density")
ax.hist(
all_cell_median_intensity, bins=255, density=True, alpha=0.5, label="Histogram"
)
ax.plot(xs, density_xs_values, label="Estimated Density", linewidth=3)
for values in intensity_threshold:
ax.axvline(x=values, color="red", label="Threshold")
ax.set_xlabel("Pixel Intensity")
Expand Down
34 changes: 28 additions & 6 deletions notebooks/atp_exploration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,10 @@
"metadata": {},
"outputs": [],
"source": [
"ATP_IMAGE_DF = df[df[\"Staining method\"] == \"ATP 9.4\"]\n",
"ATP_IMAGE_NAME = ATP_IMAGE_DF[\"Number\"].tolist()\n",
"IMAGE_INDEX = 189\n",
"# show the first image in the list using the image name\n",
"from IPython.display import Image\n",
"Image(filename='../data/muscle_atlas/images/' + ATP_IMAGE_NAME[IMAGE_INDEX])"
"Image(filename='../sample_img/sample_atp.jpg')"
]
},
{
Expand All @@ -39,7 +37,7 @@
"except ImportError:\n",
" from imageio import imread\n",
"\n",
"image_array = imread('../data/muscle_atlas/images/' + ATP_IMAGE_NAME[IMAGE_INDEX])\n",
"image_array = imread('../sample_img/sample_atp.jpg')\n",
"model_cellpose = load_cellpose()\n",
"mask_cellpose = run_cellpose(image_array, model_cellpose)\n",
"plt.imshow(mask_cellpose)"
Expand Down Expand Up @@ -92,6 +90,19 @@
" all_cell_median_intensity.append(single_cell_median_intensity)\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Histogram plot of the median pixel intensity of all cells\n",
"plt.hist(all_cell_median_intensity, bins=255, density=True, alpha=0.5)\n",
"plt.plot(xs,density(xs))\n",
"plt.xlim(50,220)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -103,7 +114,7 @@
"# Build a \"density\" function based on the dataset\n",
"# When you give a value from the X axis to this function, it returns the according value on the Y axis\n",
"density = gaussian_kde(all_cell_median_intensity)\n",
"density.covariance_factor = lambda : .25\n",
"density.covariance_factor = lambda : .05\n",
"density._compute_covariance()\n",
"\n",
"# Create a vector of 256 values going from 0 to 256:\n",
Expand All @@ -115,10 +126,19 @@
"# Make the chart\n",
"# We're actually building a line chart where x values are set all along the axis and y value are\n",
"# the corresponding values from the density function\n",
"\n",
"plt.plot(xs,density(xs))\n",
"plt.xlim(50,220)\n",
"plt.show()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -179,7 +199,9 @@
"threshold = sorted_peaks[0]+xs[min_index]\n",
"print(threshold)\n",
"# Plot the data\n",
"plt.plot(xs, density(xs), label='Density')\n",
"plt.hist(all_cell_median_intensity, bins=255, density=True, alpha=0.5, label='Histogram')\n",
"plt.plot(xs,density(xs), label='Density', linewidth=3)\n",
"plt.xlim(50,220)\n",
"plt.axvline(threshold, color='r', label='Threshold')\n",
"plt.legend()\n",
"plt.show()"
Expand Down

0 comments on commit 7550a15

Please sign in to comment.