Skip to content

Commit

Permalink
ENH: update ISS to use Segmentation pipeline component, revert to usi…
Browse files Browse the repository at this point in the history
…ng cloudfront
  • Loading branch information
ambrosejcarr committed Aug 15, 2018
1 parent af9db68 commit 13d4636
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 33 deletions.
16 changes: 8 additions & 8 deletions notebooks/ISS_Pipeline_-_Breast_-_1_FOV.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@
"metadata": {},
"outputs": [],
"source": [
"from starfish.image._registration import Registration\n",
"from starfish.image import Registration\n",
"\n",
"registration = Registration.FourierShiftRegistration(\n",
" upsampling=1000, \n",
Expand Down Expand Up @@ -386,22 +386,22 @@
"outputs": [],
"source": [
"from starfish.constants import Indices\n",
"from starfish.image._segmentation.watershed import _WatershedSegmenter\n",
"from starfish.image import Segmentation\n",
"\n",
"dapi_thresh = .16 # binary mask for cell (nuclear) locations\n",
"stain_thresh = .22 # binary mask for overall cells // binarization of stain\n",
"size_lim = (10, 10000)\n",
"disk_size_markers = None\n",
"disk_size_mask = None\n",
"min_dist = 57\n",
"\n",
"stain = np.mean(primary_image.max_proj(Indices.CH, Indices.Z), axis=0)\n",
"stain = stain/stain.max()\n",
"nuclei_projection = nuclei.max_proj(Indices.ROUND, Indices.CH, Indices.Z)\n",
"\n",
"\n",
"seg = _WatershedSegmenter(nuclei_projection, stain) # uses skimage watershed.\n",
"cells_labels = seg.segment(dapi_thresh, stain_thresh, size_lim, disk_size_markers, disk_size_mask, min_dist)\n",
"seg = Segmentation.Watershed(\n",
" dapi_threshold=dapi_thresh,\n",
" input_threshold=stain_thresh,\n",
" min_distance=min_dist\n",
")\n",
"seg.run(primary_image, nuclei)\n",
"seg.show()"
]
},
Expand Down
11 changes: 1 addition & 10 deletions notebooks/MERFISH_Pipeline_-_U2O2_Cell_Culture_-_1_FOV.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,6 @@
"%autoreload 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import slicedimage"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -55,7 +46,7 @@
"source": [
"# load the data from cloudfront\n",
"experiment = Experiment()\n",
"experiment.read('http://czi.starfish.data.public.s3.amazonaws.com/20180802/MERFISH/fov_001/experiment_new.json')"
"experiment.read('https://dmf0bdeheu4zf.cloudfront.net/20180802/MERFISH/fov_001/experiment.json')"
]
},
{
Expand Down
16 changes: 8 additions & 8 deletions notebooks/py/ISS_Pipeline_-_Breast_-_1_FOV.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@
# EPY: END markdown

# EPY: START code
from starfish.image._registration import Registration
from starfish.image import Registration

registration = Registration.FourierShiftRegistration(
upsampling=1000,
Expand Down Expand Up @@ -235,22 +235,22 @@

# EPY: START code
from starfish.constants import Indices
from starfish.image._segmentation.watershed import _WatershedSegmenter
from starfish.image import Segmentation

dapi_thresh = .16 # binary mask for cell (nuclear) locations
stain_thresh = .22 # binary mask for overall cells // binarization of stain
size_lim = (10, 10000)
disk_size_markers = None
disk_size_mask = None
min_dist = 57

stain = np.mean(primary_image.max_proj(Indices.CH, Indices.Z), axis=0)
stain = stain/stain.max()
nuclei_projection = nuclei.max_proj(Indices.ROUND, Indices.CH, Indices.Z)


seg = _WatershedSegmenter(nuclei_projection, stain) # uses skimage watershed.
cells_labels = seg.segment(dapi_thresh, stain_thresh, size_lim, disk_size_markers, disk_size_mask, min_dist)
seg = Segmentation.Watershed(
dapi_threshold=dapi_thresh,
input_threshold=stain_thresh,
min_distance=min_dist
)
seg.run(primary_image, nuclei)
seg.show()
# EPY: END code

Expand Down
6 changes: 1 addition & 5 deletions notebooks/py/MERFISH_Pipeline_-_U2O2_Cell_Culture_-_1_FOV.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
# EPY: ESCAPE %autoreload 2
# EPY: END code

# EPY: START code
import slicedimage
# EPY: END code

# EPY: START code
# EPY: ESCAPE %matplotlib notebook

Expand All @@ -35,7 +31,7 @@
# EPY: START code
# load the data from cloudfront
experiment = Experiment()
experiment.read('http://czi.starfish.data.public.s3.amazonaws.com/20180802/MERFISH/fov_001/experiment_new.json')
experiment.read('https://dmf0bdeheu4zf.cloudfront.net/20180802/MERFISH/fov_001/experiment.json')
# EPY: END code

# EPY: START markdown
Expand Down
13 changes: 11 additions & 2 deletions starfish/image/_segmentation/watershed.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Tuple, Optional

import numpy as np
import scipy.ndimage.measurements as spm
import regional
Expand All @@ -22,6 +24,7 @@ def __init__(self, dapi_threshold, input_threshold, min_distance, **kwargs) -> N
self.dapi_threshold = dapi_threshold
self.input_threshold = input_threshold
self.min_distance = min_distance
self._segmentation_instance: Optional[_WatershedSegmenter] = None

@classmethod
def add_arguments(cls, group_parser) -> None:
Expand All @@ -44,8 +47,8 @@ def run(self, hybridization_stack: ImageStack, nuclei_stack: ImageStack) -> regi
disk_size_mask = None

nuclei = nuclei_stack.max_proj(Indices.ROUND, Indices.CH, Indices.Z)
seg = _WatershedSegmenter(nuclei, stain)
cells_labels = seg.segment(
self._segmentation_instance = _WatershedSegmenter(nuclei, stain)
cells_labels = self._segmentation_instance.segment(
self.dapi_threshold, self.input_threshold, size_lim, disk_size_markers, disk_size_mask,
self.min_distance
)
Expand All @@ -54,6 +57,12 @@ def run(self, hybridization_stack: ImageStack, nuclei_stack: ImageStack) -> regi

return regions

def show(self, figsize: Tuple[int, int]=(10, 10)) -> None:
if isinstance(self._segmentation_instance, _WatershedSegmenter):
self._segmentation_instance.show(figsize=figsize)
else:
raise RuntimeError('Run segmentation before attempting to show results.')


# TODO dganguli: fill in these types & document
class _WatershedSegmenter:
Expand Down

0 comments on commit 13d4636

Please sign in to comment.