Skip to main content

A comprehensive toolkit for medical image processing, including DICOM, NIfTI, and multi-format I/O utilities

Project description

MedImgKit

A comprehensive toolkit for medical image processing, providing utilities for DICOM, NIfTI, and other medical image formats with seamless multi-format I/O operations.

Features

  • DICOM Support: Read, anonymize, and manipulate DICOM files
  • NIfTI Support: Work with neuroimaging data in NIfTI format
  • Multi-format I/O: Unified interface for reading various image formats
  • Anonymization: DICOM anonymization following DICOM standards
  • Coordinate Conversion: Convert between pixel and patient coordinates
  • Multi-frame Assembly: Combine multiple DICOM files into multi-frame volumes

Installation

From PyPI

pip install medimgkit

From Source

pip install git+https://github.com/SonanceAI/medimgkit

Quick Start

DICOM Operations

import medimgkit as mik
import pydicom

# Read and normalize DICOM image
ds = pydicom.dcmread('path/to/dicom.dcm')
image_array = mik.load_image_normalized(ds)

# Anonymize DICOM
anonymized_ds = mik.anonymize_dicom(ds)

# Convert pixel coordinates to patient coordinates
patient_coords = mik.pixel_to_patient(ds, pixel_x=100, pixel_y=150)

# Use a specific native axis or anatomical plane when working with reformatted slices
coronal_coords = mik.pixel_to_patient(ds, pixel_x=80, pixel_y=20, slice_index=120, axis_index='coronal')

NIfTI Operations

import nibabel as nib
import medimgkit as mik
from medimgkit.nifti_utils import read_nifti_slice

# Load NIfTI file
nifti_data = nib.load('path/to/image.nii.gz')

# Get a specific slice
slice_image = mik.get_slice(nifti_data, slice_index=50, slice_axis=2)

# Read a slice by anatomical plane while preserving native slice orientation
slice_image, nifti_img = read_nifti_slice(
	'path/to/image.nii.gz',
	slice_index=50,
	plane='coronal',
)

# Convert world coordinates to slice index
slice_idx, axis = mik.line_to_slice_index(nifti_data, point1, point2)

Multi-format Reading

import medimgkit as mik

# Read any supported format
image_array = mik.read_array_normalized('path/to/image.dcm')
image_array = mik.read_array_normalized('path/to/image.nii.gz')
image_array = mik.read_array_normalized('path/to/image.png')

API Reference

DICOM Utils (medimgkit.dicom_utils)

Core Functions

  • load_image_normalized(dicom, index=None): Load and normalize DICOM pixel data
  • anonymize_dicom(ds, retain_codes=[], copy=False, token_mapper=None): Anonymize DICOM following standards
  • assemble_dicoms(files_path, return_as_IO=False): Combine multiple DICOMs into multi-frame
  • is_dicom(f): Check if file is a DICOM

Coordinate Conversion

  • pixel_to_patient(ds, pixel_x, pixel_y, slice_index=None, axis_index=None): Convert pixel to patient coordinates, optionally along a native axis or anatomical plane
  • get_image_position(ds, slice_index=None): Get image position in patient coordinates
  • get_pixel_spacing(ds, slice_index): Get pixel spacing information

Anatomical Analysis

  • determine_anatomical_plane_from_dicom(ds, slice_axis, alignment_threshold=0.95): Determine anatomical plane

NIfTI Utils (medimgkit.nifti_utils)

Slice Operations

  • get_slice(data, slice_index, slice_axis=None, plane=None): Extract a slice from a 3D/4D volume
  • read_nifti_slice(file_path, slice_index, plane=None): Read one standardized slice in (C, H, W) format while preserving native orientation
  • get_slice_from_line(data, world_point1, world_point2): Get slice defined by line
  • slice_location_to_slice_index(data, slice_location, slice_axis): Convert location to index

Coordinate Conversion

  • line_to_slice_index(data, world_point1=None, world_point2=None, coplanar_vector=None): Convert line to slice
  • axis_name_to_axis_index(data, axis_name): Convert axis name to index

Utilities

  • is_nifti_file(file_path): Check if file is NIfTI format

I/O Utils (medimgkit.io_utils)

Reading Functions

  • read_array_normalized(file_path, index=None, return_metainfo=False, use_magic=False): Universal image reader
  • read_image(file_path): Read standard image formats (PNG, JPEG)
  • read_nifti(file_path, mimetype=None, slice_index=None, plane=None): Read NIfTI files and optionally order slices by anatomical plane
  • read_video(file_path, index=None): Read video files

Supported Formats

  • DICOM: .dcm, .dicom (and files without extension)
  • NIfTI: .nii, .nii.gz
  • Images: .png, .jpg, .jpeg
  • Video: .mp4, .avi, .mov, .mkv
  • NumPy: .npy

Development

Running Tests

pytest

License

MIT License - see LICENSE file for details.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

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

medimgkit-0.17.0.tar.gz (54.6 kB view details)

Uploaded Source

Built Distribution

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

medimgkit-0.17.0-py3-none-any.whl (48.5 kB view details)

Uploaded Python 3

File details

Details for the file medimgkit-0.17.0.tar.gz.

File metadata

  • Download URL: medimgkit-0.17.0.tar.gz
  • Upload date:
  • Size: 54.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for medimgkit-0.17.0.tar.gz
Algorithm Hash digest
SHA256 908b721971725836c99bd88330750e87ec3e927db08757309ffd6b80765835d5
MD5 84107ba67dfcfb3ba9b52765947abeaa
BLAKE2b-256 7c3b2372e79a92ded6fdc9387616a3977399fde789d1720d76d2d2b40c0469c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for medimgkit-0.17.0.tar.gz:

Publisher: release_pypi.yaml on SonanceAI/medical-image-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file medimgkit-0.17.0-py3-none-any.whl.

File metadata

  • Download URL: medimgkit-0.17.0-py3-none-any.whl
  • Upload date:
  • Size: 48.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for medimgkit-0.17.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a890d1f588ae03a694a4b2230ae91f0f3f4ea7134e5060a6ae3889efa2ef38ed
MD5 4bf0cd4df07727980cbf76da36b1230e
BLAKE2b-256 13c714ce731e8c4464855967a15129d3d0f6bacafef67ec2f14af07dbdc95275

See more details on using hashes here.

Provenance

The following attestation bundles were made for medimgkit-0.17.0-py3-none-any.whl:

Publisher: release_pypi.yaml on SonanceAI/medical-image-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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