python庫skimage 繪制二值圖像的凸殼

二值圖像的凸殼指的是包圍輸入二值圖像白色區(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()

實驗輸出

左圖:原圖;右圖:原圖的凸殼

一張圖中顯示原圖及其凸殼
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

  • 本文轉(zhuǎn)自 python數(shù)字圖像處理 霍夫線變換 在圖片處理中,霍夫變換主要是用來檢測圖片中的幾何形狀,包括直線、圓...
    jiandanjinxin閱讀 33,716評論 6 23
  • 本文轉(zhuǎn)自 python數(shù)字圖像處理 圖像簡單濾波 對圖像進行濾波,可以有兩種效果:一種是平滑濾波,用來抑制噪聲;另...
    jiandanjinxin閱讀 31,733評論 2 14
  • 本章包括以下內(nèi)容: 用形態(tài)學濾波器腐蝕和膨脹圖像; 用形態(tài)學濾波器開啟和閉合圖像; 在灰度圖像中應用形態(tài)學運算; ...
    sumpig閱讀 1,301評論 0 0
  • 廣州又回歸到了夏季的燥熱,時至中午,火辣的太陽即將走向正南方,大葉榕的葉子被曬的油亮,路上的人都撐起遮陽傘,有的走...
    王小村閱讀 1,184評論 0 6
  • 今天的作文,圈定了一個話題,叫無畏。多久沒動筆寫寫自己的事了,好久了吧。就是那種完全沒有任何目的的寫作,好久沒...
    MrC天才閱讀 223評論 0 0

友情鏈接更多精彩內(nèi)容