Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alibylite
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Swain Lab
aliby
alibylite
Commits
8b0f55b5
Commit
8b0f55b5
authored
3 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
reorganise and add otsu import
parent
a8187318
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
extraction/core/functions/cell.py
+14
-9
14 additions, 9 deletions
extraction/core/functions/cell.py
with
14 additions
and
9 deletions
extraction/core/functions/cell.py
+
14
−
9
View file @
8b0f55b5
...
@@ -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
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment