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
11e340cc
Commit
11e340cc
authored
3 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
add med-norm maxes as default
parent
77dc3a1e
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
extraction/core/functions/cell.py
+26
-10
26 additions, 10 deletions
extraction/core/functions/cell.py
extraction/core/functions/defaults.py
+9
-1
9 additions, 1 deletion
extraction/core/functions/defaults.py
with
35 additions
and
11 deletions
extraction/core/functions/cell.py
+
26
−
10
View file @
11e340cc
...
@@ -49,6 +49,25 @@ def max5px(cell_mask, trap_image):
...
@@ -49,6 +49,25 @@ def max5px(cell_mask, trap_image):
return
max5px
return
max5px
def
max5px_med
(
cell_mask
,
trap_image
):
sorted_vals
=
np
.
sort
(
trap_image
[
np
.
where
(
cell_mask
)],
axis
=
None
)
top_vals
=
sorted_vals
[
-
5
:]
max5px
=
np
.
mean
(
top_vals
,
dtype
=
float
)
return
max5px
/
sorted_vals
[
len
(
sorted_vals
)
//
2
]
def
max5pc_med
(
cell_mask
,
trap_image
):
npixels
=
cell_mask
.
sum
()
top_pixels
=
int
(
np
.
ceil
(
npixels
*
0.025
))
sorted_vals
=
np
.
sort
(
trap_image
[
np
.
where
(
cell_mask
)],
axis
=
None
)
top_vals
=
sorted_vals
[
-
top_pixels
:]
max2p5pc
=
np
.
mean
(
top_vals
,
dtype
=
float
)
return
max5pc
/
sorted_vals
[
len
(
sorted_vals
)
//
2
]
def
std
(
cell_mask
,
trap_image
):
def
std
(
cell_mask
,
trap_image
):
return
np
.
std
(
trap_image
[
np
.
where
(
cell_mask
)],
dtype
=
float
)
return
np
.
std
(
trap_image
[
np
.
where
(
cell_mask
)],
dtype
=
float
)
...
@@ -84,20 +103,19 @@ def volume(cell_mask, trap_image=None):
...
@@ -84,20 +103,19 @@ def volume(cell_mask, trap_image=None):
Assumes rotational symmetry around the major axis.
Assumes rotational symmetry around the major axis.
"""
"""
min_ax
,
maj_ax
=
min_maj_approximation
(
cell_mask
,
trap_image
)
min_ax
,
maj_ax
=
min_maj_approximation
(
cell_mask
,
trap_image
)
return
(
4
*
math
.
pi
*
min_ax
**
2
*
maj_ax
)
/
3
return
(
4
*
math
.
pi
*
min_ax
**
2
*
maj_ax
)
/
3
def
conical_volume
(
cell_mask
,
trap_image
=
None
):
def
conical_volume
(
cell_mask
,
trap_image
=
None
):
padded
=
np
.
pad
(
cell_mask
,
1
,
mode
=
'
constant
'
,
constant_values
=
0
)
padded
=
np
.
pad
(
cell_mask
,
1
,
mode
=
"
constant
"
,
constant_values
=
0
)
nearest_neighbor
=
ndimage
.
morphology
.
distance_transform_edt
(
nearest_neighbor
=
ndimage
.
morphology
.
distance_transform_edt
(
padded
==
1
)
*
padded
padded
==
1
)
*
padded
return
4
*
(
nearest_neighbor
.
sum
())
return
4
*
(
nearest_neighbor
.
sum
())
def
spherical_volume
(
cell_mask
,
trap_image
=
None
):
def
spherical_volume
(
cell_mask
,
trap_image
=
None
):
area
=
cell_mask
.
sum
()
area
=
cell_mask
.
sum
()
r
=
np
.
sqrt
(
area
/
np
.
pi
)
r
=
np
.
sqrt
(
area
/
np
.
pi
)
return
(
4
*
np
.
pi
*
r
**
3
)
/
3
return
(
4
*
np
.
pi
*
r
**
3
)
/
3
def
min_maj_approximation
(
cell_mask
,
trap_image
=
None
):
def
min_maj_approximation
(
cell_mask
,
trap_image
=
None
):
...
@@ -108,17 +126,15 @@ def min_maj_approximation(cell_mask, trap_image=None):
...
@@ -108,17 +126,15 @@ def min_maj_approximation(cell_mask, trap_image=None):
:param trap_image:
:param trap_image:
:return:
:return:
"""
"""
padded
=
np
.
pad
(
cell_mask
,
1
,
mode
=
'
constant
'
,
constant_values
=
0
)
padded
=
np
.
pad
(
cell_mask
,
1
,
mode
=
"
constant
"
,
constant_values
=
0
)
nn
=
ndimage
.
morphology
.
distance_transform_edt
(
padded
==
1
)
*
padded
nn
=
ndimage
.
morphology
.
distance_transform_edt
(
padded
==
1
)
*
padded
dn
=
ndimage
.
morphology
.
distance_transform_edt
(
nn
-
nn
.
max
())
*
padded
dn
=
ndimage
.
morphology
.
distance_transform_edt
(
nn
-
nn
.
max
())
*
padded
cone_top
=
ndimage
.
morphology
.
distance_transform_edt
(
dn
==
0
)
*
padded
cone_top
=
ndimage
.
morphology
.
distance_transform_edt
(
dn
==
0
)
*
padded
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
):
def
eccentricity
(
cell_mask
,
trap_image
=
None
):
min_ax
,
maj_ax
=
min_maj_approximation
(
cell_mask
)
min_ax
,
maj_ax
=
min_maj_approximation
(
cell_mask
)
return
np
.
sqrt
(
maj_ax
**
2
-
min_ax
**
2
)
/
maj_ax
return
np
.
sqrt
(
maj_ax
**
2
-
min_ax
**
2
)
/
maj_ax
This diff is collapsed.
Click to expand it.
extraction/core/functions/defaults.py
+
9
−
1
View file @
11e340cc
...
@@ -26,7 +26,15 @@ def exparams_from_meta(meta: Union[dict, PosixPath, str], extras=["ph"]):
...
@@ -26,7 +26,15 @@ def exparams_from_meta(meta: Union[dict, PosixPath, str], extras=["ph"]):
}
}
default_reductions
=
{
"
np_max
"
}
default_reductions
=
{
"
np_max
"
}
default_metrics
=
{
"
mean
"
,
"
median
"
,
"
imBackground
"
,
"
max2p5pc
"
}
default_metrics
=
{
"
mean
"
,
"
median
"
,
"
imBackground
"
,
"
max2p5pc
"
,
"
max2p5pc_med
"
,
"
max2p5px
"
,
"
max2p5px_med
"
,
}
default_rm
=
{
r
:
default_metrics
for
r
in
default_reductions
}
default_rm
=
{
r
:
default_metrics
for
r
in
default_reductions
}
av_flch
=
av_channels
.
intersection
(
meta
[
"
channels/channel
"
]).
difference
(
av_flch
=
av_channels
.
intersection
(
meta
[
"
channels/channel
"
]).
difference
(
...
...
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