Skip to main content

A simple package for preprocessing ultrasound imaging data for machine learning

Project description

ultraml: a simple package for ultrasound ML data preprocessing

Example Usage

Before After Extracted Background
aorta-0 extracted_aorta-0 pocus_atlas-aorta-1-background

Installation

  1. Pip
pip install ultraml
  1. Local Clone
git clone https://github.com/stan-hua/ultraml.git
cd ultraml
pip install -e .

Example Usages

1. (File-Level) Pre-process ultrasound video to individual image frames

from ultraml import convert_video_to_frames
video_path = "path/to/video.mp4"
video_save_dir = "path/to/save/frames"
background_save_path = "path/to/save/frames/background.png"
save_paths, background_save_path = convert_video_to_frames(
    path=video_path,
    save_dir=video_save_dir,
    prefix_fname="frame_",
    background_save_path=background_save_path,
    overwrite=True
)
print(f"{len(save_paths)} Video frames saved at: \n\t{'\n\t'.join(save_paths)}")
print(f"Background Saved = {background_save_path is not None}")

2. (File-Level) Pre-process ultrasound beamform to individual image frames

# If handling DICOMs, please install pydicom with `pip install pydicom`
from ultraml import convert_dicom_to_frames
dicom_path = "path/to/dicom.dcm"
dicom_save_dir = "path/to/save/dicom_frames"
background_save_path = "path/to/save/frames/background.png"
save_paths, background_save_path = convert_dicom_to_frames(
    path=dicom_path,
    save_dir=dicom_save_dir,
    prefix_fname="dicom_frame_",
    grayscale=True,
    uniform_num_samples=10,
    background_save_path=background_save_path,
    overwrite=True
)
print(f"{len(save_paths)} DICOM frames saved at: \n\t{'\n\t'.join(save_paths)}")
print(f"Background Saved = {background_save_path is not None}")

3. (Array-Level) Extract beamform from a video (list of images)

from ultraml import extract_ultrasound_video_foreground, convert_img_to_uint8
video_frames_arr = ...        # list of numpy image arrays
ultrasound_foreground, static_mask = extract_ultrasound_video_foreground(
    img_sequence=video_frames_arr,
    apply_filter=True,
    crop=True
)

# Function returns: (i) the video frames with extracted foreground and
#                   (ii) a mask for the static parts of the image
# To get the background, mask out the static parts of any image frame
first_img = video_frames_arr[0]
background_img = convert_img_to_uint8(first_img)
background_img[~static_mask] = 0

4. (Array-Level) Extract ultrasound from a single image

from ultraml import extract_ultrasound_image_foreground
img_arr = ...               # single numpy image array
ultrasound_foreground, static_mask = extract_ultrasound_image_foreground(
    img=img_arr,
    apply_filter=True,
    crop=True
)

# Function returns: (i) the image frame with extracted foreground and
#                   (ii) a mask for the estimated background of the image
# To get the background, mask out the static parts of any image frame
background_img = convert_img_to_uint8(img_arr)
background_img[~static_mask] = 0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ultraml-0.1.1.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ultraml-0.1.1-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file ultraml-0.1.1.tar.gz.

File metadata

  • Download URL: ultraml-0.1.1.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.19

File hashes

Hashes for ultraml-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9adf67e314c9645d86fbe30be297f4d2f666619feeb6595149433e7869632ce8
MD5 9e08ffd8eaec1e8d71066630fd24c3b0
BLAKE2b-256 a9b62d650bc1a287bd0a4326a675bd9232a9d765c0f136bb2f7e4f88e7574d4a

See more details on using hashes here.

File details

Details for the file ultraml-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ultraml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.9.19

File hashes

Hashes for ultraml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9d76d7aaaee5c2e59be21b69c3aa580552ee4c56bcd0e46a1945b479f608e437
MD5 4e42cc5f719f844484e2d3be5f61543f
BLAKE2b-256 8ac3f8fe3eec79322d0365625776c1294b849c0796a80dffca887020fd60c8f6

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page