Esempio n. 1
0
    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")
Esempio n. 2
0
    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")
Esempio n. 3
0
    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")
Esempio n. 4
0
    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")
Esempio n. 5
0
    def test_classification(self):
        bifurcations, crossings = l.classification(self.image.np_image, 2)
        result = np.genfromtxt(self._test_path + "boxes_bifurcations_test.csv",
                               delimiter=',')
        result2 = np.genfromtxt(self._test_path + "boxes_crossings_test.csv",
                                delimiter=',')

        assert_array_equal(result, bifurcations[0],
                           "Bifurcation points does not match")
        assert_array_equal(result2, crossings[0],
                           "Crossing points does not match")
Esempio n. 6
0
    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 post_landmarks_classification():
    data = {"success": False}

    if flask.request.method == "POST":
        json = flask.request.get_json(silent=True)
        if json is not None:  # pragma: no cover
            image = base64.b64decode(json["image"])
            image = Image.open(io.BytesIO(image)).convert('L')
            bifurcations_data, crossings_data = landmarks.classification(
                np.array(image), 20)
            data = {
                "bifurcations": bifurcations_data,
                "crossings": crossings_data
            }
    return flask.jsonify(data)
def classification(original_img: np.ndarray, manual_img: np.ndarray):
    manual = manual_img
    bifurcations, crossings = l.classification(manual, 0)
    features, sectioned_img, thr_img, predict_img = _loading_model(
        original_img, manual, None, 38)
    acc, rgb, network, original = _validating_model(features, sectioned_img,
                                                    original_img, predict_img,
                                                    38, 0)
    connected_components = cv2.connectedComponentsWithStats(
        sectioned_img.astype(np.uint8), 4, cv2.CV_32S)
    final_img, img_original = _homogenize(connected_components, network, rgb,
                                          original)
    post_img = _postprocessing(connected_components, thr_img, bifurcations,
                               img_original)
    return post_img