从二维图像块重建图像#
- sklearn.feature_extraction.image.reconstruct_from_patches_2d(patches, image_size)[source]#
从所有图像块重建图像。
假设图像块相互重叠,图像通过从左到右、从上到下填充图像块来构建,对重叠区域取平均值。
更多信息请参见 用户指南.
- 参数:
- 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_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)
图库示例#
使用字典学习进行图像去噪