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
1eaca3da
Commit
1eaca3da
authored
2 years ago
by
Alán Muñoz
Browse files
Options
Downloads
Patches
Plain Diff
feat(vis_tools): add overlay_masks_tiles
parent
269ee5ab
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/aliby/utils/vis_tools.py
+55
-0
55 additions, 0 deletions
src/aliby/utils/vis_tools.py
with
55 additions
and
0 deletions
src/aliby/utils/vis_tools.py
+
55
−
0
View file @
1eaca3da
#!/usr/bin/env jupyter
#!/usr/bin/env jupyter
"""
"""
Visualisation tools useful to generate figures cell pictures and figures from scripts.
Visualisation tools useful to generate figures cell pictures and figures from scripts.
These do not depend on matplotlib to work, they focus on array processing.
To check plot-related functions look at plots.py in this folder.
"""
"""
import
typing
as
t
import
typing
as
t
from
copy
import
copy
from
copy
import
copy
...
@@ -152,3 +155,55 @@ def crop_mask(img: np.ndarray, mask: np.ndarray):
...
@@ -152,3 +155,55 @@ def crop_mask(img: np.ndarray, mask: np.ndarray):
img
=
copy
(
img
).
astype
(
float
)
img
=
copy
(
img
).
astype
(
float
)
img
[
~
mask
]
=
np
.
nan
img
[
~
mask
]
=
np
.
nan
return
img
return
img
def
overlay_masks_tiles
(
image_path
:
str
,
results_path
:
str
,
masks
:
np
.
ndarray
,
locations
:
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
,
)
->
t
.
Tuple
[
np
.
ndarray
,
np
.
ndarray
]:
tcs
=
np
.
stack
(
[
[
fetch_tc
(
image_path
,
results_path
,
tp
,
i
)
for
i
in
(
bg_channel
,
fg_channel
)
]
for
tp
in
locations
[
1
]
]
)
# Returns TC(tile)ZYX
tiles
=
np
.
stack
(
[
tcs
[
i
,
:,
tile
].
astype
(
float
)
for
i
,
tile
in
enumerate
(
locations
[
0
])]
)
reduced_z
=
(
reduce_z
(
tiles
,
axis
=
2
)
if
reduce_z
else
concatenate_dims
(
tiles
,
2
,
-
2
)
)
repeated_mask
=
np
.
stack
(
[
tile_like
(
mask
,
reduced_z
[
0
,
0
])
for
mask
in
masks
]
)
cropped_fg
=
np
.
stack
(
[
crop_mask
(
c
,
mask
)
for
mask
,
c
in
zip
(
repeated_mask
,
reduced_z
[:,
1
])]
)
return
reduced_z
[:,
0
],
cropped_fg
def
_sample_n_tiles_masks
(
image_path
:
str
,
results_path
:
str
,
n
:
int
,
seed
:
int
=
0
)
->
t
.
Tuple
[
t
.
Tuple
,
t
.
Tuple
[
np
.
ndarray
,
np
.
ndarray
]]:
cells
=
Cells
(
results_path
)
locations
,
masks
=
cells
.
_sample_masks
(
n
,
seed
=
seed
)
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
)
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