angelolab / ark-analysis

Integrated pipeline for multiplexed image analysis
https://ark-analysis.readthedocs.io/en/latest/
MIT License
72 stars 25 forks source link

plot_neighborhood_cluster_result has multiple colors per cell #967

Closed ngreenwald closed 1 year ago

ngreenwald commented 1 year ago

Please refer to our FAQ and look at our known issues before opening a bug report.

Describe the bug This function should assign each cell a unique color. However, upon closer inspection, it's clear that many cells are getting assigned multiple colors, but only at the borders. From a distance it's not clear, but a zoom in highlights the problem.

image image

This is after running the neighborhood analysis notebook, specifically this cell:

# load the masks in and plot them
for fov in subset_neighborhood_fovs:
    neighborhood_mask = load_utils.load_imgs_from_dir(
        data_dir=overlay_out_dir,
        files=[fov + "_neighborhood_mask.tiff"],
        trim_suffix="_neighborhood_mask",
        match_substring="_neighborhood_mask",
        xr_dim_name="neighborhood_mask",
        xr_channel_names=None,
    )

    plot_utils.plot_neighborhood_cluster_result(neighborhood_mask, [fov], k=k, save_dir=overlay_out_dir)
camisowers commented 1 year ago

It was an issue with plt.imshow() using a custom defined ListedColormap for int values instead of a colormap along a range. By default, imshow uses interpolation='antialiased' for boundary points. We can fix this by setting that arg to 'none'.

Screenshot 2023-04-25 at 1 27 04 PM Screenshot 2023-04-25 at 1 27 04 PM

Seems the kmeans notebook is the only instance of it in ark.