def _find_regions(self, node): if node.width == 1: return 0., 0. # resigned to split into 2 if node.width == 2: is_homogeneous = np.allclose(node.pixels[0], node.pixels[1], rtol=5e-2, atol=0) if is_homogeneous: idx = int(node.seq, 2) base = 2 ** len(node.seq) start = idx * node.width // base end = start + node.width else: stat, isSimilar = normal_test(node.pixels) if isSimilar: start = end = start + node.width return stat stat = 0. node.split() stat += self._find_regions(node.left_child) stat += self._find_regions(node.right_child) return stat
def homogeneity(self, node): # constant intensity if (node.pixels == node.pixels[:, 0]).all(): return 0., True if node.width == 2: sse = math.sqrt((node.pixels[:, 0] - node.pixels[:, 1]) ** 2) is_homogeneous = np.allclose(left, right, rtol=5e-2, atol=0) return sse.sum(), is_homogeneous # fit a low-order polynomial x = [i for i in range(node.width)] degree = 1 p, residuals, rank, _, _ = np.polyfit(x, node.pixels, degree, full=True) return residuals.sum(), normal_test(residuals)
def homogenity_test(root): # constant intensity if (root.pixels == root.pixels[0]).all(): return True if root.width == 2: return closeness_test(root.pixels[0], root.pixels[1]) # fit a low-order polynomial x = [i for i in range(root.width)] degree = 1 p, residuals, rank, _, _ = np.polyfit(x, root.pixels, degree, full=True) # the residuals are only some noise stat, hypothesis = normal_test(residuals) return hypothesis
def _grow_column_tree(self, node): if node.width == 1: return 0. if node.width == 2: is_homogeneous = np.allclose(node.pixels[0], node.pixels[1], rtol=5e-2, atol=0) if is_homogeneous: return elif normal_test(root): return root.split() self._grow_column_tree(self, root.left_child) self._grow_column_tree(self, root.right_child) return
def similarity_test(self, left_tree, right_tree): diff = left_tree.pixels - right_tree.pixels quality = np.linalg.norm(left_tree.pixels - right_tree.pixels) stat, similar = normal_test(left_tree.pixels - right_tree.pixels) return quality, stat, similar