def METHOD_NAME(
    c: np.ndarray,
    p: np.ndarray,
    pvalue_cutoff: float = None,
    method: str = "edge-watershed",  # edge-detection and watershed  'edge-watershed' or 'otsu'
    c_cutoff: float = None,
    tissue_mask: Optional[np.ndarray] = None,
) -> np.ndarray:
    """Generate cell mask based on Moran's I."""
    if pvalue_cutoff == None:
        if method == "otsu":
            p = (p * 255).astype(np.uint8)
            if isinstance(tissue_mask, np.ndarray):
                p2 = p[tissue_mask > 0]
            else:
                p2 = p.flatten()
            pvalue_cutoff = threshold_otsu(hist=(np.bincount(p2), np.arange(len(np.bincount(p2)))))
            # print(f'pvalue_cutoff: {pvalue_cutoff}')
            p_cell_mask = np.where(p <= pvalue_cutoff, 255, 0).astype(np.uint8)
        if method == "edge-watershed":
            edges = sobel(p)
            markers = np.zeros_like(p, np.int8)
            foreground, background = 1, 2
            markers[p > 0.95] = background
            markers[p < 1e-5] = foreground
            ws = watershed(edges, markers)  # np.int32
            p_cell_mask = np.where(ws == 1, 255, 0).astype(np.uint8)
            # cv2.imwrite("p_cell_mask.tif", p_cell_mask)
    else:  # pvalue_cutoff = 0.05
        p_cell_mask = np.where(p <= pvalue_cutoff, 255, 0).astype(np.uint8)
    if c_cutoff == None:
        c = ((c - np.min(c)) / (np.max(c) - np.min(c)) * 255).astype(np.uint8)
        if isinstance(tissue_mask, np.ndarray):
            c2 = c[(p_cell_mask == 255) & (tissue_mask > 0)]
        else:
            c2 = c[p_cell_mask == 255]
        counts = np.bincount(c2)
        if counts[0] == 0:
            counts[0] = 1
        if counts[-1] == 0:
            counts[-1] = 1
        c_cutoff = threshold_otsu(hist=(counts, np.arange(256)))
        # for i in counts:
        #    print(i)
        # print(f'c_cutoff after adjust to 0-255: {c_cutoff}')
        # cv2.imwrite("c_255.tif", c)
    # out
    if isinstance(tissue_mask, np.ndarray):
        cell_mask = np.where((p_cell_mask == 255) & (c >= c_cutoff) & (tissue_mask > 0), 255, 0).astype(np.uint8)
    else:
        cell_mask = np.where((p_cell_mask == 255) & (c >= c_cutoff), 255, 0).astype(np.uint8)
    return cell_mask.astype(np.bool)