def test_loading_model(self): features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) result = np.genfromtxt(self._test_path + "loading_model_segments_test.csv", delimiter=',') result2 = np.genfromtxt(self._test_path + "loading_model_predictions_test.csv", delimiter=',') assert_array_equal(result, segments[:, 20], "Segmented skeleton image does not match") assert_array_equal(result2, predictions[:, 20], "Neural Network predictions does not match")
def test_normalize_indexes(self): features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) normal = vc._normalize_indexes(connected_components, 7) result = np.genfromtxt(self._test_path + "normalize_indexes_test.csv", delimiter=',') assert_array_equal(result, normal, "Width and color do not match")
def test_validating_model(self): features, segments, thr, predictions = vc._loading_model( self.original, self.manual.np_image, self.av, 38) acc, rgb, network, original = vc._validating_model( features, segments, self.original, predictions, 38, 1) self.assertEqual(76.18243243243244, acc, "Wrong validation, should return 81.1214953271028")
def test_box_labels(self): bifurcations, crossings = l.classification(self.manual.np_image, 0) features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) connected_vessels = vc._box_labels(bifurcations, connected_components) result = np.genfromtxt(self._test_path + "box_labels_test.csv", delimiter=',') assert_array_equal(result, connected_vessels, "Box labels does not match")
def test_homogenize(self): features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) acc, rgb, network, original = vc._validating_model(features, segments, self.original, predictions, 38, 1) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) final_img, rgb_img = vc._homogenize(connected_components, network, rgb, original) result = np.genfromtxt(self._test_path + "homogenize_test.csv", delimiter=',') assert_array_equal(result, rgb_img[:, 20], "Homogenized image does not match")
def test_postprocessing(self): bifurcations, crossings = l.classification(self.manual.np_image, 0) features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) acc, rgb, network, original = vc._validating_model(features, segments, self.original, predictions, 38, 1) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) final_img, rgb_img = vc._homogenize(connected_components, network, rgb, original) post_img = vc._postprocessing(connected_components, thr, bifurcations, rgb_img) result = np.genfromtxt(self._test_path + "postprocessing_test.csv", delimiter=',') assert_array_equal(result, post_img[:, 20], "Post image does not match")
def test_coloring(self): features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) bifurcations, crossings = l.classification(self.manual.np_image, 0) connected_vessels = vc._box_labels(bifurcations, connected_components) acc, rgb, network, original = vc._validating_model(features, segments, self.original, predictions, 38, 1) final_img, rgb_img = vc._homogenize(connected_components, network, rgb, original) rgb = vc._coloring(connected_components, connected_vessels[0], [0, 0, 255], rgb_img) assert_array_equal([0, 0, 255], rgb, "Coloring does not match")
def test_accuracy(self): bifurcations, crossings = l.classification(self.manual.np_image, 0) features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) acc, rgb, network, original = vc._validating_model(features, segments, self.original, predictions, 38, 1) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) final_img, rgb_img = vc._homogenize(connected_components, network, rgb, original) post_img = vc._postprocessing(connected_components, thr, bifurcations, rgb_img) acc = vc._accuracy(post_img, segments, self.av) assert_array_equal([0.8447412353923205, 0.7686274509803922, 0.9011627906976745], acc, "Accuracy does not match")
def test_average_width(self): features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) connected_components = cv2.connectedComponentsWithStats(segments.astype(np.uint8), 4, cv2.CV_32S) bifurcations, crossings = l.classification(self.manual.np_image, 0) connected_vessels = vc._box_labels(bifurcations, connected_components) acc, rgb, network, original = vc._validating_model(features, segments, self.original, predictions, 38, 1) final_img, rgb_img = vc._homogenize(connected_components, network, rgb, original) widths_colors = vc._average_width(connected_components, connected_vessels[0], thr, rgb_img) wc = [widths_colors[2]] wc.extend(widths_colors[3]) result = np.genfromtxt(self._test_path + "average_width_test.csv", delimiter=',') assert_array_equal(result, wc, "Width and color do not match")
def test_validating_model_without_av(self): features, segments, thr, predictions = vc._loading_model(self.original, self.manual.np_image, self.av, 38) acc, rgb, network, original = vc._validating_model(features, segments, self.original, predictions, 38, 0) self.assertEqual(-1, acc, "Wrong validation, should return -1")