Skip to content

Commit 98c0837

Browse files
author
Corentin
committed
better atp options and treatment
1 parent ab66321 commit 98c0837

File tree

5 files changed

+36
-23
lines changed

5 files changed

+36
-23
lines changed

.gitignore

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

myoquant/commands/run_atp.py

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ def atp_analysis(
6363
None,
6464
help="Image channel to use for the analysis. If not specified, the analysis will be performed on all three channels.",
6565
),
66+
channel_first: bool = typer.Option(
67+
False,
68+
help="If the channel is the first dimension of the image, set this to True. False by default.",
69+
),
70+
rescale_exposure: bool = typer.Option(
71+
False,
72+
help="Rescale the image exposure if your image is not in the 0 255 forma, False by default.",
73+
),
6674
n_classes: int = typer.Option(
6775
2,
6876
max=10,
@@ -72,9 +80,10 @@ def atp_analysis(
7280
"median",
7381
help="The method to use to compute the intensity of the cell. Can be either 'median' or 'mean'.",
7482
),
75-
erosion: bool = typer.Option(
83+
erosion: int = typer.Option(
7684
False,
77-
help="Perform an erosion on the cells images to remove signal in the cell membrane (usefull for fluo)",
85+
max=45,
86+
help="Perform an erosion on the cells images to remove signal in the cell membrane (usefull for fluo). Expressed in percentage of the cell radius",
7887
),
7988
export_map: bool = typer.Option(
8089
True,
@@ -127,6 +136,7 @@ def atp_analysis(
127136
from ..src.ATP_analysis import run_atp_analysis
128137
import numpy as np
129138
from PIL import Image
139+
from skimage.exposure import rescale_intensity
130140

131141
try:
132142
from imageio.v2 import imread
@@ -153,8 +163,16 @@ def atp_analysis(
153163
progress.add_task(description="Reading all inputs...", total=None)
154164
image_ndarray = imread(image_path)
155165
if channel is not None:
156-
image_ndarray = image_ndarray[:, :, channel]
157-
166+
if channel_first:
167+
# Put the channel as third dimension instead of first
168+
image_ndarray = np.moveaxis(image_ndarray, 0, -1)
169+
image_ndarray = image_ndarray[:, :, channel]
170+
if rescale_exposure:
171+
image_ndarray = rescale_intensity(
172+
image_ndarray,
173+
in_range=(np.amin(image_ndarray), np.amax(image_ndarray)),
174+
out_range=np.uint8,
175+
)
158176
if mask_path is not None:
159177
mask_ndarray = imread(mask_path)
160178
if np.unique(mask_ndarray).shape[0] != 2:

myoquant/src/ATP_analysis.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def get_all_intensity(
17-
image_array, df_cellpose, intensity_method="median", erosion=False
17+
image_array, df_cellpose, intensity_method="median", erosion=None
1818
):
1919
all_cell_median_intensity = []
2020
for index in range(len(df_cellpose)):
@@ -97,7 +97,7 @@ def predict_all_cells(
9797
intensity_threshold,
9898
n_classes=2,
9999
intensity_method="median",
100-
erosion=False,
100+
erosion=None,
101101
):
102102
all_cell_median_intensity = get_all_intensity(
103103
histo_img, cellpose_df, intensity_method, erosion
@@ -146,7 +146,7 @@ def run_atp_analysis(
146146
intensity_threshold=None,
147147
n_classes=2,
148148
intensity_method="median",
149-
erosion=False,
149+
erosion=None,
150150
):
151151
df_cellpose = df_from_cellpose_mask(mask_cellpose)
152152
class_predicted_all, intensity_all, intensity_threshold = predict_all_cells(

myoquant/src/common_func.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,19 @@ def df_from_stardist_mask(mask, intensity_image=None):
173173
return df_stardist
174174

175175

176-
def extract_single_image(raw_image, df_props, index, erosion=False):
176+
def extract_single_image(raw_image, df_props, index, erosion=None):
177177
single_entity_img = raw_image[
178178
df_props.iloc[index, 5] : df_props.iloc[index, 7],
179179
df_props.iloc[index, 6] : df_props.iloc[index, 8],
180180
].copy()
181181
surface_area = df_props.iloc[index, 1]
182182
cell_radius = math.sqrt(surface_area / math.pi)
183-
single_entity_mask = df_props.iloc[index, 9]
184-
erosion_size = int(cell_radius / 5) # 20% of the cell
185-
if erosion:
186-
for i in range(erosion_size):
183+
single_entity_mask = df_props.iloc[index, 9].copy()
184+
erosion_size = cell_radius * (
185+
erosion / 100
186+
) # Erosion in percentage of the cell radius
187+
if erosion is not None:
188+
for i in range(int(erosion_size)):
187189
single_entity_mask = binary_erosion(
188190
single_entity_mask, out=single_entity_mask
189191
)

poetry.lock

Lines changed: 3 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)