reconstruct_from_patches_2d#

sklearn.feature_extraction.image.reconstruct_from_patches_2d(patches, image_size)[源码]#

从图像的所有块中重建图像。

假定图像块(patches)之间存在重叠,图像通过从左到右、从上到下填充图像块来构建,并对重叠区域进行平均。

用户指南中阅读更多内容。

参数:
patches形状为 (n_patches, patch_height, patch_width) 或 (n_patches, patch_height, patch_width, n_channels) 的 ndarray

完整的图像块集合。如果图像块包含颜色信息,则通道沿最后一个维度索引:RGB 图像块将具有 n_channels=3

image_size形状为 (image_height, image_width) 或 (image_height, image_width, n_channels) 的整数元组

将要重建的图像大小。

返回:
image形状为 image_size 的 ndarray

重建的图像。

示例

>>> from sklearn.datasets import load_sample_image
>>> from sklearn.feature_extraction import image
>>> one_image = load_sample_image("china.jpg")
>>> print('Image shape: {}'.format(one_image.shape))
Image shape: (427, 640, 3)
>>> image_patches = image.extract_patches_2d(image=one_image, patch_size=(10, 10))
>>> print('Patches shape: {}'.format(image_patches.shape))
Patches shape: (263758, 10, 10, 3)
>>> image_reconstructed = image.reconstruct_from_patches_2d(
...     patches=image_patches,
...     image_size=one_image.shape
... )
>>> print(f"Reconstructed shape: {image_reconstructed.shape}")
Reconstructed shape: (427, 640, 3)