extract_patches_2d#
- sklearn.feature_extraction.image.extract_patches_2d(image, patch_size, *, max_patches=None, random_state=None)[源代码]#
将2D图像重塑为补丁集合。
生成的补丁被分配到专用阵列中。
阅读更多的 User Guide .
- 参数:
- image形状的nd数组(Image_height、Image_宽度)或 (图像_高度、图像_宽度、n_通道)
原始图像数据。对于彩色图像,最后一个维度指定通道:GB图像将具有
n_channels=3
.- patch_sizeint(patch_height,patch_size)的二元组
一个补丁的尺寸。
- max_patchesint或float,默认=无
要提取的最大补丁数。如果
max_patches
是0和1之间的浮动位,则取其占补丁总数的一定比例。如果max_patches
为无,它对应于可以提取的补丁总数。- random_stateint,RandomState实例,默认=无
确定用于随机采样的随机数生成器
max_patches
不是没有。使用int使随机性具有确定性。看到 Glossary .
- 返回:
- patches形状数组(n_patches、patch_height、patch_宽度)或 (n_patches、patches_height、patch_宽度、n_channels)
从图像中提取的补丁集合,其中
n_patches
要么是max_patches
或可以提取的补丁总数。
示例
>>> from sklearn.datasets import load_sample_image >>> from sklearn.feature_extraction import image >>> # Use the array data from the first image in this dataset: >>> one_image = load_sample_image("china.jpg") >>> print('Image shape: {}'.format(one_image.shape)) Image shape: (427, 640, 3) >>> patches = image.extract_patches_2d(one_image, (2, 2)) >>> print('Patches shape: {}'.format(patches.shape)) Patches shape: (272214, 2, 2, 3) >>> # Here are just two of these patches: >>> print(patches[1]) [[[174 201 231] [174 201 231]] [[173 200 230] [173 200 230]]] >>> print(patches[800]) [[[187 214 243] [188 215 244]] [[187 214 243] [188 215 244]]]