Python庫skimage繪制二值圖像代碼實例
二值圖像的凸殼指的是包圍輸入二值圖像白色區(qū)域的最小的凸多邊形的像素集合。
skimage中的函數(shù)
from skimage.morphology import convex_hull_imagechull = convex_hull_image(image)
完整代碼:
'''===========Convex Hull===========The convex hull of a binary image is the set of pixels included in thesmallest convex polygon that surround all white pixels in the input.A good overview of the algorithm is given on `Steve Eddin’s blog<http://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/>`__.'''import matplotlib.pyplot as pltfrom skimage.morphology import convex_hull_imagefrom skimage import data, img_as_floatfrom skimage.util import invert# The original image is inverted as the object must be white.image = invert(data.horse())chull = convex_hull_image(image)fig, axes = plt.subplots(1, 2, figsize=(8, 4))ax = axes.ravel()ax[0].set_title(’Original picture’)ax[0].imshow(image, cmap=plt.cm.gray)ax[0].set_axis_off()ax[1].set_title(’Transformed picture’)ax[1].imshow(chull, cmap=plt.cm.gray)ax[1].set_axis_off()plt.tight_layout()plt.show()####################################################################### We prepare a second plot to show the difference.#chull_diff = img_as_float(chull.copy())chull_diff[image] = 2fig, ax = plt.subplots()ax.imshow(chull_diff, cmap=plt.cm.gray)ax.set_title(’Difference’)plt.show()
實驗輸出
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. 解決Android Studio 格式化 Format代碼快捷鍵問題2. php解決注冊并發(fā)問題并提高QPS3. 完美解決vue 中多個echarts圖表自適應的問題4. JavaEE SpringMyBatis是什么? 它和Hibernate的區(qū)別及如何配置MyBatis5. Springboot 全局日期格式化處理的實現(xiàn)6. Java使用Tesseract-Ocr識別數(shù)字7. SpringBoot+TestNG單元測試的實現(xiàn)8. vue實現(xiàn)web在線聊天功能9. 在Chrome DevTools中調(diào)試JavaScript的實現(xiàn)10. Python使用urlretrieve實現(xiàn)直接遠程下載圖片的示例代碼
