zoukankan      html  css  js  c++  java
  • python库skimage 常值轮廓寻找并标记

    我们使用行进正方形方法找到图像中的常值轮廓
    **函数:

    Find contours at a constant value of 0.8

    contours = measure.find_contours(r, 0.8)**
    使用它,需要:from skimage import measure

    """
    ===============
    Contour finding
    ===============
    
    We use a marching squares method to find constant valued contours in an image.
    In ``skimage.measure.find_contours``, array values are linearly interpolated
    to provide better precision of the output contours. Contours which intersect
    the image edge are open; all others are closed.
    
    The `marching squares algorithm
    <http://www.essi.fr/~lingrand/MarchingCubes/algo.html>`__ is a special case of
    the marching cubes algorithm (Lorensen, William and Harvey E. Cline. Marching
    Cubes: A High Resolution 3D Surface Construction Algorithm. Computer Graphics
    (SIGGRAPH 87 Proceedings) 21(4) July 1987, p. 163-170).
    
    """
    import numpy as np
    import matplotlib.pyplot as plt
    
    from skimage import measure
    
    
    # Construct some test data
    x, y = np.ogrid[-np.pi:np.pi:100j, -np.pi:np.pi:100j]
    r = np.sin(np.exp((np.sin(x)**3 + np.cos(y)**2)))
    
    # Find contours at a constant value of 0.8
    contours = measure.find_contours(r, 0.8)
    
    # Display the image and plot all contours found
    fig, ax = plt.subplots()
    ax.imshow(r, cmap=plt.cm.gray)
    
    for n, contour in enumerate(contours):
        ax.plot(contour[:, 1], contour[:, 0], linewidth=2, color='red')
    
    ax.axis('image')
    ax.set_xticks([])
    ax.set_yticks([])
    plt.show()
    

    红色标记图像轮廓

  • 相关阅读:
    ajax三级联动
    ajax基础
    pdo连接数据
    jquery选择器和基本语句
    会话
    封装连接类
    1218数据访问
    php登陆与注册
    数据库连接和乱码问题
    mysql 严格模式 Strict Mode说明(text 字段不能加默认或者 不能加null值得修改方法)
  • 原文地址:https://www.cnblogs.com/wojianxin/p/12652876.html
Copyright © 2011-2022 走看看