WIP on MinTree
This commit is contained in:
parent
76f49ac72b
commit
a621cca388
@ -11,9 +11,11 @@
|
||||
import collections
|
||||
|
||||
class ComponentTree:
|
||||
def __init__(self, parent=None):
|
||||
self.parent = parent
|
||||
self.children = dict()
|
||||
def __init__(self, parent=None, data=None):
|
||||
self.parent = parent
|
||||
self.children = list()
|
||||
self.component = None # Boolean filter on img
|
||||
self.data = data # ref. on img
|
||||
|
||||
def __iter__(self):
|
||||
return self.children.__iter__()
|
||||
|
40
MinTree.py
Executable file
40
MinTree.py
Executable file
@ -0,0 +1,40 @@
|
||||
#!/usr/bin/python
|
||||
# -*- coding: utf-8 -*-
|
||||
# \file MinTree.py
|
||||
# \brief TODO
|
||||
# \author Florent Guiotte <florent.guiotte@gmail.com>
|
||||
# \version 0.1
|
||||
# \date 10 oct. 2017
|
||||
#
|
||||
# TODO details
|
||||
|
||||
from ComponentTree import ComponentTree
|
||||
import cv2
|
||||
from scipy.ndimage import label
|
||||
|
||||
class MinTree(ComponentTree):
|
||||
def __init__(self, parent=None, data=None):
|
||||
super().__init__(parent, data)
|
||||
|
||||
def construct(self, value=0):
|
||||
if self.component is None:
|
||||
# Then self is groot
|
||||
self.component = img != None
|
||||
|
||||
filter = img * self> value
|
||||
labels_array, num_features = label(filter)
|
||||
|
||||
for i in range(num_features):
|
||||
child = MinTree(self, self.data)
|
||||
child.component = labels_array == i + 1
|
||||
child.construct(img, self.value + 1)
|
||||
self.children.append(child)
|
||||
|
||||
|
||||
def main():
|
||||
img = cv2.imread('./img/lena.ppm', 0)
|
||||
t = MinTree(data=img)
|
||||
t.construct()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Reference in New Issue
Block a user