Python庫skimage繪制二值圖像代碼實(shí)例
二值圖像的凸殼指的是包圍輸入二值圖像白色區(qū)域的最小的凸多邊形的像素集合。
skimage中的函數(shù)
from skimage.morphology import convex_hull_image
chull = convex_hull_image(image)
完整代碼:
""" =========== Convex Hull =========== The convex hull of a binary image is the set of pixels included in the smallest 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 plt from skimage.morphology import convex_hull_image from skimage import data, img_as_float from 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] = 2 fig, ax = plt.subplots() ax.imshow(chull_diff, cmap=plt.cm.gray) ax.set_title('Difference') plt.show()
實(shí)驗(yàn)輸出
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Python matplotlib繪圖設(shè)置圖例案例
這篇文章主要給大家分享Python matplotlib繪圖設(shè)置圖例案例,過程會(huì)學(xué)到edgecolor 圖例邊框線顏色 facecolor 圖例背景色 shadow 是否添加陰影 title 圖例標(biāo)題 fontsize 設(shè)置字體大小,小編覺得挺有意思的,感興趣的小伙伴也可以參考一下2021-12-12比較詳細(xì)Python正則表達(dá)式操作指南(re使用)
Python 1.5之前版本則是通過 regex 模塊提供 Emecs 風(fēng)格的模式。Emacs 風(fēng)格模式可讀性稍差些,而且功能也不強(qiáng),因此編寫新代碼時(shí)盡量不要再使用 regex 模塊,當(dāng)然偶爾你還是可能在老代碼里發(fā)現(xiàn)其蹤影2008-09-09圖文詳解Python中模塊或py文件導(dǎo)入(超詳細(xì)!)
導(dǎo)入文件目的就是為了執(zhí)行文件,下面這篇文章主要給大家介紹了關(guān)于Python中模塊或py文件導(dǎo)入的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04python 基于opencv實(shí)現(xiàn)高斯平滑
這篇文章主要介紹了python 基于opencv實(shí)現(xiàn)高斯平滑,幫助大家更好的理解和使用python處理圖片,感興趣的朋友可以了解下2020-12-12python opencv實(shí)現(xiàn)直線檢測(cè)并測(cè)出傾斜角度(附源碼+注釋)
這篇文章主要介紹了python opencv實(shí)現(xiàn)直線檢測(cè)并測(cè)出傾斜角度(附源碼+注釋),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-12-12