Skip to content
Snippets Groups Projects
Commit 8b0f55b5 authored by Alán Muñoz's avatar Alán Muñoz
Browse files

reorganise and add otsu import

parent a8187318
No related branches found
No related tags found
No related merge requests found
...@@ -16,12 +16,21 @@ import math ...@@ -16,12 +16,21 @@ import math
import numpy as np import numpy as np
from scipy import ndimage from scipy import ndimage
from sklearn.cluster import KMeans from sklearn.cluster import KMeans
from skimage.filters import threshold_otsu
# Basic extraction functions
def area(cell_mask, trap_image=None): def area(cell_mask, trap_image=None):
return np.sum(cell_mask, dtype=int) return np.sum(cell_mask, dtype=int)
def eccentricity(cell_mask, trap_image=None):
min_ax, maj_ax = min_maj_approximation(cell_mask)
return np.sqrt(maj_ax ** 2 - min_ax ** 2) / maj_ax
def mean(cell_mask, trap_image): def mean(cell_mask, trap_image):
return np.mean(trap_image[np.where(cell_mask)], dtype=float) return np.mean(trap_image[np.where(cell_mask)], dtype=float)
...@@ -70,6 +79,11 @@ def max2p5pc_med(cell_mask, trap_image): ...@@ -70,6 +79,11 @@ def max2p5pc_med(cell_mask, trap_image):
return max2p5pc / med if med else max2p5pc return max2p5pc / med if med else max2p5pc
def std(cell_mask, trap_image):
return np.std(trap_image[np.where(cell_mask)], dtype=float)
## Specialised extraction functions
def foci_area_otsu(cell_mask, trap_image): def foci_area_otsu(cell_mask, trap_image):
# Use otsu threshold to calculate the are of high-expression blobs inside a cell. # Use otsu threshold to calculate the are of high-expression blobs inside a cell.
cell_pixels = trap_image[cell_mask] cell_pixels = trap_image[cell_mask]
...@@ -79,10 +93,6 @@ def foci_area_otsu(cell_mask, trap_image): ...@@ -79,10 +93,6 @@ def foci_area_otsu(cell_mask, trap_image):
return np.sum(cell_pixels > threshold) return np.sum(cell_pixels > threshold)
def std(cell_mask, trap_image):
return np.std(trap_image[np.where(cell_mask)], dtype=float)
def k2_top_median(cell_mask, trap_image): def k2_top_median(cell_mask, trap_image):
# Use kmeans to cluster the contents of a cell in two, return the high median # Use kmeans to cluster the contents of a cell in two, return the high median
# Useful when a big non-tagged organelle (e.g. vacuole) occupies a big fraction # Useful when a big non-tagged organelle (e.g. vacuole) occupies a big fraction
...@@ -144,8 +154,3 @@ def min_maj_approximation(cell_mask, trap_image=None): ...@@ -144,8 +154,3 @@ def min_maj_approximation(cell_mask, trap_image=None):
min_ax = np.round(nn.max()) min_ax = np.round(nn.max())
maj_ax = np.round(dn.max() + cone_top.sum() / 2) maj_ax = np.round(dn.max() + cone_top.sum() / 2)
return min_ax, maj_ax return min_ax, maj_ax
def eccentricity(cell_mask, trap_image=None):
min_ax, maj_ax = min_maj_approximation(cell_mask)
return np.sqrt(maj_ax ** 2 - min_ax ** 2) / maj_ax
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment