Skip to main content

scripts used for meidcal data manipulation

Project description

mdataio

What it is

It is a software package that abstracts the representation of the raw CT patient data (e.g. dicom, mhd, niffty etc.), and provides unified and clean approaches to manipulate the image together with the corresponding segmentation mask, including data loading, saving and visualization.

What it contains

How to install

$ pip install mdataio

Visualization

This module contains functions for interactive 2D/3D image visualization. It is useful for 1. overlaying mask onto image 2. comparing across a series of images 3. showing the difference of image pairs.

keyboard shortcuts

.: next slice
,: last slice
esc: quit
#to visualize prep study in /mnt/SSD_2/final_seg/leftheart_ct_ali_annotation2_cleaned_boundaries/0
#volshow* is to visualize volumes with shape NxHxW
from mdataio.visualization import volshow, volshowpair, volshowlist
img = np.load('0_img.npy')
seg = np.load('0_seg.npy')
volshow(img)
volshowpair(img, seg)
volshowlist([img, img])

#imshow is to visualize 2d images with shape HxW (gray scale image) or shape HxWx3 (RGB image)
from mdataio.visualization import imshow
imshow(img[0,:,:])
#another 2 useful functions are overlay_image and diff_image, which reflect the 2 most common procedures in debugging:
1. overlaying mask on top of image
2. comparing the difference of two images

from mdataio.visualization import overlay_image, diff_image
img_overlay = overlay_image(img[0,:,:], seg[0,:,:]) # can display the seg as mask (default) or contour (method='contour')
img_diff = diff_image(img[0,:,:], img[20,:,:])
imshow(img_overlay)
imshow(img_diff)
imshowlist([img_overlay, img_diff], title_list=['overylay', 'difference']) 
#all 3 functions support landmarks 

Data

  • Load raw image data, currently only supports dicom, niffty, mdh and save to dicoms so that it can be loaded into any dicom image viewer
from mdataio.data import PatientDicom, PatientNifty, PatientMhd
#dicom
pfile = PatientDicom("parent folder path of your dicom images")
#niffty
pfile = PatientNifty("path of your .nii file")
#mdh
#note that the file ending in .mhd is only the ASCII header information.
#the file ended in .raw/.mha contains the actual voxel data and should be put together with the .mhd file
pfile = PatientMhd("path of your .mdh file")

img, spacing = pd.get_data()

pfile.save_as_dicom("path where you want to save the converted dicoms")

Saver

A class that wrapps up the video saving functionality

form ss.saver import VideoSaver
vs = VideoSaver([[img[i,:,:],img[i,:,:]] for i in range(img.shape[0])])
vs.to_video('/home/xin/tmp/test.mp4')

Common

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

mdataio-0.1.4.tar.gz (13.8 kB view details)

Uploaded Source

File details

Details for the file mdataio-0.1.4.tar.gz.

File metadata

  • Download URL: mdataio-0.1.4.tar.gz
  • Upload date:
  • Size: 13.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.33.0 CPython/3.6.8

File hashes

Hashes for mdataio-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ff99833803e076cd38fe6b532de261f1f634f1e9dd8798e34e82d338f8527e4d
MD5 59df49f55db54bac35a128b36453e53c
BLAKE2b-256 ffa2a5493977d03e84062124c35ef40bc26a45d6b7fdc2ecaf4e5ce84ab004f4

See more details on using hashes here.

Supported by

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