Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean SegmentMIF #294

Merged
merged 3 commits into from
Feb 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 23 additions & 8 deletions pathml/preprocessing/transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,9 @@ class SegmentMIF(Transform):
nuclear_channel(int): channel that defines cell nucleus
cytoplasm_channel(int): channel that defines cell membrane or cytoplasm
image_resolution(float): pixel resolution of image in microns
gpu(bool): flag indicating whether gpu will be used for inference
preprocess_kwargs(dict): keyword arguemnts to pass to pre-processing function
postprocess_kwargs_nuclear(dict): keyword arguments to pass to post-processing function
postprocess_kwargs_whole_cell(dict): keyword arguments to pass to post-processing function

References:
Greenwald, N.F., Miller, G., Moen, E. et al. Whole-cell segmentation of tissue images with human-level
Expand All @@ -1307,9 +1309,9 @@ def __init__(
nuclear_channel=None,
cytoplasm_channel=None,
image_resolution=0.5,
gpu=True,
preprocess_kwargs=None,
postprocess_kwargs_nuclear=None,
postprocess_kwargs_whole_cell=None,
postprocess_kwrags_nuclear=None,
):
assert isinstance(
nuclear_channel, int
Expand All @@ -1320,7 +1322,13 @@ def __init__(
self.nuclear_channel = nuclear_channel
self.cytoplasm_channel = cytoplasm_channel
self.image_resolution = image_resolution
self.gpu = gpu
self.preprocess_kwargs = preprocess_kwargs if preprocess_kwargs else {}
self.postprocess_kwargs_nuclear = (
postprocess_kwargs_nuclear if postprocess_kwargs_nuclear else {}
)
self.postprocess_kwargs_whole_cell = (
postprocess_kwargs_whole_cell if postprocess_kwargs_whole_cell else {}
)

if model.lower() == "mesmer":
try:
Expand All @@ -1346,8 +1354,7 @@ def __init__(

def __repr__(self):
return (
f"SegmentMIF(model={self.model}, image_resolution={self.image_resolution}, "
f"gpu={self.gpu})"
f"SegmentMIF(model={self.model}, image_resolution={self.image_resolution})"
)

def F(self, image):
Expand All @@ -1371,10 +1378,18 @@ def F(self, image):

model = Mesmer()
cell_segmentation_predictions = model.predict(
nuc_cytoplasm, image_mpp=self.image_resolution, compartment="whole-cell"
nuc_cytoplasm,
image_mpp=self.image_resolution,
compartment="whole-cell",
preprocess_kwargs=self.preprocess_kwargs,
postprocess_kwargs_whole_cell=self.postprocess_kwargs_whole_cell,
)
nuclear_segmentation_predictions = model.predict(
nuc_cytoplasm, image_mpp=self.image_resolution, compartment="nuclear"
nuc_cytoplasm,
image_mpp=self.image_resolution,
compartment="nuclear",
preprocess_kwargs=self.preprocess_kwargs,
postprocess_kwargs_nuclear=self.postprocess_kwargs_nuclear,
)
cell_segmentation_predictions = np.squeeze(
cell_segmentation_predictions, axis=0
Expand Down