<commit_before>import os
import cv2
import numpy as np


def extract(image_files, image_path, feature_path):
    """ Extracts SIFT features for a list of images. Saves the descriptors to file.

        Parameters
        ----------
        image_files: Image names.
        image_path: Folder path for image files.
        feature_path: Folder path for features.
    """
    if not os.path.exists(feature_path):
        os.makedirs(feature_path)

    for image_file in image_files:
        image = cv2.imread(os.path.join(image_path, image_file), cv2.IMREAD_GRAYSCALE)
        locs, descs = extract_feature_vectors(image)

        save_features(feature_path, image_file, locs, descs)

        print 'Extracted {0} features for {1}'.format(descs.shape[0], image_file)

    print 'Features extracted'


def extract_feature_vectors(image, edge_threshold=10, peak_threshold=0.001):<commit_msg>Extracting features in parallel.<commit_after>import os
import cv2
import numpy as np

from multiprocessing import Pool


class SiftExtractor:

    def __init__(self, image_path, feature_path):
        """ Creates a SiftExtractor.

            Parameters
            ----------
            image_path: Path to image files.
            feature_path: Path to feature files.
        """

        self.image_path = image_path
        self.feature_path = feature_path

    def __call__(self, image):
        """ Extracts SIFT features for an image and saves the descriptors and locations to file.

            Parameters
            ----------
            image: Image name.
        """

        im = cv2.imread(os.path.join(self.image_path, image), cv2.IMREAD_GRAYSCALE)
        locs, descs = extract_feature_vectors(im)

        save_features(self.feature_path, image, locs, descs)

        print 'Extracted {0} features for {1}'.format(descs.shape[0], image)


def extract(images, image_path, feature_path, processes=6):
    """ Extracts SIFT features for a list of images. Saves the descriptors and locations to file.

        Parameters
        ----------
        image_files: Image names.
        image_path: Folder path for image files.
        feature_path: Folder path for features.
    """
    if not os.path.exists(feature_path):
        os.makedirs(feature_path)

    sift_extractor = SiftExtractor(image_path, feature_path)
    if processes == 1:
        for image in images:
            sift_extractor(image)
    else:
        pool = Pool(processes)
        pool.map(sift_extractor, images)

    print 'Features extracted'


def extract_feature_vectors(image, edge_threshold=10, peak_threshold=0.001):
{'fraction_non_alphanumeric': 0.0938822624086187, 'fraction_numerical': 0.010003847633705272, 'mean_word_length': 2.586206896551724, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2921521', 'n_tokens_mistral': 784, 'n_tokens_neox': 745, 'n_words': 212}