Skip to main content
. 2025 Sep 9;11(9):309. doi: 10.3390/jimaging11090309
Algorithm 4. Ellipse-based RBC Morphology classification and clustering
RBC_Ellipse_Fitting_Clustering(data_list, image_path)
  for each folder in data_list do
    define folder_path
    if folder_path exists then
      for each image_file in folder_path do
        load image          → image_input
        convert image to grayscale   → gray
        apply Otsu thresholding    → binary
        find contours from binary   → contours
        for each contour cnt in contours do
          if contour length ≥ 5 then
            fit ellipse to contour  → ellipse
            extract ellipse parameters: center, major_ax, minor_ax, angle
            compute major/minor axis lines and endpoints
            convert axis lengths to micrometers (µm)
            determine aspect ratio (AR)
            generate contour and ellipse masks
            compute overlap region (intersection) → inter_contours
            calculate area ratio (ER)
            annotate image with ellipse, axes, ratio, and area metrics
            classify cell morphology using classify_cell() function
            define output directories based on classification
            save annotated and raw images into their respective folders
            log extracted metrics for statistical analysis
            append classification results to CSV for later clustering review
      end for
    else: print warning (folder not found)
  end for export full metrics dataset and classification summary
  return ellipse_classification_results