python的skimage庫 圖像讀取顯示


單幅圖像讀取並顯示

代碼

"""
讀取圖像並顯示
"""
import matplotlib.pyplot as plt
import matplotlib

from skimage import data

matplotlib.rcParams['font.size'] = 18

images = ('astronaut',
          'binary_blobs',
          'brick',
          'colorwheel',
          'camera',
          'checkerboard',
          'chelsea',
          'clock',
          'coffee',
          'coins',
          'grass',
          'gravel',
          'horse',
          'logo',
          'page',
          'text',
          'rocket',
          )


for name in images:
    # getattr(object, name[, default])
    # 函數功能是從對象object中獲取名稱為name的屬性,等效與調用object.name。
    caller = getattr(data, name)
    # 得到圖像們
    image = caller()
    plt.figure()
    plt.title(name)
    if image.ndim == 2:
        plt.imshow(image, cmap=plt.cm.gray)
    else:
        plt.imshow(image)

plt.show()

效果

程序顯示的圖像

讀取顯示立體圖像;同時顯示多幅圖像

代碼

"""
===============
Specific images
===============

"""
import matplotlib.pyplot as plt
import matplotlib
from skimage import data

matplotlib.rcParams['font.size'] = 18


######################################################################
# 立體圖像顯示
# Stereo images
# =============

fig, axes = plt.subplots(1, 2, figsize=(8, 4))
ax = axes.ravel()

images = data.stereo_motorcycle()
ax[0].imshow(images[0])
ax[1].imshow(images[1])

# tight_layout會自動調整子圖參數,使之填充整個圖像區域。這是個實驗特性,可能在一些情況下不工作。
# 它僅僅檢查坐標軸標簽、刻度標簽以及標題的部分。
fig.tight_layout()
plt.show()


######################################################################
# 同時顯示多幅人臉圖像
# Faces and non-faces dataset
# ===========================
#
# A sample of 20 over 200 images is displayed.

fig, axes = plt.subplots(4, 5, figsize=(20, 20))
ax = axes.ravel()
images = data.lfw_subset()
for i in range(20):
    ax[i].imshow(images[90+i], cmap=plt.cm.gray)
    ax[i].axis('off')
fig.tight_layout()
plt.show()

結果

立體圖像顯示
同時顯示多幅圖像


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM