visualizers.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:PyNIT 作者: dvm-shlee 项目源码 文件源码
def check_reg(fixed_img, moved_img, scale=15, norm=True, sigma=0.8, **kwargs):
        dim = list(moved_img.shape)
        resol = list(moved_img.header['pixdim'][1:4])
        # Convert 4D image to 3D or raise error
        data = convert_to_3d(moved_img)
        # Check normalization
        if norm:
            data = apply_p2_98(data)
        # Set slice axis for mosaic grid
        slice_axis, cmap = check_sliceaxis_cmap(data, kwargs)
        cmap = 'YlOrRd'
        # Set grid shape
        data, slice_grid, size = set_mosaic_fig(data, dim, resol, slice_axis, scale)
        fig, axes = BrainPlot.mosaic(fixed_img, scale=scale, norm=norm, cmap='bone', **kwargs)
        # Applying inversion
        invert = check_invert(kwargs)
        data = apply_invert(data, *invert)
        # Plot image
        for i in range(slice_grid[1] * slice_grid[2]):
            ax = axes.flat[i]
            edge = data[:, :, i]
            edge = feature.canny(edge, sigma=sigma)  # edge detection for second image
            # edge = ndimage.gaussian_filter(edge, 3)
            mask = np.ones(edge.shape)
            sx = ndimage.sobel(edge, axis=0, mode='constant')
            sy = ndimage.sobel(edge, axis=1, mode='constant')
            sob = np.hypot(sx, sy)
            mask[sob == False] = np.nan
            m_norm = colors.Normalize(vmin=0, vmax=1.5)
            if i < slice_grid[0] and False in np.isnan(mask.flatten()):
                ax.imshow(mask.T, origin='lower', interpolation='nearest', cmap=cmap, norm=m_norm, alpha=0.8)
            else:
                ax.imshow(np.zeros((dim[0], dim[1])).T, origin='lower', interpolation='nearest', cmap='bone')
            ax.set_axis_off()
        fig.set_facecolor('black')
        if notebook_env:
            display(fig)
        return fig, axes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号