Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
model_server
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
Christopher Randolph Rhodes
model_server
Commits
95e419f4
Commit
95e419f4
authored
1 year ago
by
Christopher Randolph Rhodes
Browse files
Options
Downloads
Patches
Plain Diff
Removed external build_zmask_meta function
parent
d436bb0d
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
model_server/extensions/chaeo/zmask.py
+0
-148
0 additions, 148 deletions
model_server/extensions/chaeo/zmask.py
with
0 additions
and
148 deletions
model_server/extensions/chaeo/zmask.py
+
0
−
148
View file @
95e419f4
...
...
@@ -32,62 +32,14 @@ class RoiSet(object):
acc_raw
:
GenericImageDataAccessor
,
params
:
RoiSetMetaParams
=
RoiSetMetaParams
(),
):
# # parse filters
# filters = params.filters
# query_str = 'label > 0' # always true
# if filters is not None:
# for k, val in filters.dict(exclude_unset=True).items():
# assert k in ('area', 'solidity')
# vmin = val['min']
# vmax = val['max']
# assert vmin >= 0
# query_str = query_str + f' & {k} > {vmin} & {k} < {vmax}'
#
# # build dataframe of objects, assign z index to each object
# argmax = acc_raw.data.argmax(axis=3, keepdims=True)[:, :, 0, 0].astype('uint16')
# df = (
# pd.DataFrame(
# regionprops_table(
# acc_obj_ids,
# intensity_image=argmax,
# properties=('label', 'area', 'intensity_mean', 'solidity', 'bbox', 'centroid')
# )
# )
# .rename(
# columns={'bbox-0': 'y0', 'bbox-1': 'x0', 'bbox-2': 'y1', 'bbox-3': 'x1',}
# )
# )
# df['zi'] = df['intensity_mean'].round().astype('int')
# df['keeper'] = False
# df.loc[df.query(query_str).index, 'keeper'] = True
# self.df = df
# remaining zmask_meta write ops
self
.
acc_obj_ids
=
acc_obj_ids
self
.
acc_raw
=
acc_raw
self
.
_df
=
self
.
filter_df
(
self
.
make_df
(
self
.
acc_raw
,
self
.
acc_obj_ids
,
expand_box_by
=
params
.
expand_box_by
),
params
.
filters
,
)
# self._df = self.make_slices(
# self._df,
# expand_box_by=params.expand_box_by,
# shape=acc_raw.shape
# )
# remaining zmask_meta write ops
# self.zmask_meta, _, self.interm = build_zmask_from_object_mask(
# acc_obj_ids,
# acc_raw,
# self.get_df(),
# params=params,
# )
# temporarily build zmask meta here
meta
=
[]
for
ob
in
self
.
get_df
().
itertuples
(
name
=
'
LabeledObject
'
):
...
...
@@ -206,19 +158,6 @@ class RoiSet(object):
def
get_object_mask_by_class
(
self
,
class_id
):
return
self
.
object_id_labels
==
class_id
# def loc_mask(self, i):
# # compute contours
# # obmask = (lamap == ob.label) # TODO: on-the-fly
# # contour = find_contours(obmask) # TODO: on-the-fly
# # mask = obmask[ob.y0: ob.y1, ob.x0: ob.x1]
# ob = self.df.loc[i]
# return
#
# def loc_contour(self, i):
# pass
def
get_patch_masks
(
self
,
**
kwargs
)
->
MonoPatchStack
:
return
get_patch_masks
(
self
,
**
kwargs
)
...
...
@@ -339,93 +278,6 @@ class RoiSet(object):
self
.
df
.
to_csv
(
dfpa
,
index
=
False
)
def
build_zmask_from_object_mask
(
obmask
:
GenericImageDataAccessor
,
zstack
:
GenericImageDataAccessor
,
df
,
params
:
RoiSetMetaParams
=
RoiSetMetaParams
(),
):
# """
# Given a 2D mask of objects, build a 3D mask, where each object's z-position is determined by the index of
# maximum intensity in z. Return this zmask and a list of each object's meta information.
# :param obmask: GenericImageDataAccessor 2D map of objects IDs
# :param zstack: GenericImageDataAccessor monochrome zstack of same Y, X dimension as obmask
# :param params: RoiSetMetaParams
# filters: dictionary of form {attribute: (min, max)}; valid attributes are 'area' and 'solidity'
# mask_type: if 'boxes', zmask is True in each object's complete bounding box; otherwise 'contours'
# expand_box_by: (xy, z) expands bounding box by (xy, z) pixels except where this hits a boundary
# :return: tuple (zmask, meta)
# np.ndarray:
# boolean mask of same size as stack
# List containing one Dict per object, with keys:
# info: object's properties from skimage.measure.regionprops_table, including bounding box (y0, y1, x0, x1)
# slice: named slice (np.s_) of (optionally) expanded bounding box
# relative_bounding_box: bounding box (y0, y1, x0, x1) in relative frame of (optionally) expanded bounding box
# contour: object's contour returned by skimage.measure.find_contours
# mask: mask of object in relative frame of (optionally) expanded bounding box
# pd.DataFrame: objects, including bounding, box information after filtering
# Dict of intermediate image products:
# label_map: np.ndarray (h x w) where each unique object has an integer label
# argmax: np.ndarray (h x w x 1 x 1) z-index of highest intensity in zstack
# """
filters
=
params
.
filters
expand_box_by
=
params
.
expand_box_by
# validate inputs
assert
zstack
.
hw
==
obmask
.
shape
lamap
=
obmask
argmax
=
zstack
.
data
.
argmax
(
axis
=
3
,
keepdims
=
True
)[:,
:,
0
,
0
].
astype
(
'
uint16
'
)
# convert bounding boxes to numpy slice objects
ebxy
,
ebz
=
expand_box_by
h
,
w
,
c
,
nz
=
zstack
.
shape
meta
=
[]
for
ob
in
df
.
itertuples
(
name
=
'
LabeledObject
'
):
y0
=
max
(
ob
.
y0
-
ebxy
,
0
)
y1
=
min
(
ob
.
y1
+
ebxy
,
h
)
x0
=
max
(
ob
.
x0
-
ebxy
,
0
)
x1
=
min
(
ob
.
x1
+
ebxy
,
w
)
z0
=
max
(
ob
.
zi
-
ebz
,
0
)
z1
=
min
(
ob
.
zi
+
ebz
,
nz
)
# relative bounding box positions
rbb
=
{
# TODO: just put in the DF
'
y0
'
:
ob
.
y0
-
y0
,
'
y1
'
:
ob
.
y1
-
y0
,
'
x0
'
:
ob
.
x0
-
x0
,
'
x1
'
:
ob
.
x1
-
x0
,
}
sl
=
np
.
s_
[
y0
:
y1
,
x0
:
x1
,
:,
z0
:
z1
+
1
]
# TODO: on-the-fly in RoiSet, given DF
# compute contours
obmask
=
(
lamap
==
ob
.
label
)
# TODO: on-the-fly
contour
=
find_contours
(
obmask
)
# TODO: on-the-fly
mask
=
obmask
[
ob
.
y0
:
ob
.
y1
,
ob
.
x0
:
ob
.
x1
]
assert
rbb
[
'
x1
'
]
<=
(
x1
-
x0
)
assert
rbb
[
'
y1
'
]
<=
(
y1
-
y0
)
meta
.
append
({
'
df_index
'
:
ob
.
Index
,
'
info
'
:
ob
,
# 'slice': sl,
'
relative_bounding_box
'
:
rbb
,
# TODO: put in DF
'
contour
'
:
contour
,
# TODO: delegate to getter
'
mask
'
:
mask
# TODO: delegate to getter
})
# return intermediate image arrays
interm
=
{
'
label_map
'
:
lamap
,
'
argmax
'
:
argmax
,
}
return
meta
,
df
,
interm
def
project_stack_from_focal_points
(
xx
:
np
.
ndarray
,
yy
:
np
.
ndarray
,
...
...
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