Skip to content

Instantly share code, notes, and snippets.

@chkoar
Last active May 13, 2020 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chkoar/810bbe21d42a5c695b1c23424440fb4c to your computer and use it in GitHub Desktop.
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
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