從切片重建 2D 影像#
- sklearn.feature_extraction.image.reconstruct_from_patches_2d(patches, image_size)[來源]#
從所有切片重建影像。
假設切片重疊,影像的建構方式是從左到右、從上到下填入切片,並平均重疊區域。
在使用者指南中閱讀更多。
- 參數:
- 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)