movie_maker.py 文件源码

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

项目:chxanalys 作者: yugangzhang 项目源码 文件源码
def save_png_series( imgs, ROI=None, logs=True, outDir=None, uid=None,vmin=None, vmax=None,cmap='viridis',dpi=100):
    import numpy as np
    import matplotlib.pyplot as plt
    from matplotlib.colors import LogNorm

    """
    save a series of images in a format of png

    Parameters
    ----------
    imgs : array
        image data array for the movie
        dimensions are: [num_img][num_rows][num_cols]
    ROI: e.g. xs,xe,ys,ye = vert #x_start, x_end, y_start,y_end
    outDir: the output path
    vmin/vmax: for image contrast
    cmap: the color for plot
    dpi: resolution 

    Returns
    -------
    save png files 

    """     
    if uid==None:
        uid='uid'
    num_frame=0
    for img in imgs: 
        fig = plt.figure()
        ax = fig.add_subplot(111)  
        ax.get_xaxis().set_visible(False)
        ax.get_yaxis().set_visible(False)
        if ROI is None:
            i0=img
            asp =1.0         
        else:
            i0=select_regoin(img, ROI, keep_shape=False,)
            xs,xe,ys,ye = ROI        
            asp = (ye-ys)/float( xe - xs ) 
        ax.set_aspect('equal')  

        if not logs:         
            im=ax.imshow(i0, origin='lower' ,cmap=cmap,interpolation="nearest", vmin=vmin,vmax=vmax)  #vmin=0,vmax=1,
        else:
            im=ax.imshow(i0, origin='lower' ,cmap=cmap,
                        interpolation="nearest" , norm=LogNorm(vmin,  vmax)) 
        #ttl = ax.text(.75, .2, '', transform = ax.transAxes, va='center', color='white', fontsize=18) 
        #fig.set_size_inches( [5., 5 * asp] )
        #plt.tight_layout()  
        fname = outDir + 'uid_%s-frame-%s.png'%(uid,num_frame )
        num_frame +=1
        plt.savefig( fname, dpi=None )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号