How To Apply A Scikitlearn Classifier To Tiles/windows In A Large Image
Given is a trained classifer in scikit learn, e.g. a RandomForestClassifier. The classifier has been trained on samples of size e.g. 25x25. How can I easily apply this to all tiles
Solution 1:
Perhaps you are looking for something like skimage.util.view_as_windows
. Please, be sure to read the caveat about memory usage at the end of the documentation.
If using view_as_windows
is an affordable approach for you, you could magically generate test data from all the windows in the image by reshaping the returned array like this:
import numpy as np
from skimage import io
from skimage.utilimport 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)
Post a Comment for "How To Apply A Scikitlearn Classifier To Tiles/windows In A Large Image"