Skip to main content

Periorbital Segmentation and Distance Measurement Package

Table of Contents

Background

This package is designed to assist researchers and practitioners in the field of ophthalmology and facial analysis by providing tools to segment periorbital features and compute associated distance measurements. Whether you have a pretrained segmentation model or require a full pipeline from segmentation to distance measurement, this package offers a streamlined approach to analyze periorbital regions in facial images.

Installation

To install this package, you can clone the repository and install it locally, or install it directly via pip:

pip install git+https://github.com/monkeygobah/periorbital_package.git

Designed with Two Primary Users in Mind

  1. Users with an image of a face or eyes looking to compute periorbital distances and associated plots but without a segmentation model:

    • This user can leverage the package's built-in segmentation models to process their images, obtain segmentation masks, and compute the relevant periorbital distances and plots.
  2. Users who have developed their own segmentation model for the brow, iris, and sclera (+/- caruncle and lid) and want to use the segmentation masks to get arrays:

    • This user can input their custom segmentation masks into the package to compute periorbital measurements without the need for additional segmentation.

Instructions for User 1

  1. Prepare your image in a compatible format (e.g., JPEG, PNG).
  2. Use the run_periorbital_pipeline function with your image and specify full_face=True if your image contains a full face.
  3. The package will handle segmentation and return measurements and plots.

Instructions for User 2

  1. Prepare your segmentation masks for the brow, iris, sclera, and optional caruncle and lid. For every anatomical object, the mask for both the left and the right anatomical structure needs to be stored in a dict with the following keynames and correspinding pixel values to be compatible with the measurement pipeline

    sample_dict = {
        'sclera_orig': 2,
        'iris': 3,
        'brow': 1,
        'caruncle': 4,
        'lid': 5
    }
    

This means that if your segmentation model predicts all 5 structures, you will have 10 entries in the dict (5 for left, and 5 for right). To be compatible with the measurement pipeline, only sclera_orig, iris, and brow are required.

  1. Use the run_periorbital_pipeline function with your masks and set the model='custom' parameter.
  2. The package will use your provided masks to compute the relevant measurements.

What is Returned

When you run the periorbital pipeline, the following outputs are returned:

  • Pixel Measurements DataFrame: A DataFrame containing periorbital measurements in pixel values.
  • Millimeter Measurements DataFrame: A DataFrame containing periorbital measurements converted to millimeters.
  • Segmentation Masks: The segmentation masks for each anatomical structure.
  • Overlay Images: Images with segmentation masks overlaid on the original image.
  • Annotated Image: An image with annotated periorbital measurements.

Important Functions and Classes

  • run_periorbital_pipeline: The main function to run the entire pipeline, from segmentation to measurement extraction.

  • PupilIris, Sclera, Brows: Classes responsible for extracting specific anatomical features from the segmentation masks:

    • PupilIris: Extracts the centroid, diameter, and superior/inferior points of the iris.
    • Sclera: Extracts key points of the sclera and fits polynomials to the upper and lower borders of the sclera.
    • Brows: Extracts key points on the eyebrows relative to the medial canthus, lateral canthus, and iris center.
  • EyeFeatureExtractor: A class that coordinates the extraction of all relevant periorbital features from the segmentation masks. It utilizes PupilIris, Sclera, and Brows classes to gather and organize landmarks into a cohesive structure for measurement.

  • EyeMetrics:

    • Description: This class is responsible for calculating various periorbital distances based on the extracted landmarks.
    • Example Usage: You can instantiate this class with the landmarks and predictions_dict and call its run method to get a dictionary of measurements in pixel values.
    • Code Example:
      periorbital_calculator = EyeMetrics(landmarks, predictions_dict)
      measurements_pix = periorbital_calculator.run()
      
  • Plotter:

    • Description: This class is used to create annotated plots of the periorbital measurements directly on the resized images. It visualizes the extracted features and measurements.
    • Example Usage: After calculating the measurements, use this class to generate annotated images that overlay the results on the original image.
    • Code Example:
      periorbital_plotter = Plotter()
      image_annot = periorbital_plotter.create_plots(resize_img, predictions_dict, landmarks, img_name, measurements_pix)
      
  • Tester:

    • Description: This class is responsible for handling the segmentation process. It loads a specified model, applies it to the input image, and returns the segmentation masks and predictions.
    • Example Usage: You can instantiate this class with the model weights and image name, then call the test_single_image method to obtain the segmentation results.
    • Code Example:
      test_obj = Tester(model_weights=model, image_name=img_name)
      predictions_dict, resize_img, segmentation_mask_array, merged_image_array = test_obj.test_single_image(img)
      

Things to Keep in Mind

  1. Iris Segmentation Failure:

    • If the iris fails to be segmented in both eyes, the entire program will not work. The current implementation cannot handle cases where one eye is closed or absent.
  2. Brow Segmentation Failure:

    • If the brow is not segmented, the coordinates for the brow points will be set to 0. This will result in curious measurements in the final dataset of periorbital measurements. Future improvements should address this limitation.

Metadata

Release files for periorbital-package 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for periorbital-package 0.1.0
File Size Uploaded
periorbital_package-0.1.0.tar.gz 23.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for periorbital-package 0.1.0
File Interpreter ABI Platform
periorbital_package-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.8 kB

Release files / periorbital_package-0.1.0.tar.gz

Download URL periorbital_package-0.1.0.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9238e6278bd157a88f3b5cc729b2fabefc0651468214231762824b7a0b0769d4
BLAKE2b-256 checksum
How to use checksums
fd7563c9d7b06f0df541557c7de5eafa0bfde1386ba8d58f4c4005cac6f6bf6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.10

Release files / periorbital_package-0.1.0-py3-none-any.whl

Download URL periorbital_package-0.1.0-py3-none-any.whl
Size 23.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
580e863adf20b5a0082f16f75c84912d846e18d0569e31f6997b9d34fe85a663
BLAKE2b-256 checksum
How to use checksums
b47613c7f734287eca37985741523a6727231b3f99de9f1e4e41471e48e3d330
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.10

Release history Release notifications | RSS feed

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page