Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
aliby-mirror
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
aliby-mirror
Commits
c14c2ad9
Commit
c14c2ad9
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
change(vis_tools): refactor _overlay_mask_tile
parent
76f293b9
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aliby/utils/vis_tools.py
+60
-36
60 additions, 36 deletions
src/aliby/utils/vis_tools.py
with
60 additions
and
36 deletions
src/aliby/utils/vis_tools.py
+
60
−
36
View file @
c14c2ad9
...
...
@@ -41,7 +41,7 @@ def get_tiles_at_times(
Parameters
----------
image_path : str
hdf5
location
hdf5
index
timepoints : t.List[int]
list of timepoints to fetch
tile_reduction : t.Union[int, t.List[int], str, t.Callable]
...
...
@@ -164,60 +164,84 @@ def crop_mask(img: np.ndarray, mask: np.ndarray):
return
img
def
overlay_masks_tile
s
(
def
_sample_n_tiles_mask
s
(
image_path
:
str
,
results_path
:
str
,
masks
:
np
.
ndarray
,
locations
:
t
.
Tuple
[
t
.
Tuple
[
int
],
t
.
Tuple
[
int
],
t
.
Tuple
[
int
]],
n
:
int
,
seed
:
int
=
0
,
interval
=
None
,
as_generator
=
False
,
)
->
t
.
Tuple
[
t
.
Tuple
,
t
.
Tuple
[
np
.
ndarray
,
np
.
ndarray
]]:
cells
=
Cells
(
results_path
)
indices
,
masks
=
cells
.
_sample_masks
(
n
,
seed
=
seed
,
interval
=
interval
)
processed_tiles
,
cropped_masks
=
_overlay_masks_tiles
(
image_path
,
results_path
,
masks
,
[
indices
[
i
]
for
i
in
(
0
,
2
)],
as_generator
=
as_generator
,
)
return
indices
,
(
processed_tiles
,
cropped_masks
)
def
_overlay_mask_tile
(
image_path
:
str
,
results_path
:
str
,
mask
:
np
.
ndarray
,
index
:
t
.
Tuple
[
int
,
int
,
int
],
bg_channel
:
int
=
0
,
fg_channel
:
int
=
1
,
reduce_z
:
t
.
Union
[
None
,
t
.
Callable
]
=
np
.
max
,
as_generator
:
bool
=
False
,
)
->
t
.
Tuple
[
np
.
ndarray
,
np
.
ndarray
]:
"""
Return a tuplw with two channels
"""
tc
s
=
np
.
stack
(
tc
=
np
.
stack
(
[
[
fetch_tc
(
image_path
,
results_path
,
tp
,
i
)
for
i
in
(
bg_channel
,
fg_channel
)
]
for
tp
in
locations
[
1
]
fetch_tc
(
image_path
,
results_path
,
index
[
1
],
i
)
for
i
in
(
bg_channel
,
fg_channel
)
]
)
# Returns
T
C(tile)ZYX
)
# Returns C(tile)ZYX
tiles
=
np
.
stack
(
[
tcs
[
i
,
:,
tile
].
astype
(
float
)
for
i
,
tile
in
enumerate
(
locations
[
0
])]
)
tiles
=
tc
[:,
index
[
0
]].
astype
(
float
)
reduced_z
=
(
reduce_z
(
tiles
,
axis
=
2
)
if
reduce_z
else
concatenate_dims
(
tiles
,
2
,
-
2
)
reduce_z
(
tiles
,
axis
=
1
)
if
reduce_z
else
concatenate_dims
(
tiles
,
1
,
-
2
)
)
repeated_mask
=
np
.
stack
(
[
tile_like
(
mask
,
reduced_z
[
0
,
0
])
for
mask
in
masks
]
)
repeated_mask
=
tile_like
(
mask
,
reduced_z
[
0
])
cropped_fg
=
np
.
stack
(
[
crop_mask
(
c
,
mask
)
for
mask
,
c
in
zip
(
repeated_mask
,
reduced_z
[:,
1
])]
)
cropped_fg
=
crop_mask
(
reduced_z
[
1
],
repeated_mask
)
return
reduced_z
[
:,
0
],
cropped_fg
return
reduced_z
[
0
],
cropped_fg
def
_
sample_n_tiles_mask
s
(
def
_
overlay_masks_tile
s
(
image_path
:
str
,
results_path
:
str
,
n
:
int
,
seed
:
int
=
0
,
interval
=
None
,
)
->
t
.
Tuple
[
t
.
Tuple
,
t
.
Tuple
[
np
.
ndarray
,
np
.
ndarray
]]:
masks
:
np
.
ndarray
,
indices
:
t
.
Tuple
[
t
.
Tuple
[
int
],
t
.
Tuple
[
int
],
t
.
Tuple
[
int
]],
bg_channel
:
int
=
0
,
fg_channel
:
int
=
1
,
reduce_z
:
t
.
Union
[
None
,
t
.
Callable
]
=
np
.
max
,
as_generator
:
bool
=
False
,
)
->
t
.
Tuple
[
np
.
ndarray
,
np
.
ndarray
]:
cells
=
Cells
(
results_path
)
locations
,
masks
=
cells
.
_sample_masks
(
n
,
seed
=
seed
,
interval
=
interval
)
tmp
=
[
_overlay_mask_tile
(
image_path
,
results_path
,
mask
,
index
,
bg_channel
,
fg_channel
,
reduce_z
,
)
for
mask
,
index
in
zip
(
masks
,
zip
(
*
indices
))
]
processed_tiles
,
cropped_masks
=
overlay_masks_tiles
(
image_path
,
results_path
,
masks
,
[
locations
[
i
]
for
i
in
(
0
,
2
)],
)
return
locations
,
(
processed_tiles
,
cropped_masks
)
return
[
np
.
stack
(
x
)
for
x
in
zip
(
*
tmp
)]
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