display.py 文件源码

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

项目:DeepPicker-python 作者: nejyeah 项目源码 文件源码
def plot_circle_in_micrograph(micrograph_2d, coordinate, particle_size, filename, color = 'white'):
    """plot the particle circle in micrograph image 

    Based on the coordinate of particle, plot circles of the particles in the micrograph.
    And save the ploted image in filename.

    Args:
        micrograph_2d: numpy.array,it is a 2D numpy array.
        coordinate: list, it is a 2D list, the shape is (num_particle, 2).
        particle_size: int, the value of the particle size
        filename: the filename of the image to be save.
        color: define the color of the circle

    Raises:
        pass
    """
    micrograph_2d = micrograph_2d.reshape(micrograph_2d.shape[0], micrograph_2d.shape[1])
    fig = plt.figure()
    ax = fig.add_subplot(111)
    plt.axis('off')
    plt.gray()
    plt.imshow(micrograph_2d)
    radius = particle_size/2
    i = 0 
    while True: 
        if i >= len(coordinate):
            break
        coordinate_x = coordinate[i][0]
        coordinate_y = coordinate[i][1]
        cir1 = Circle(xy = (coordinate_x, coordinate_y), radius = radius, alpha = 0.5, color = color, fill = False)
        ax.add_patch(cir1)
        # extract the particles
        i = i + 1
    plt.savefig(filename)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号