Skip to content

Commit

Permalink
better atp options and treatment
Browse files Browse the repository at this point in the history
  • Loading branch information
Corentin committed Feb 17, 2023
1 parent ab66321 commit 98c0837
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,4 @@ debug_data/
!cytoplasm.tif
!binary_mask_sdh.tif
data/*
sample_atp_intensity_plot.png
*intensity_plot.png
26 changes: 22 additions & 4 deletions myoquant/commands/run_atp.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,14 @@ def atp_analysis(
None,
help="Image channel to use for the analysis. If not specified, the analysis will be performed on all three channels.",
),
channel_first: bool = typer.Option(
False,
help="If the channel is the first dimension of the image, set this to True. False by default.",
),
rescale_exposure: bool = typer.Option(
False,
help="Rescale the image exposure if your image is not in the 0 255 forma, False by default.",
),
n_classes: int = typer.Option(
2,
max=10,
Expand All @@ -72,9 +80,10 @@ def atp_analysis(
"median",
help="The method to use to compute the intensity of the cell. Can be either 'median' or 'mean'.",
),
erosion: bool = typer.Option(
erosion: int = typer.Option(
False,
help="Perform an erosion on the cells images to remove signal in the cell membrane (usefull for fluo)",
max=45,
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",
),
export_map: bool = typer.Option(
True,
Expand Down Expand Up @@ -127,6 +136,7 @@ def atp_analysis(
from ..src.ATP_analysis import run_atp_analysis
import numpy as np
from PIL import Image
from skimage.exposure import rescale_intensity

try:
from imageio.v2 import imread
Expand All @@ -153,8 +163,16 @@ def atp_analysis(
progress.add_task(description="Reading all inputs...", total=None)
image_ndarray = imread(image_path)
if channel is not None:
image_ndarray = image_ndarray[:, :, channel]

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]
if rescale_exposure:
image_ndarray = rescale_intensity(
image_ndarray,
in_range=(np.amin(image_ndarray), np.amax(image_ndarray)),
out_range=np.uint8,
)
if mask_path is not None:
mask_ndarray = imread(mask_path)
if np.unique(mask_ndarray).shape[0] != 2:
Expand Down
6 changes: 3 additions & 3 deletions myoquant/src/ATP_analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def get_all_intensity(
image_array, df_cellpose, intensity_method="median", erosion=False
image_array, df_cellpose, intensity_method="median", erosion=None
):
all_cell_median_intensity = []
for index in range(len(df_cellpose)):
Expand Down Expand Up @@ -97,7 +97,7 @@ def predict_all_cells(
intensity_threshold,
n_classes=2,
intensity_method="median",
erosion=False,
erosion=None,
):
all_cell_median_intensity = get_all_intensity(
histo_img, cellpose_df, intensity_method, erosion
Expand Down Expand Up @@ -146,7 +146,7 @@ def run_atp_analysis(
intensity_threshold=None,
n_classes=2,
intensity_method="median",
erosion=False,
erosion=None,
):
df_cellpose = df_from_cellpose_mask(mask_cellpose)
class_predicted_all, intensity_all, intensity_threshold = predict_all_cells(
Expand Down
12 changes: 7 additions & 5 deletions myoquant/src/common_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,17 +173,19 @@ def df_from_stardist_mask(mask, intensity_image=None):
return df_stardist


def extract_single_image(raw_image, df_props, index, erosion=False):
def extract_single_image(raw_image, df_props, index, erosion=None):
single_entity_img = raw_image[
df_props.iloc[index, 5] : df_props.iloc[index, 7],
df_props.iloc[index, 6] : df_props.iloc[index, 8],
].copy()
surface_area = df_props.iloc[index, 1]
cell_radius = math.sqrt(surface_area / math.pi)
single_entity_mask = df_props.iloc[index, 9]
erosion_size = int(cell_radius / 5) # 20% of the cell
if erosion:
for i in range(erosion_size):
single_entity_mask = df_props.iloc[index, 9].copy()
erosion_size = cell_radius * (
erosion / 100
) # Erosion in percentage of the cell radius
if erosion is not None:
for i in range(int(erosion_size)):
single_entity_mask = binary_erosion(
single_entity_mask, out=single_entity_mask
)
Expand Down
13 changes: 3 additions & 10 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 98c0837

Please sign in to comment.