def test_principal_boxes(self): self.image.reshape_for_landmarks(2) self.image.threshold_image() threshold = self.image.get_uint_image() self.image.skeletonization() skeleton = self.image.get_uint_image() self.image.bin_to_bgr() skeleton_rgb = self.image.get_uint_image() landmarks, segments = l.potential_landmarks(skeleton, 3) widths = l.vessel_width(threshold, landmarks) vessels = l.finding_landmark_vessels(widths, landmarks, skeleton, skeleton_rgb) marked_skeleton, final_landmarks = l.vessel_number( vessels, landmarks, skeleton_rgb) bifurcations, crossings = l.principal_boxes(marked_skeleton, final_landmarks, 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")
def test_vessel_number(self): self.image.reshape_for_landmarks(2) self.image.threshold_image() threshold = self.image.get_uint_image() self.image.skeletonization() skeleton = self.image.get_uint_image() self.image.bin_to_bgr() skeleton_rgb = self.image.get_uint_image() landmarks, segments = l.potential_landmarks(skeleton, 3) widths = l.vessel_width(threshold, landmarks) vessels = l.finding_landmark_vessels(widths, landmarks, skeleton, skeleton_rgb) marked_skeleton, final_landmarks = l.vessel_number( vessels, landmarks, skeleton_rgb) result_skeleton = np.genfromtxt(self._test_path + "vessel_number_skeleton_test.csv", delimiter=',') result_landmarks = np.genfromtxt(self._test_path + "vessel_number_filter_test.csv", delimiter=',') assert_array_equal(result_skeleton, marked_skeleton[20, :], "Vessel skeleton does not match") assert_array_equal(result_landmarks, final_landmarks, "Vessel final landmarks does not match")
def _feature_vectors(): directory = _base_directory_training + "original/" features = [] for filename in sorted(glob.glob(os.path.join(directory, '*.tif'))): name = os.path.basename(filename) name = name.split(".")[0] original = cv2.imread(filename, 1) gray = cv2.imread(filename, 0) (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray) lab = cv2.cvtColor(original, cv2.COLOR_BGR2LAB) L, A, B = cv2.split(lab) manual = retina.Retina( None, _base_directory_training + "manual/" + name + ".png") manual.threshold_image() thr_img = manual.get_uint_image() cv2.circle(thr_img, maxLoc, 60, 0, -1) manual.skeletonization() skeleton_img = manual.get_uint_image() cv2.circle(skeleton_img, maxLoc, 60, 0, -1) landmarks, segmented_skeleton_img = l.potential_landmarks( skeleton_img, 3) av = cv2.imread(_base_directory_training + "av/" + name + ".png", 1) widths = _vessel_widths(segmented_skeleton_img, thr_img) data = _preparing_data(widths, 6, original, av, L, gray) features.extend(data) h5f = h5py.File(_base_directory_model + 'vector_features_interpolation.h5', 'w') h5f.create_dataset('training', data=features) return features
def test_vessel_width(self): self.manual.threshold_image() threshold = self.manual.get_uint_image() self.manual.skeletonization() skeleton = self.manual.get_uint_image() landmarks, segmented = l.potential_landmarks(skeleton, 3) widths = vc._vessel_widths(segmented, threshold) result = np.genfromtxt(self._test_path + "vessels_width_test.csv", delimiter=',') assert_array_equal(result, widths[0:10], "Vessel widths does not match")
def test_potential_landmarks(self): self.image.reshape_for_landmarks(2) self.image.threshold_image() self.image.skeletonization() skeleton = self.image.get_uint_image() landmarks, segments = l.potential_landmarks(skeleton, 3) result = np.genfromtxt(self._test_path + "potential_landmarks_test.csv", delimiter=',') assert_array_equal(result, landmarks, "landmark points does not match")
def test_vessel_width(self): self.image.reshape_for_landmarks(2) self.image.threshold_image() threshold = self.image.get_uint_image() self.image.skeletonization() skeleton = self.image.get_uint_image() landmarks, segments = l.potential_landmarks(skeleton, 3) widths = l.vessel_width(threshold, landmarks) result = np.genfromtxt(self._test_path + "vessel_widths_test.csv", delimiter=',') assert_array_equal(result, widths, "Vessel widths does not match")
def test_preparing_data_without_av(self): self.manual.threshold_image() threshold = self.manual.get_uint_image() self.manual.skeletonization() skeleton = self.manual.get_uint_image() gray = cv2.cvtColor(self.original, cv2.COLOR_BGR2GRAY) lab = cv2.cvtColor(self.original, cv2.COLOR_BGR2LAB) L, A, B = cv2.split(lab) landmarks, segmented = l.potential_landmarks(skeleton, 3) widths = vc._vessel_widths(segmented, threshold) features = vc._preparing_data(widths, 6, self.original, None, L, gray) result = np.genfromtxt(self._test_path + "preparing_data_without_av_test.csv", delimiter=',') assert_array_equal(result, features[0:10], "Data does not match")
def test_finding_landmark_vessels(self): self.image.reshape_for_landmarks(2) self.image.threshold_image() threshold = self.image.get_uint_image() self.image.skeletonization() skeleton = self.image.get_uint_image() self.image.bin_to_bgr() skeleton_rgb = self.image.get_uint_image() landmarks, segments = l.potential_landmarks(skeleton, 3) widths = l.vessel_width(threshold, landmarks) vessels = l.finding_landmark_vessels(widths, landmarks, skeleton, skeleton_rgb) result = np.genfromtxt(self._test_path + "finding_landmark_vessels_test.csv", delimiter=',') assert_array_equal(result, vessels[0], "Landmark vessels does not match")
def _loading_model(original: np.ndarray, threshold: np.ndarray, av: np.ndarray, size: int): # Load model of the neuronal network json_file = open(_base_directory_model + 'modelVA.json', "r") loaded_model_json = json_file.read() json_file.close() loaded_model = model_from_json(loaded_model_json) # Load weights loaded_model.load_weights(_base_directory_model + 'modelVA.h5') gray = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) (minVal, maxVal, minLoc, maxLoc) = cv2.minMaxLoc(gray) lab = cv2.cvtColor(original, cv2.COLOR_BGR2LAB) L, A, B = cv2.split(lab) manual = retina.Retina(threshold, None) manual.threshold_image() thr_img = manual.get_uint_image() cv2.circle(thr_img, maxLoc, 60, 0, -1) manual.skeletonization() skeleton_img = manual.get_uint_image() cv2.circle(skeleton_img, maxLoc, 60, 0, -1) landmarks, segmented_skeleton_img = l.potential_landmarks(skeleton_img, 3) widths = _vessel_widths(segmented_skeleton_img, thr_img) data = _preparing_data(widths, 6, original, av, L, gray) features = np.array(data) predict_img = np.full( (segmented_skeleton_img.shape[0], segmented_skeleton_img.shape[1]), 3, dtype=float) for row in range(0, features.shape[0]): prediction = loaded_model.predict(np.divide( features[row:row + 1, 2:size], 255), batch_size=1) predict_img[features[row, 0], features[row, 1]] = prediction return features, segmented_skeleton_img, thr_img, predict_img