当前位置:   article > 正文

python读取图像属性并显示_python的skimage库 图像读取显示

ax[i].imshow

单幅图像读取并显示

代码

"""

读取图像并显示

"""

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()

效果

1240

读取显示立体图像;同时显示多幅图像

代码

"""

===============

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()

结果

1240

1240

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/782845
推荐阅读
相关标签
  

闽ICP备14008679号