Skip to content
Snippets Groups Projects
Commit fd4a04dc authored by Marc Feger's avatar Marc Feger
Browse files

Add A2b

parent 970f0f73
No related branches found
No related tags found
No related merge requests found
...@@ -154,8 +154,8 @@ class GUI(object): ...@@ -154,8 +154,8 @@ class GUI(object):
if __name__ == '__main__': if __name__ == '__main__':
# Todo: Add smooth filter # Todo: Add smooth filter
""" """
This program is for editing images with ORB keypoints. This program implements the CCV.
Those keypoints are then been grouped with k-means. Since the DFS is very costly please take images of: /images
Preparation: Preparation:
Make sure you have already installed all packages by running: Make sure you have already installed all packages by running:
......
...@@ -9,6 +9,15 @@ from KEYS import KEYS ...@@ -9,6 +9,15 @@ from KEYS import KEYS
class Graph(object): class Graph(object):
def __init__(self, row, col, g, bins, threshold) -> None: def __init__(self, row, col, g, bins, threshold) -> None:
"""
This constructs the graph for the CCV.
:param row: Amount of rows
:param col: Amount if columns
:param g: Graph for recursion
:param bins: Amount of bins
:param threshold: What is the threshold for plotting
"""
self.ROW = row self.ROW = row
self.COL = col self.COL = col
self.graph = g self.graph = g
...@@ -16,10 +25,28 @@ class Graph(object): ...@@ -16,10 +25,28 @@ class Graph(object):
self.bins = bins self.bins = bins
self.threshold = threshold self.threshold = threshold
def isSafe(self, i, j, visited, g): def isSafe(self, i, j, visited, g) -> bool:
"""
Check if the neighbor is in the matrix.
:param i: row coordinate
:param j: column coordinate
:param visited: matrix which holds the visited fileds
:param g: graph
:return: Is the neighbor in the matrix ?
"""
return 0 <= i < self.ROW and 0 <= j < self.COL and not visited[i][j] and g[i][j] return 0 <= i < self.ROW and 0 <= j < self.COL and not visited[i][j] and g[i][j]
def DFS(self, i, j, visited, g): def DFS(self, i, j, visited, g) -> None:
"""
Depth first search to get the connected components in the matrix.
:param i: row coordinate
:param j: column coordinate
:param visited: matrix which holds the visited fileds
:param g: graph
:return: None
"""
rowNbr = [-1, -1, -1, 0, 0, 1, 1, 1] rowNbr = [-1, -1, -1, 0, 0, 1, 1, 1]
colNbr = [-1, 0, 1, -1, 1, -1, 0, 1] colNbr = [-1, 0, 1, -1, 1, -1, 0, 1]
...@@ -29,7 +56,15 @@ class Graph(object): ...@@ -29,7 +56,15 @@ class Graph(object):
if self.isSafe(i + rowNbr[k], j + colNbr[k], visited, g): if self.isSafe(i + rowNbr[k], j + colNbr[k], visited, g):
self.DFS(i + rowNbr[k], j + colNbr[k], visited, g) self.DFS(i + rowNbr[k], j + colNbr[k], visited, g)
def label_connected_components(self, visited, label, count): def label_connected_components(self, visited, label, count) -> None:
"""
Label the connected components.
:param visited: matrix which holds the visited fileds
:param label: label of the color
:param count: label of the component
:return:
"""
for x in range(self.ROW): for x in range(self.ROW):
for y in range(self.COL): for y in range(self.COL):
if self.connected_components[x][y] is None and visited[x][y] is True: if self.connected_components[x][y] is None and visited[x][y] is True:
...@@ -38,7 +73,12 @@ class Graph(object): ...@@ -38,7 +73,12 @@ class Graph(object):
KEYS.COLOR.name: label KEYS.COLOR.name: label
} }
def detect_connected_components(self): def detect_connected_components(self) -> None:
"""
This method detect all connected components.
:return: None
"""
visited = [[False for _ in range(self.COL)] for _ in range(self.ROW)] visited = [[False for _ in range(self.COL)] for _ in range(self.ROW)]
count = 0 count = 0
for numb in range(1, self.bins + 1): for numb in range(1, self.bins + 1):
...@@ -49,10 +89,18 @@ class Graph(object): ...@@ -49,10 +89,18 @@ class Graph(object):
self.DFS(i, j, visited, g) self.DFS(i, j, visited, g)
self.label_connected_components(visited, numb, count) self.label_connected_components(visited, numb, count)
count += 1 count += 1
print(np.array(visited))
return count return count
def binary_matrix(self, number, g, r, c): def binary_matrix(self, number, g, r, c) -> np.array:
"""
Turn the matrix into a given binary matrix to detect connected components.
:param number: how many colors labels are in the matrix
:param g: the graph
:param r: row
:param c: column
:return: matrix
"""
adjacency_matrix = copy.deepcopy(g) adjacency_matrix = copy.deepcopy(g)
for i in range(r): for i in range(r):
for j in range(c): for j in range(c):
......
# Ex 2
Es wäre möglich die die coherenten und incoherenten Pixel über den Farbraum RGB zu berechnen.
Daraus könnten dann Histogramme erzeugt werden.
Jeder Bin repräsentiert dann ein Farbe und die Information "coherent" bzw. "incoherent".
Die modifizierten CCV sehen dann bspw. so aus:
RotCoherent: 10,
RotIncoherent: 1,
GrünCoherent: 1,
GrünIncoherent: 10,
BlueCoherent: 5,
BlueIncoherent: 5
Anschließend können solche Histogramme mit der "Earth Mover Distance" verglichen werden.
\ No newline at end of file
A2/images/astronauts/Eileen-Collins-2.jpg

46.4 KiB

A2/images/astronauts/Eileen-Collins.jpg

10.2 KiB | W: | H:

A2/images/astronauts/Eileen-Collins.jpg

46.4 KiB | W: | H:

A2/images/astronauts/Eileen-Collins.jpg
A2/images/astronauts/Eileen-Collins.jpg
A2/images/astronauts/Eileen-Collins.jpg
A2/images/astronauts/Eileen-Collins.jpg
  • 2-up
  • Swipe
  • Onion skin
A2/images/original.jpg

10.2 KiB | W: | H:

A2/images/original.jpg

46.4 KiB | W: | H:

A2/images/original.jpg
A2/images/original.jpg
A2/images/original.jpg
A2/images/original.jpg
  • 2-up
  • Swipe
  • Onion skin
A2/images/result.jpg

403 KiB | W: | H:

A2/images/result.jpg

354 KiB | W: | H:

A2/images/result.jpg
A2/images/result.jpg
A2/images/result.jpg
A2/images/result.jpg
  • 2-up
  • Swipe
  • Onion skin
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment