reconstruct_from_patches_2d#

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

从其所有补丁重建图像。

假设补丁重叠,图像通过从左到右、从上到下填充补丁来构建,重叠区域取平均值。

Read more in the User Guide.

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

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

image_sizeint 的元组 (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)