4

scikit learnの訓練されたクラスファクターです。 RandomForestClassifier。分類器は、サイズのサンプルに訓練されている。 25x25。大きな画像のタイル/ウィンドウにScikitLearnクラシファイアを適用する方法

これを大きな画像(例:640x480)のすべてのタイル/ウィンドウに簡単に適用するにはどうすればよいですか?

行うことができますが(先に遅いコード!)である

x_train = np.arange(25*25*1000).reshape(25,25,1000) # just some pseudo training data 
y_train = np.arange(1000) # just some pseudo training labels 
clf = RandomForestClassifier() 
clf.train(...) #train the classifier 

img = np.arange(640*480).reshape(640,480) #just some pseudo image data 

clf.magicallyApplyToAllSubwindoes(img) 

私はimg内のすべての25×25のウィンドウにclfを適用することができますどのように?

答えて

4

おそらくskimage.util.view_as_windowsのようなものをお探しですか?ドキュメントの末尾には、メモリの使用に関する警告を必ずお読みください。

view_as_windowsを使用すると、魔法のような返される配列を再形成することにより、画像内のすべてのウィンドウからテストデータを生成することができ、あなたのための手頃な価格のアプローチの場合:

import numpy as np 
from skimage import io 
from skimage.util import view_as_windows 

img = io.imread('image_name.png')  
window_shape = (25, 25) 

windows = view_as_windows(img, window_shape)  
n_windows = np.prod(windows.shape[:2]) 
n_pixels = np.prod(windows.shape[2:]) 

x_test = windows.reshape(n_windows, n_pixels) 

clf.apply(x_test) 
関連する問題