Python庫(kù)skimage繪制二值圖像代碼實(shí)例
二值圖像的凸殼指的是包圍輸入二值圖像白色區(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()
實(shí)驗(yàn)輸出
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. jsp文件下載功能實(shí)現(xiàn)代碼2. CSS可以做的幾個(gè)令你嘆為觀止的實(shí)例分享3. XML入門(mén)的常見(jiàn)問(wèn)題(二)4. JSP之表單提交get和post的區(qū)別詳解及實(shí)例5. 讀大數(shù)據(jù)量的XML文件的讀取問(wèn)題6. ASP實(shí)現(xiàn)加法驗(yàn)證碼7. 低版本IE正常運(yùn)行HTML5+CSS3網(wǎng)站的3種解決方案8. asp知識(shí)整理筆記4(問(wèn)答模式)9. javascript xml xsl取值及數(shù)據(jù)修改第1/2頁(yè)10. 概述IE和SQL2k開(kāi)發(fā)一個(gè)XML聊天程序
