示例#1
0
def display_mask(fig,
                 mask,
                 display_type,
                 type=1,
                 color="C1",
                 d=np.sqrt(2),
                 ax=None,
                 dm=True,
                 lw=9,
                 dashes=(3, 1)):
    if not dm:
        return
    mask = mask.astype(int)
    if display_type == "outline":
        out_line = mask - binary_erosion((mask))
        out_line = custom_edge_filter(out_line)  # risky
        out_line_graph, points = mask_to_graph(out_line, d=d)
        circular_path = find_path_circular(out_line_graph, 0)
        circular_path.append(circular_path[0])  # to plot a fully closed loop
        if type == 1:
            ax = fig.axes[0] if ax is None else ax
            ax.plot(points[circular_path][:, 1],
                    points[circular_path][:, 0],
                    "--",
                    color=color,
                    linewidth=lw,
                    dashes=dashes)
        if type == 2:
            for ax in fig.axes:
                ax.plot(points[circular_path][:, 1],
                        points[circular_path][:, 0],
                        "--",
                        color=color,
                        linewidth=lw,
                        dashes=dashes)

    if display_type == "overlay":

        mask_show = make_display_mask(mask)
        if type == 1:
            ax = fig.axes[0] if ax is None else ax
            ax.imshow(mask_show, alpha=0.4)
        if type == 2:
            for ax in fig.axes:
                ax.imshow(mask_show, alpha=0.4)

    if display_type == "windowed":

        mask_show = make_display_mask(mask)
        mask_window = copy.deepcopy(mask_show)
        mask_window[np.isnan(mask_show)] = 1
        mask_window[mask_show] = np.nan
        if type == 1:
            ax = fig.axes[0] if ax is None else ax
            ax.imshow(mask_window, alpha=0.4)
        if type == 2:
            for ax in fig.axes:
                ax.imshow(mask_window, alpha=0.4)
示例#2
0
def add_mask(fig, mask):
    mask_show = make_display_mask(mask)
    ax = fig.axes[0]
    ax.imshow(mask, alpha=0.4)