reconstruct_from_patches_2d#
- sklearn.feature_extraction.image.reconstruct_from_patches_2d(patches, image_size)#
从所有补丁重建图像。
假设补丁重叠,并且通过从左到右、从上到下填充补丁来构建图像,平均重叠区域。
更多信息请参阅 用户指南 。
- Parameters:
- patchesndarray of shape (n_patches, patch_height, patch_width) 或 (n_patches, patch_height, patch_width, n_channels)
完整的补丁集。如果补丁包含颜色信息,通道沿最后一个维度索引:RGB 补丁将有
n_channels=3
。- image_sizetuple of int (image_height, image_width) 或 (image_height, image_width, n_channels)
将要重建的图像的大小。
- Returns:
- imagendarray of shape image_size
重建的图像。
Examples
>>> 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)
Gallery examples#
使用字典学习进行图像去噪