def create_histogram(self, normalize_histogram=False): counts = [] words = [] word_occurences = [] hists = [] words_1 = [] self.logger.info('Start histogram creation...') fe = ExtractFeatures(self.feature_type) for idx, image_name in enumerate(self.im_list): self.logger.debug('Processing image %s, %s out of %s', image_name, idx, len(self.im_list)) try: img = np.array(Image.open(image_name)) except Exception as e: self.logger.error('Failed to load image %s', e) features = fe.extractFeature(img) words = self.km.predict(features.reshape(-1, 200)) histogram = np.bincount(words, minlength=self.vocab_size) if normalize_histogram: histogram = self.normalize_histogram(histogram) hists.append(histogram) words_1.append(words) self.logger.debug('') self.logger.info('Finished histogram creation') return hists
def feature_extraction(self): self.logger.info('Start feature extraction...') feature_extractor = ExtractFeatures(self.feature_type) #Feature list all_features = [] for idx, image_name in enumerate(self.im_list): self.logger.debug('Processing image %s, %s out of %s', image_name, idx, len(self.im_list)) try: img = np.array(Image.open(image_name)) except Exception as e: self.logger('Failed to load image %s', e) features = feature_extractor.extractFeature(img) self.logger.debug('Feature shape %s', features.shape) all_features.append(features.reshape(-1, 200)) self.logger.info('Finished feature extraction') return all_features