示例#1
0
文件: viz.py 项目: DerThorsten/ray
def plot_vi_breakdown(seg, gt, ignore_seg=[], ignore_gt=[], 
                                        hlines=None, subplot=False, **kwargs):
    """Plot conditional entropy H(Y|X) vs P(X) for both seg|gt and gt|seg."""
    plt.ion()
    pxy,px,py,hxgy,hygx,lpygx,lpxgy = evaluate.vi_tables(seg,gt,
            ignore_seg=ignore_seg, ignore_gt=ignore_gt)
    cu = -px*lpygx
    co = -py*lpxgy
    if hlines is None:
        hlines = []
    elif hlines == True:
        hlines = 10
    if type(hlines) == int:
        minc = min(cu[cu!=0].min(), co[co!=0].min())
        maxc = max(cu[cu!=0].max(), co[co!=0].max())
        hlines = np.arange(maxc/hlines, maxc, maxc/hlines)
    plt.figure()
    if subplot: plt.subplot(1,2,1)
    plot_vi_breakdown_panel(px, -lpygx, 
        'False merges', 'p(S=seg)', 'H(G|S=seg)', 
        hlines, c='blue', **kwargs)
    if subplot: plt.subplot(1,2,2)
    plot_vi_breakdown_panel(py, -lpxgy, 
        'False splits', 'p(G=gt)', 'H(S|G=gt)', 
        hlines, c='orange', **kwargs)
    if not subplot:
        plt.title('vi contributions by body.')
        plt.legend(loc='upper right', scatterpoints=1)
        plt.xlabel('Segment size (fraction of volume)', fontsize='large')
        plt.ylabel('Conditional entropy (bits)', fontsize='large')
        xmax = max(px.max(), py.max())
        plt.xlim(-0.05*xmax, 1.05*xmax)
        ymax = max(-lpygx.min(), -lpxgy.min())
        plt.ylim(-0.05*ymax, 1.05*ymax)
示例#2
0
def plot_vi_breakdown(seg,
                      gt,
                      ignore_seg=[],
                      ignore_gt=[],
                      hlines=None,
                      subplot=False,
                      **kwargs):
    """Plot conditional entropy H(Y|X) vs P(X) for both seg|gt and gt|seg."""
    plt.ion()
    pxy, px, py, hxgy, hygx, lpygx, lpxgy = evaluate.vi_tables(
        seg, gt, ignore_seg=ignore_seg, ignore_gt=ignore_gt)
    cu = -px * lpygx
    co = -py * lpxgy
    if hlines is None:
        hlines = []
    elif hlines == True:
        hlines = 10
    if type(hlines) == int:
        minc = min(cu[cu != 0].min(), co[co != 0].min())
        maxc = max(cu[cu != 0].max(), co[co != 0].max())
        hlines = np.arange(maxc / hlines, maxc, maxc / hlines)
    plt.figure()
    if subplot: plt.subplot(1, 2, 1)
    plot_vi_breakdown_panel(px,
                            -lpygx,
                            'False merges',
                            'p(S=seg)',
                            'H(G|S=seg)',
                            hlines,
                            c='blue',
                            **kwargs)
    if subplot: plt.subplot(1, 2, 2)
    plot_vi_breakdown_panel(py,
                            -lpxgy,
                            'False splits',
                            'p(G=gt)',
                            'H(S|G=gt)',
                            hlines,
                            c='orange',
                            **kwargs)
    if not subplot:
        plt.title('vi contributions by body.')
        plt.legend(loc='upper right', scatterpoints=1)
        plt.xlabel('Segment size (fraction of volume)', fontsize='large')
        plt.ylabel('Conditional entropy (bits)', fontsize='large')
        xmax = max(px.max(), py.max())
        plt.xlim(-0.05 * xmax, 1.05 * xmax)
        ymax = max(-lpygx.min(), -lpxgy.min())
        plt.ylim(-0.05 * ymax, 1.05 * ymax)
示例#3
0
文件: viz.py 项目: NealJMD/gala
def plot_vi_breakdown(seg, gt, ignore_seg=[], ignore_gt=[], 
                      hlines=None, subplot=False, figsize=None, **kwargs):
    """Plot conditional entropy H(Y|X) vs P(X) for both seg|gt and gt|seg.
    
    Parameters
    ----------
    seg : np.ndarray of int, shape (M, [N, ..., P])
        The automatic (candidate) segmentation.
    gt : np.ndarray of int, shape (M, [N, ..., P]) (same as `seg`)
        The gold standard/ground truth segmentation.
    ignore_seg : list of int, optional
        Ignore segments in this list from the automatic segmentation during
        evaluation and plotting.
    ignore_gt : list of int, optional
        Ignore segments in this list from the ground truth segmentation during
        evaluation and plotting.
    hlines : int, optional
        Plot this many isoclines between the minimum and maximum VI
        contributions.
    subplot : bool, optional
        If True, plot oversegmentation and undersegmentation in separate
        subplots.
    figsize : tuple of float, optional
        The figure width and height, in inches.
    **kwargs : dict
        Additional keyword arguments for `matplotlib.pyplot.plot`.

    Returns
    -------
    None
    """
    plt.ion()
    pxy,px,py,hxgy,hygx,lpygx,lpxgy = evaluate.vi_tables(seg, gt,
                                                         ignore_seg, ignore_gt)
    cu = -px*lpygx
    co = -py*lpxgy
    if hlines is None:
        hlines = []
    elif hlines == True:
        hlines = 10
    if type(hlines) == int:
        maxc = max(cu[cu!=0].max(), co[co!=0].max())
        hlines = np.arange(maxc/hlines, maxc, maxc/hlines)
    plt.figure(figsize=figsize)
    if subplot: plt.subplot(1,2,1)
    plot_vi_breakdown_panel(px, -lpygx, 
        'False merges', 'p(S=seg)', 'H(G|S=seg)', 
        hlines, c='blue', **kwargs)
    if subplot: plt.subplot(1,2,2)
    plot_vi_breakdown_panel(py, -lpxgy, 
        'False splits', 'p(G=gt)', 'H(S|G=gt)', 
        hlines, c='orange', **kwargs)
    if not subplot:
        plt.title('vi contributions by body.')
        plt.legend(loc='upper right', scatterpoints=1)
        plt.xlabel('Segment size (fraction of volume)', fontsize='large')
        plt.ylabel('Conditional entropy (bits)', fontsize='large')
        xmax = max(px.max(), py.max())
        plt.xlim(-0.05*xmax, 1.05*xmax)
        ymax = max(-lpygx.min(), -lpxgy.min())
        plt.ylim(-0.05*ymax, 1.05*ymax)
示例#4
0
文件: viz.py 项目: nagyist/gala
def plot_vi_breakdown(seg,
                      gt,
                      ignore_seg=[],
                      ignore_gt=[],
                      hlines=None,
                      subplot=False,
                      figsize=None,
                      **kwargs):
    """Plot conditional entropy H(Y|X) vs P(X) for both seg|gt and gt|seg.
    
    Parameters
    ----------
    seg : np.ndarray of int, shape (M, [N, ..., P])
        The automatic (candidate) segmentation.
    gt : np.ndarray of int, shape (M, [N, ..., P]) (same as `seg`)
        The gold standard/ground truth segmentation.
    ignore_seg : list of int, optional
        Ignore segments in this list from the automatic segmentation during
        evaluation and plotting.
    ignore_gt : list of int, optional
        Ignore segments in this list from the ground truth segmentation during
        evaluation and plotting.
    hlines : int, optional
        Plot this many isoclines between the minimum and maximum VI
        contributions.
    subplot : bool, optional
        If True, plot oversegmentation and undersegmentation in separate
        subplots.
    figsize : tuple of float, optional
        The figure width and height, in inches.
    **kwargs : dict
        Additional keyword arguments for `matplotlib.pyplot.plot`.

    Returns
    -------
    None
    """
    plt.ion()
    pxy, px, py, hxgy, hygx, lpygx, lpxgy = evaluate.vi_tables(
        seg, gt, ignore_seg, ignore_gt)
    cu = -px * lpygx
    co = -py * lpxgy
    if hlines is None:
        hlines = []
    elif hlines == True:
        hlines = 10
    if type(hlines) == int:
        maxc = max(cu[cu != 0].max(), co[co != 0].max())
        hlines = np.arange(maxc / hlines, maxc, maxc / hlines)
    plt.figure(figsize=figsize)
    if subplot: plt.subplot(1, 2, 1)
    plot_vi_breakdown_panel(px,
                            -lpygx,
                            'False merges',
                            'p(S=seg)',
                            'H(G|S=seg)',
                            hlines,
                            c='blue',
                            **kwargs)
    if subplot: plt.subplot(1, 2, 2)
    plot_vi_breakdown_panel(py,
                            -lpxgy,
                            'False splits',
                            'p(G=gt)',
                            'H(S|G=gt)',
                            hlines,
                            c='orange',
                            **kwargs)
    if not subplot:
        plt.title('vi contributions by body.')
        plt.legend(loc='upper right', scatterpoints=1)
        plt.xlabel('Segment size (fraction of volume)', fontsize='large')
        plt.ylabel('Conditional entropy (bits)', fontsize='large')
        xmax = max(px.max(), py.max())
        plt.xlim(-0.05 * xmax, 1.05 * xmax)
        ymax = max(-lpygx.min(), -lpxgy.min())
        plt.ylim(-0.05 * ymax, 1.05 * ymax)