diff --git a/A2/GUI.py b/A2/GUI.py index cfb9b2fa53a4308942fe74bf262b4417398cf204..fa29348d546c1d287a0106fb4fa449faa550b957 100644 --- a/A2/GUI.py +++ b/A2/GUI.py @@ -154,8 +154,8 @@ class GUI(object): if __name__ == '__main__': # Todo: Add smooth filter """ - This program is for editing images with ORB keypoints. - Those keypoints are then been grouped with k-means. + This program implements the CCV. + Since the DFS is very costly please take images of: /images Preparation: Make sure you have already installed all packages by running: diff --git a/A2/Graph.py b/A2/Graph.py index 49105bb2d9e7c5411f99dd09098eb3c5a8541328..0747d5b20be61bed0f7de753b278d7e5cf1adf56 100644 --- a/A2/Graph.py +++ b/A2/Graph.py @@ -9,6 +9,15 @@ from KEYS import KEYS class Graph(object): 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.COL = col self.graph = g @@ -16,10 +25,28 @@ class Graph(object): self.bins = bins 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] - 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] colNbr = [-1, 0, 1, -1, 1, -1, 0, 1] @@ -29,7 +56,15 @@ class Graph(object): if self.isSafe(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 y in range(self.COL): if self.connected_components[x][y] is None and visited[x][y] is True: @@ -38,7 +73,12 @@ class Graph(object): 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)] count = 0 for numb in range(1, self.bins + 1): @@ -49,10 +89,18 @@ class Graph(object): self.DFS(i, j, visited, g) self.label_connected_components(visited, numb, count) count += 1 - print(np.array(visited)) 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) for i in range(r): for j in range(c): diff --git a/A2/README.md b/A2/README.md new file mode 100644 index 0000000000000000000000000000000000000000..4834ac7e0f4a8fa8cdcccde88aa71b0ef6846842 --- /dev/null +++ b/A2/README.md @@ -0,0 +1,17 @@ +# 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 diff --git a/A2/images/astronauts/Eileen-Collins-2.jpg b/A2/images/astronauts/Eileen-Collins-2.jpg deleted file mode 100644 index 29ce31cd0828954be05948d9513ab8ad140afa96..0000000000000000000000000000000000000000 Binary files a/A2/images/astronauts/Eileen-Collins-2.jpg and /dev/null differ diff --git a/A2/images/astronauts/Eileen-Collins.jpg b/A2/images/astronauts/Eileen-Collins.jpg index e42f76544783e7746f797f56bacc1ae86028972e..29ce31cd0828954be05948d9513ab8ad140afa96 100644 Binary files a/A2/images/astronauts/Eileen-Collins.jpg and b/A2/images/astronauts/Eileen-Collins.jpg differ diff --git a/A2/images/original.jpg b/A2/images/original.jpg index e42f76544783e7746f797f56bacc1ae86028972e..29ce31cd0828954be05948d9513ab8ad140afa96 100644 Binary files a/A2/images/original.jpg and b/A2/images/original.jpg differ diff --git a/A2/images/result.jpg b/A2/images/result.jpg index cb1699a84f83a89bbe0444baebbd18e9ca36e6b5..09d2010b644c2838e84741b1cfa4afb4ff6e5203 100644 Binary files a/A2/images/result.jpg and b/A2/images/result.jpg differ