Skip to content
Snippets Groups Projects
Commit a3043334 authored by Christopher Randolph Rhodes's avatar Christopher Randolph Rhodes
Browse files

Renamed ZMask to RoiSet, prototyped object classification methods that add...

Renamed ZMask to RoiSet, prototyped object classification methods that add classification result as a dataframe column
parent 0f27c220
No related branches found
No related tags found
No related merge requests found
...@@ -2,19 +2,22 @@ from typing import Dict, List, Union ...@@ -2,19 +2,22 @@ from typing import Dict, List, Union
from pydantic import BaseModel from pydantic import BaseModel
class PatchParams(BaseModel): class PatchParams(BaseModel):
draw_bounding_box: bool = False draw_bounding_box: bool = False
draw_contour: bool = False draw_contour: bool = False
draw_mask: bool = False draw_mask: bool = False
rescale_clip: float = 0.001 rescale_clip: float = 0.001
focus_metric: str = 'max_sobel' focus_metric: str = 'max_sobel'
rgb_overlay_channels: List[Union[int, None]] = (None, None, None), rgb_overlay_channels: List[Union[int, None]] = [None, None, None]
rgb_overlay_weights: List[float] = (1.0, 1.0, 1.0) rgb_overlay_weights: List[float] = [1.0, 1.0, 1.0]
class AnnotatedZStackParams(BaseModel): class AnnotatedZStackParams(BaseModel):
draw_label: bool = False draw_label: bool = False
class ZMaskExportParams(BaseModel):
class RoiSetExportParams(BaseModel):
pixel_probabilities: bool = False pixel_probabilities: bool = False
patches_3d: Union[PatchParams, None] = None patches_3d: Union[PatchParams, None] = None
patches_2d_for_annotation: Union[PatchParams, None] = None patches_2d_for_annotation: Union[PatchParams, None] = None
...@@ -22,3 +25,19 @@ class ZMaskExportParams(BaseModel): ...@@ -22,3 +25,19 @@ class ZMaskExportParams(BaseModel):
patch_masks: bool = False patch_masks: bool = False
annotated_z_stack: Union[AnnotatedZStackParams, None] = None annotated_z_stack: Union[AnnotatedZStackParams, None] = None
class RoiClassifierValue(BaseModel):
name: str
value: int
class RoiFilterRange(BaseModel):
min: float
max: float
class RoiFilter(BaseModel):
area: Union[RoiFilterRange, None] = None
solidity: Union[RoiFilterRange, None] = None
classifiers: List[RoiClassifierValue] = []
...@@ -15,7 +15,7 @@ from extensions.chaeo.models import PatchStackObjectClassifier ...@@ -15,7 +15,7 @@ from extensions.chaeo.models import PatchStackObjectClassifier
from extensions.chaeo.params import ZMaskExportParams from extensions.chaeo.params import ZMaskExportParams
from extensions.chaeo.process import mask_largest_object from extensions.chaeo.process import mask_largest_object
from extensions.chaeo.products import export_patches_from_zstack, export_patch_masks_from_zstack, export_multichannel_patches_from_zstack, get_patches_from_zmask_meta, get_patch_masks_from_zmask_meta from extensions.chaeo.products import export_patches_from_zstack, export_patch_masks_from_zstack, export_multichannel_patches_from_zstack, get_patches_from_zmask_meta, get_patch_masks_from_zmask_meta
from extensions.chaeo.zmask import project_stack_from_focal_points, ZMaskObjectTable from extensions.chaeo.zmask import project_stack_from_focal_points, RoiSet
from extensions.ilastik.models import IlastikPixelClassifierModel from extensions.ilastik.models import IlastikPixelClassifierModel
from model_server.accessors import generate_file_accessor, InMemoryDataAccessor, write_accessor_data_to_file from model_server.accessors import generate_file_accessor, InMemoryDataAccessor, write_accessor_data_to_file
...@@ -281,7 +281,7 @@ def infer_object_map_from_zstack( ...@@ -281,7 +281,7 @@ def infer_object_map_from_zstack(
ti.click('threshold_pixel_mask') ti.click('threshold_pixel_mask')
# make zmask # make zmask
obj_table = ZMaskObjectTable( obj_table = RoiSet(
obmask.get_one_channel_data(pxmap_foreground_channel), obmask.get_one_channel_data(pxmap_foreground_channel),
stack.get_one_channel_data(segmentation_channel), stack.get_one_channel_data(segmentation_channel),
mask_type=zmask_type, mask_type=zmask_type,
......
...@@ -9,12 +9,12 @@ from sklearn.linear_model import LinearRegression ...@@ -9,12 +9,12 @@ from sklearn.linear_model import LinearRegression
from extensions.chaeo.annotators import draw_boxes_on_3d_image from extensions.chaeo.annotators import draw_boxes_on_3d_image
from extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack, export_patch_masks_from_zstack from extensions.chaeo.products import export_patches_from_zstack, export_multichannel_patches_from_zstack, export_patch_masks_from_zstack
from extensions.chaeo.params import ZMaskExportParams from extensions.chaeo.params import RoiFilter, RoiSetExportParams
from model_server.accessors import GenericImageDataAccessor, InMemoryDataAccessor, write_accessor_data_to_file from model_server.accessors import GenericImageDataAccessor, InMemoryDataAccessor, write_accessor_data_to_file
class ZMaskObjectTable(object): class RoiSet(object):
def __init__( def __init__(
self, self,
...@@ -41,7 +41,7 @@ class ZMaskObjectTable(object): ...@@ -41,7 +41,7 @@ class ZMaskObjectTable(object):
def get_argmax(self): def get_argmax(self):
return self.interm.argmax return self.interm.argmax
def export_3d_patches(self, where, prefix, channel, params: ZMaskExportParams): def export_3d_patches(self, where, prefix, channel, params: RoiSetExportParams):
if not self.count: if not self.count:
return return
files = export_patches_from_zstack( files = export_patches_from_zstack(
...@@ -54,7 +54,7 @@ class ZMaskObjectTable(object): ...@@ -54,7 +54,7 @@ class ZMaskObjectTable(object):
make_3d=True, make_3d=True,
) )
def export_2d_patches_for_annotation(self, where, prefix, channel, params: ZMaskExportParams): def export_2d_patches_for_annotation(self, where, prefix, channel, params: RoiSetExportParams):
if not self.count: if not self.count:
return return
files = export_multichannel_patches_from_zstack( files = export_multichannel_patches_from_zstack(
...@@ -78,7 +78,7 @@ class ZMaskObjectTable(object): ...@@ -78,7 +78,7 @@ class ZMaskObjectTable(object):
self.df = pd.merge(self.df, df_patches, left_index=True, right_on='df_index').drop(columns='df_index') self.df = pd.merge(self.df, df_patches, left_index=True, right_on='df_index').drop(columns='df_index')
self.df['patch_id'] = self.df.apply(lambda _: uuid4(), axis=1) self.df['patch_id'] = self.df.apply(lambda _: uuid4(), axis=1)
def export_2d_patches_for_training(self, where, prefix, channel, params: ZMaskExportParams): def export_2d_patches_for_training(self, where, prefix, channel, params: RoiSetExportParams):
if not self.count: if not self.count:
return return
files = export_multichannel_patches_from_zstack( files = export_multichannel_patches_from_zstack(
...@@ -102,7 +102,7 @@ class ZMaskObjectTable(object): ...@@ -102,7 +102,7 @@ class ZMaskObjectTable(object):
self.df = pd.merge(self.df, df_patches, left_index=True, right_on='df_index').drop(columns='df_index') self.df = pd.merge(self.df, df_patches, left_index=True, right_on='df_index').drop(columns='df_index')
self.df['patch_id'] = self.df.apply(lambda _: uuid4(), axis=1) self.df['patch_id'] = self.df.apply(lambda _: uuid4(), axis=1)
def export_2d_patches_for_annotation(self, where, prefix, channel, params: ZMaskExportParams): def export_2d_patches_for_annotation(self, where, prefix, channel, params: RoiSetExportParams):
if not self.count: if not self.count:
return return
files = export_multichannel_patches_from_zstack( files = export_multichannel_patches_from_zstack(
...@@ -115,7 +115,7 @@ class ZMaskObjectTable(object): ...@@ -115,7 +115,7 @@ class ZMaskObjectTable(object):
focus_metric=params.focus_metric, focus_metric=params.focus_metric,
) )
def export_patch_masks(self, where, prefix, channel, params: ZMaskExportParams): def export_patch_masks(self, where, prefix, channel, params: RoiSetExportParams):
if not self.count: if not self.count:
return return
files = export_patch_masks_from_zstack( files = export_patch_masks_from_zstack(
...@@ -125,7 +125,7 @@ class ZMaskObjectTable(object): ...@@ -125,7 +125,7 @@ class ZMaskObjectTable(object):
prefix=prefix, prefix=prefix,
) )
def export_annotated_zstack(self, where, prefix, channel, params: ZMaskExportParams): def export_annotated_zstack(self, where, prefix, channel, params: RoiSetExportParams):
annotated = InMemoryDataAccessor( annotated = InMemoryDataAccessor(
draw_boxes_on_3d_image( draw_boxes_on_3d_image(
self.acc_raw.get_one_channel_data(channel).data, self.acc_raw.get_one_channel_data(channel).data,
...@@ -152,6 +152,19 @@ class ZMaskObjectTable(object): ...@@ -152,6 +152,19 @@ class ZMaskObjectTable(object):
projected = self.acc_raw.data.max(axis=-1) projected = self.acc_raw.data.max(axis=-1)
return projected return projected
def classify_by(self, column_name, object_classification_model, patch_basis=True):
# add one column to df where each value is an integer
pass
def get_raw_patches(self, filters: RoiFilter):
pass
def get_patch_masks(self, filters: RoiFilter):
pass
def get_object_map(self, filters: RoiFilter):
pass
def build_zmask_from_object_mask( def build_zmask_from_object_mask(
obmask: GenericImageDataAccessor, obmask: GenericImageDataAccessor,
zstack: GenericImageDataAccessor, zstack: GenericImageDataAccessor,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment