Issue using Segment.Watershed

I am running into an issue when trying to use Segment.Watershed to segment cells in an image set. I am getting the following error: “ValueError: not all masks have the same physical ticks”

When I run the example from the starfish documentation example it seems to work, but I cannot seem to get my images to work. I am wanting to use DAPI images to provide the seed to the watershed algorithm, and then mRNA stained (polyA) images to define the edges of the cells.

Example code:

from starfish import Experiment
from starfish.image import Filter
from starfish import FieldOfView
from starfish.types import Axes
import os

primary_out = “F:/Data/20200724/sorted_data/primary_3k_10k”
exp = Experiment.from_json(os.path.join(primary_out, “experiment.json”))
print(exp)

dapi_img = exp[“fov_000”].get_image(“dapi”)
polyA_img = exp[“fov_000”].get_image(“polyA”)

print(dapi_img)
print(polyA_img)

masking_radius = 10
filt = Filter.WhiteTophat(masking_radius, is_volume=False)
filt.run(dapi_img, in_place=True)
filt.run(polyA_img, in_place=True)

from starfish import display
from starfish.image import Segment
display(ref)

dapi_thresh = .18 # global threshold value for nuclei images
stain_thresh = .22 # global threshold value for primary images
min_dist = 57 # minimum distance (pixels) between nuclei distance transformed peaks

seg = Segment.Watershed(
nuclei_threshold=dapi_thresh,
input_threshold=stain_thresh,
min_distance=min_dist)

masks = seg.run(polyA_img, dapi_img)

seg.show()

Image description
DAPI - Labeled nuclei
PolyA - Labeled mRNA in the cell

Experiment format:
<starfish.Experiment (FOVs=2)>
{
fov_000: <starfish.FieldOfView>
Primary Image: <slicedimage.TileSet (z: 1, r: 8, c: 2, x: 2048, y: 2048)>
Auxiliary Images:
fiducial: <slicedimage.TileSet (z: 1, r: 8, c: 1, x: 2048, y: 2048)>
dapi: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
dapi_fiducial: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
polyA: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
polyA_fiducial: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
fov_001: <starfish.FieldOfView>
Primary Image: <slicedimage.TileSet (z: 1, r: 8, c: 2, x: 2048, y: 2048)>
Auxiliary Images:
fiducial: <slicedimage.TileSet (z: 1, r: 8, c: 1, x: 2048, y: 2048)>
dapi: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
dapi_fiducial: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
polyA: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
polyA_fiducial: <slicedimage.TileSet (z: 1, r: 1, c: 1, x: 2048, y: 2048)>
}

Error traceback:
masks = seg.run(ref, dapi_img)

File “C:\Users\ALEX\anaconda3\envs\starfish3\lib\site-packages\starfish\core\pipeline\algorithmbase.py”, line 23, in helper
result = func(*args, **kwargs)

File “C:\Users\ALEX\anaconda3\envs\starfish3\lib\site-packages\starfish\core\image\Segment\watershed.py”, line 86, in run
disk_size_mask, self.min_distance

File “C:\Users\ALEX\anaconda3\envs\starfish3\lib\site-packages\starfish\core\image\Segment\watershed.py”, line 170, in segment
self.mask = self.watershed_mask(stain_thresh, self.markers, disk_size_mask)

File “C:\Users\ALEX\anaconda3\envs\starfish3\lib\site-packages\starfish\core\image\Segment\watershed.py”, line 227, in watershed_mask
markers_and_stain = Merge.SimpleMerge().run([thresholded_stain, markers])

File “C:\Users\ALEX\anaconda3\envs\starfish3\lib\site-packages\starfish\core\pipeline\algorithmbase.py”, line 23, in helper
result = func(*args, **kwargs)

File “C:\Users\ALEX\anaconda3\envs\starfish3\lib\site-packages\starfish\core\morphology\Merge\simple.py”, line 43, in run
raise ValueError(“not all masks have the same physical ticks”)

ValueError: not all masks have the same physical ticks

I assume ref and polyA_img are the same.

I’m not sure what the issue is, but my first guess would be to check your json files. Make sure the tile coordinate values (e.g. xc, yc, and zc) are all the same for each FOV. For example the coordinates in primary-fov_000.json and dapi-fov_000.json should both contain something like (replace with your own appropriate values or dummy values):

    "tiles": [
        {
            "coordinates": {
                "xc": [
                    0.0,
                    0.2048
                ],
                "yc": [
                    0.0,
                    0.0983
                ],
                "zc": [
                    0.0,
                    0.0001
                ]
            },
...

Thank you for your quick reply Matt,

I have looked at my json files for both images, and their coordinates match. However my json files did not have the z coordinate defined. I manually added matching z coordinates into the json files and it now seems to be working correctly.

Thank you for your help!