Merge branch 'master' of http://git.normalized.xyz/Florent/LD2DAPs
This commit is contained in:
commit
47b290a23d
34
ld2dap/AttributeProfiles.py
Normal file
34
ld2dap/AttributeProfiles.py
Normal file
@ -0,0 +1,34 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file AttributeProfiles.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 04 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from core import Filter
|
||||
|
||||
## TODO: dep
|
||||
import sys
|
||||
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 = area
|
||||
self.sd = sd
|
||||
self.moi = moi
|
||||
|
||||
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)
|
||||
|
||||
return att, None
|
||||
32
ld2dap/LoadTIFF.py
Normal file
32
ld2dap/LoadTIFF.py
Normal file
@ -0,0 +1,32 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file LoadTIFF.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 04 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from core import Input
|
||||
import numpy as np
|
||||
|
||||
## TODO: dep
|
||||
import sys
|
||||
sys.path.append('../triskele/python')
|
||||
import triskele
|
||||
|
||||
class LoadTIFF(Input):
|
||||
def __init__(self, tiffFiles):
|
||||
super().__init__(self.__class__.__name__)
|
||||
self.files = tiffFiles
|
||||
|
||||
def _process(self, data, metadata):
|
||||
layers = list()
|
||||
|
||||
for file in self.files:
|
||||
print('Loading {}'.format(file))
|
||||
layers.append(triskele.read(file))
|
||||
|
||||
return np.stack(layers, axis=2), self.files
|
||||
|
||||
17
ld2dap/core/Filter.py
Normal file
17
ld2dap/core/Filter.py
Normal file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Filter.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from .Input import Input
|
||||
from .Output import Output
|
||||
|
||||
class Filter(Output, Input):
|
||||
"""Output should be first"""
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Filter:{}'.format(name))
|
||||
28
ld2dap/core/Input.py
Normal file
28
ld2dap/core/Input.py
Normal file
@ -0,0 +1,28 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Input.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from .Node import Node
|
||||
|
||||
class Input(Node):
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Input:{}'.format(name))
|
||||
self.outputs = list()
|
||||
|
||||
def register(self, output):
|
||||
self.outputs.append(output)
|
||||
|
||||
def process(self, data, metadata=None):
|
||||
"""Override abstract method"""
|
||||
data, meta = self._process(data, metadata)
|
||||
for output in self.outputs:
|
||||
output.process(data, meta)
|
||||
|
||||
def _run(self):
|
||||
self.process(None, None)
|
||||
30
ld2dap/core/Node.py
Normal file
30
ld2dap/core/Node.py
Normal file
@ -0,0 +1,30 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Node.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
|
||||
class Node(object):
|
||||
def __init__(self, name='A NODE HAS NO NAME'):
|
||||
self.name = name
|
||||
|
||||
def __str__(self):
|
||||
return ("Node:{}".format(self.name))
|
||||
|
||||
def process(self, data, metadata=None):
|
||||
self._process(data)
|
||||
|
||||
def _process(self, data, metadata=None):
|
||||
raise NotImplementedError(
|
||||
'{} should override _process(self, data, metadata)'.format(self))
|
||||
|
||||
def _run(self):
|
||||
raise NotImplementedError('{} should override _run()'.format(self))
|
||||
|
||||
def run(self):
|
||||
return self._run()
|
||||
35
ld2dap/core/Output.py
Normal file
35
ld2dap/core/Output.py
Normal file
@ -0,0 +1,35 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file Output.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
#from . import Node, Input
|
||||
from .Node import Node
|
||||
from .Input import Input
|
||||
|
||||
class Output(Node):
|
||||
def __init__(self, name='__CHILD__'):
|
||||
super().__init__('Output:{}'.format(name))
|
||||
self.__dict__['input'] = None
|
||||
|
||||
def __setattr__(self, name, value):
|
||||
if name == 'input':
|
||||
self._input(value)
|
||||
else:
|
||||
self.__dict__[name] = value
|
||||
|
||||
def _input(self, inode):
|
||||
if not isinstance(inode, (Input)):
|
||||
raise NotImplementedError('{} is not an Input'.format(inode))
|
||||
self.__dict__['input'] = inode
|
||||
inode.register(self)
|
||||
|
||||
def _run(self):
|
||||
if self.input is None:
|
||||
raise RuntimeError('{} do not have an input'.format(self))
|
||||
return self.input.run()
|
||||
13
ld2dap/core/__init__.py
Normal file
13
ld2dap/core/__init__.py
Normal file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file %filename%.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 04 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from .Output import Output
|
||||
from .Input import Input
|
||||
from .Filter import Filter
|
||||
26
ld2dap/test.py
Normal file
26
ld2dap/test.py
Normal file
@ -0,0 +1,26 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file test.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 03 avril 2018
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from core import Input, Output, Filter
|
||||
from LoadTIFF import LoadTIFF
|
||||
from AttributeProfiles import AttributeProfiles as APs
|
||||
|
||||
def main():
|
||||
i = LoadTIFF(['../Data/test.tiff'])
|
||||
ap = APs()
|
||||
o = Output('o')
|
||||
|
||||
ap.input = i
|
||||
o.input = i
|
||||
|
||||
o.run()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Loading…
Reference in New Issue
Block a user