sklearn.feature_extraction.extract_patches_2d?

sklearn.feature_extraction.image.extract_patches_2d(image, patch_size, *, max_patches=None, random_state=None)

[源碼]

將二維圖像重塑為一組補丁

產生的補丁被分配在一個專用的陣列中。

用戶指南中閱讀更多內容。

參數 說明
image ndarray of shape (image_height, image_width) or (image_height, image_width, n_channels)
原始圖像數據。對于彩色圖像,最后一個維度指定了通道:RGB圖像的n_channels=3。
patch_size tuple of int (patch_height, patch_width)
一個patch的尺寸。
max_patches int or float, default=None
要提取的最大patch數。如果max_patch是0到1之間的浮點數,則它被認為是補丁總數的一個比例。
random_state int, RandomState instance, default=None
確定當max_patch不是None時用于隨機采樣的隨機數生成器。使用int使隨機性具有確定性。詳見術語表
返回值 說明
patches array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels)
從圖像中提取的patch集合,其中n_patch為max_patch或可提取的patch總數。

示例

>>> 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: (4276403)
>>> patches = image.extract_patches_2d(one_image, (22))
>>> print('Patches shape: {}'.format(patches.shape))
Patches shape: (272214223)
>>> # 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]]]

示例sklearn.feature_extraction.image.extract_patches_2d?