Last active
May 13, 2020 11:58
-
-
Save chkoar/810bbe21d42a5c695b1c23424440fb4c to your computer and use it in GitHub Desktop.
scikit-learn compatible transformer that extracts haralick features from a given collection of images
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import joblib | |
from mahotas import features | |
from sklearn.base import TransformerMixin, BaseEstimator | |
class HaralickExtractor(BaseEstimator, TransformerMixin): | |
def __init__(self, n_jobs=1): | |
self.n_jobs = n_jobs | |
def fit(self, X, y=None): | |
return self | |
def transform(self, X): | |
extract_features = joblib.delayed(lambda x: features.haralick(x).mean(0)) | |
execute = joblib.Parallel(n_jobs=self.n_jobs) | |
images = execute(extract_features(x) for x in X) | |
return np.array(images) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment