README: MATLAB Code for Retinal Vessel Tortuosity Measurement

Overview
--------
This code package provides a modular pipeline for calculating retinal blood vessel tortuosity from skeletonized fundus images. The analysis distinguishes between artery and vein structures and computes tortuosity using both curve length (via Breadth-First Search) and straight-line distance (via Euclidean distance). The processed data supports vessel-specific biomarker research in healthy and diseased eyes.

File Descriptions
-----------------

1. RGB Tracing & Artery-Vein Separation
- Purpose: To separate artery and vein masks based on a color-coded RGB ground truth overlay.
- Key Steps:
  - Load segmented and RGB ground truth images.
  - Convert RGB image to HSV for hue-based classification.
  - Extract masks for arteries (red), veins (blue), and overlaps (green).
  - Combine segmented vessel map with classified colors to form artery and vein binary masks.
  - Apply morphological closing to maintain vessel connectivity.
- Output: Binary masks for arteries and veins.

2. Startpoint Detection (OD Intersection)
- Purpose: To identify initial vessel points near the optic disc to serve as vessel tracing startpoints.
- Key Steps:
  - Load skeletonized artery (or vein) image.
  - Load saved optic disc (OD) coordinates.
  - Calculate distances of all vessel pixels to OD center.
  - Extract points within a defined threshold distance from the OD border.
- Output: Coordinates of candidate startpoints saved in .mat format.

3. Endpoint Detection
- Purpose: To identify vessel endpoints outside the optic disc and link them to startpoints via BFS.
- Key Steps:
  - Load skeletonized vessel image and OD coordinates.
  - Detect endpoints using morphological analysis.
  - Filter out endpoints inside the OD.
  - Perform BFS to confirm connectivity between endpoints and provided startpoints.
  - Save valid start-endpoint pairs.
- Output: Startpoint and endpoint coordinates saved in Excel format.

4. Curve Path Calculation
- Purpose: To calculate the arc length (curve path) of vessels from start to endpoint.
- Key Steps:
  - Load skeletonized image and start-endpoint pairs.
  - Use BFS to trace the pixel-wise connected path.
  - Count pixels along each vessel path.
- Output: Excel file containing startpoint, endpoint, and curve path length for each vessel.

5. Straight Path Calculation (Euclidean Distance)
- Purpose: To calculate the straight-line distance between each vessel's startpoint and endpoint.
- Key Steps:
  - Load skeletonized image and start-endpoint pairs.
  - Apply Euclidean distance formula for each coordinate pair.
  - Sort and save results by x-coordinate for consistency.
- Output: Excel file with startpoint, endpoint, and straight-line distance.

Notes
-----
- All images must be preprocessed and skeletonized before applying these scripts.
- OD coordinates must be stored in a .mat file with fields: CenterX, CenterY, Radius.
- RGB ground truth images must follow a convention: Red = Artery, Blue = Vein, Green = Overlap.
- File input is handled via uigetfile for manual selection.

Suggested Execution Order
-------------------------
1. RGB Tracing & Artery-Vein Separation
2. Startpoint Detection
3. Endpoint Detection
4. Curve Path Calculation
5. Straight Path Calculation
