#!/usr/bin/python # -*- coding: utf-8 -*- # \file AttributeProfiles.py # \brief TODO # \author Florent Guiotte # \version 0.1 # \date 04 avril 2018 # # TODO details from .core import Filter, Stack ## TODO: dep import sys import numpy as np sys.path.append('../triskele/python') import triskele class AttributeProfiles(Filter): def __init__(self, area=None, sd=None, moi=None): super().__init__(self.__class__.__name__) self.area = np.sort(area) if area is not None else None self.sd = np.sort(sd) if sd is not None else None self.moi = np.sort(moi) if moi is not None else None def _process_desc(self): att_desc = dict() for att in ['area', 'sd', 'moi']: att_desc[att] = list() if self.__getattribute__(att) is not None: att_desc[att].extend( ['Thickening {} {}'.format(att, x) for x in self.__getattribute__(att)[::-1]]) att_desc[att].append(None) att_desc[att].extend( ['Thinning {} {}'.format(att, x) for x in self.__getattribute__(att)]) return att_desc def _process_offset(self): att_offset = dict() for att in ['area', 'sd', 'moi']: values = self.__getattribute__(att) att_offset[att] = len(values) * 2 + 1 if values is not None else 0 return att_offset def _process(self, data, metadata): t = triskele.Triskele(data, verbose=False) att_min = t.filter(tree='min-tree', area=self.area, standard_deviation=self.sd, moment_of_inertia=self.moi) att_max = t.filter(tree='max-tree', area=self.area, standard_deviation=self.sd, moment_of_inertia=self.moi) ## Merge filtering as APs ## Create new metadata ### Pre-process descriptions att_desc = self._process_desc() ### Compute stack offsets att_offset = self._process_offset() stack_offset = sum(att_offset.values()) ### Merge old and new descriptions metadata_new = list() for stack in metadata: if stack.end - stack.begin > 1: raise NotImplementedError('Nested filtering not implemented yet') for att in ['area', 'sd', 'moi']: stack_new = Stack(stack_offset * stack.begin, att_offset[att], stack.desc[0], stack.symb[0]) for old_desc, new_desc in zip(stack_new.desc, att_desc[att]): print('DESCRIPTION: {} > {}'.format(old_desc, new_desc)) old_desc.append(new_desc) metadata_new.append(stack_new) att = np.dstack((att_min, att_max)) return att, metadata_new if __name__ == '__main__': area = [10, 100, 1000] sd = [.1, .9] ap = AttributeProfiles(area, sd) print(ap._process_desc()) print(ap._process_offset())