PatchExtractor?
class sklearn.feature_extraction.image.PatchExtractor(*, patch_size=None, max_patches=None, random_state=None)
從一組圖像中提取補丁
在用戶指南中閱讀更多內容。
新版本0.9。
參數 | 說明 |
---|---|
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使隨機性具有確定性。詳見術語表。 |
示例
>>> from sklearn.datasets import load_sample_images
>>> from sklearn.feature_extraction import image
>>> # Use the array data from the second image in this dataset:
>>> X = load_sample_images().images[1]
>>> print('Image shape: {}'.format(X.shape))
Image shape: (427, 640, 3)
>>> pe = image.PatchExtractor(patch_size=(2, 2))
>>> pe_fit = pe.fit(X)
>>> pe_trans = pe.transform(X)
>>> print('Patches shape: {}'.format(pe_trans.shape))
Patches shape: (545706, 2, 2)
方法
方法 | 說明 |
---|---|
fit (X[, y]) |
不執行任何操作,就會不加更改地返回估算器。 |
get_params ([deep]) |
獲取這個估計器的參數。 |
set_params (**params) |
設置的參數估計量。 |
transform (X) |
將X中的圖像樣本轉換為patch數據矩陣。 |
__init__(*, patch_size=None, max_patches=None, random_state=None)
初始化self。請參閱help(type(self))以獲得準確的說明。
fit(X, y=None)
[[源碼]]
不執行任何操作,就會不加更改地返回估算器。
這個方法只是用來實現通常的API,因此可以在管道中工作。
參數 | 說明 |
---|---|
X | array-like of shape (n_samples, n_features) 訓練數據 |
get_params(deep=True)
獲取這個估計器的參數。
參數 | 說明 |
---|---|
deep | bool, default=True 如果為真,將返回此估計器的參數以及包含的作為估計器的子對象。 |
返回值 | 說明 |
---|---|
params | mapping of string to any 參數名稱映射到它們的值。 |
set_params(**params)
設置這個估計器的參數。
該方法適用于簡單估計量和嵌套對象。后者具有形式為<component>_<parameter>
的參數,這樣就讓更新嵌套對象的每個樣本成為了可能。
參數 | 說明 |
---|---|
**params | dict 訓練數據 |
返回值 | 說明 |
---|---|
self | object 估計器實例。 |
transform(X)
將X中的圖像樣本轉換為patch數據矩陣。
參數 | 說明 |
---|---|
X | ndarray of shape (n_samples, image_height, image_width) or (n_samples, image_height, image_width, n_channels) 陣列的圖像,從中提取斑塊。對于彩色圖像,最后一個維度指定了通道:RGB圖像的n_channels=3。 |
返回值 | 說明 |
---|---|
patches | array of shape (n_patches, patch_height, patch_width) or (n_patches, patch_height, patch_width, n_channels) 從圖像中提取的patch的集合,其中n_patch是n_samples * max_patch,或者是可以提取的patch的總數。 |