Imagedata

Imagedata: A Python library to handle medical image data in NumPy array subclass Series - Published in JOSS (2022)

https://github.com/erling6232/imagedata

Science Score: 93.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in JOSS metadata
  • Academic publication links
    Links to: joss.theoj.org, zenodo.org
  • Committers with academic emails
  • Institutional organization owner
  • JOSS paper metadata
    Published in Journal of Open Source Software
Last synced: 6 months ago · JSON representation

Repository

Read/write medical image data

Basic Info
  • Host: GitHub
  • Owner: erling6232
  • License: mit
  • Language: Python
  • Default Branch: master
  • Size: 153 MB
Statistics
  • Stars: 11
  • Watchers: 4
  • Forks: 0
  • Open Issues: 5
  • Releases: 107
Created almost 8 years ago · Last pushed 6 months ago
Metadata Files
Readme Changelog Contributing License

README.rst

#########
imagedata
#########

|coverage|
|Docs Badge|

|zenodo| |joss|

|pypi| |pyversions| |downloads| |buildstatus|


Imagedata is a python library to read and write medical image data into numpy arrays.
Imagedata will handle multi-dimensional data.
In particular, imagedata will read and sort DICOM 3D and 4D series based on
defined tags.
Imagedata will handle geometry information between the formats.

The following formats are included:

* DICOM
* Nifti
* ITK (MetaIO)
* Matlab
* PostScript (input only)

Other formats can be added through a plugin architecture.

Install
-------------------

.. code-block::

    pip install imagedata

Documentation
----------------
See the Documentation_ page for info.

.. _Documentation: https://imagedata.readthedocs.io

Example code
-------------------

A simple example reading two time series from dirA and dirB, and writing their mean to dirMean:

.. code-block:: python

    from imagedata import Series
    a = Series('dirA', 'time')
    b = Series('dirB', 'time')
    assert a.shape == b.shape, "Shape of a and b differ"
    # Notice how a and b are treated as numpy arrays
    c = (a + b) / 2
    c.write('dirMean')

Sorting
-------

Sorting of DICOM slices is considered a major task. Imagedata will sort slices into volumes based on slice location.
Volumes may be sorted on a number of DICOM tags:

* 'time': Dynamic time series, sorted on acquisition time
* 'b': Diffusion weighted series, sorted on diffusion b value
* 'fa': Flip angle series, sorted on flip angle
* 'te': Sort on echo time TE

In addition, volumes can be sorted on user defined tags.

Non-DICOM formats usually don't specify the labelling of the 4D data.
In this case, you can specify the sorting manually.

Viewing
-------

A simple viewer. Scroll through the image stack, step through the tags of a 4D dataset.
These operations are possible:

* Read-out voxel value: Move mouse over.
* Window/level adjustment: Move mouse with left key pressed.
* Scroll through slices of an image stack: Mouse scroll wheel, or up/down array keys.
* Step through tags (time, b-values, etc.): Left/right array keys.
* Move through series when many series are displayed: PageUp/PageDown keys.

.. code-block:: python

      # View a Series instance
      a.show()

      # View both a and b Series
      a.show(b)

      # View several Series
      a.show([b, c, d])

Converting data from DICOM and back
-----------------------------------

In many situations you need to process patient data using a tool that do not accept DICOM data.
In order to maintain the coupling to patient data, you may convert your data to e.g. Nifti and back.

Example using the command line utility image_data:

.. code-block:: bash

  image_data --of nifti niftiDir dicomDir
  # Now do your processing on Nifti data in niftiDir/, leaving the result in niftiResult/.

  # Convert the niftiResult back to DICOM, using dicomDir as a template
  image_data --of dicom --template dicomDir dicomResult niftiResult
  # The resulting dicomResult will be a new DICOM series that could be added to a PACS

  # Set series number and series description before transmitting to PACS using DICOM transport
  image_data --sernum 1004 --serdes 'Processed data' \
    dicom://server:104/AETITLE dicomResult

The same example using python code:

.. code-block:: python

  from imagedata import Series
  a = Series('dicomDir')
  a.write('niftiDir', formats=['nifti'])   # Explicitly select nifti as output format

  # Now do your processing on Nifti data in niftiDir/, leaving the result in niftiResult/.

  b = Series('niftiResult', template=a)    # Or template='dicomDir'
  b.write('dicomResult')   # Here, DICOM is default output format

  # Set series number and series description before transmitting to PACS using DICOM transport
  b.seriesNumber = 1004
  b.seriesDescription = 'Processed data'
  b.write(' dicom://server:104/AETITLE')

Series fields
-------------

The Series object is inherited from numpy.ndarray, adding a number of useful fields:

Axes
  a.axes defines the unit and size of each dimension of the matrix
  
Addressing
  4D: a[tags, slices, rows, columns]
  
  3D: a[slices, rows, columns]
  
  2D: a[rows, columns]
  
  RGB: a[..., rgb]
  
patientID, patientName, patientBirthDate
  Identifies patient

accessionNumber
  Identifies study

seriesNumber, seriesDescription, imageType
  Labels DICOM data

slices
  Returns number of slices
  
spacing
  Returns spacing for each dimension. Units depend on dimension, and could e.g. be mm or sec.
  
tags
  Returns tags for each slice
  
timeline
  Returns time steps for when a time series
  
transformationMatrix
  The transformation matrix to calculate physical coordinates from pixel coordinates

Series instancing
-----------------

From image data file(s):

.. code-block:: python

  a = Series('in_dir')
  
From a list of directories:

.. code-block:: python

  a = Series(['1', '2', '3'])

From a numpy array:

.. code-block:: python

  e = np.eye(128)
  a = Series(e)

Series methods
--------------

write()
  Write the image data as a Matlab file to out_dir:
  
.. code-block:: python

    a.write('out_dir', formats=['mat'])

slicing
  The image data array can be sliced like numpy.ndarray. The axes will be adjusted accordingly.
  This will give a 3D **b** image when **a** is 4D.

.. code-block:: python

      b = a[0, ...]
  
Archives
--------

The Series object can access image data in a number of **archives**. Some archives are:

Filesystem
  Access files in directories on the local file system.

.. code-block:: python

    a = Series('in_dir')
  
Zip
  Access files inside zip files.
  

.. code-block:: python

  # Read all files inside file.zip:
  a = Series('file.zip')

  # Read named directory inside file.zip:
  b = Series('file.zip?dir_a')
  
  # Write the image data to DICOM files inside newfile.zip:
  b.write('newfile.zip', formats=['dicom'])

Transports
----------

file
  Access local files (default):
  
.. code-block:: python

    a = Series('file:in_dir')
  
dicom
  Access files using DICOM Storage protocols. Currently, writing (implies sending) DICOM images only:
  
.. code-block:: python

    a.write('dicom://server:104/AETITLE')

Command line usage
------------------

The command line program *image_data* can be used to convert between various image data formats:

.. code-block:: bash

  image_data --order time out_dir in_dirs

.. |Docs Badge| image:: https://readthedocs.org/projects/imagedata/badge/
    :alt: Documentation Status
    :target: https://imagedata.readthedocs.io

.. |buildstatus| image:: https://github.com/erling6232/imagedata/actions/workflows/python-app.yml/badge.svg?branch=master
    :target: https://github.com/erling6232/imagedata/actions/workflows/python-app.yml
    :alt: Build Status

.. _buildstatus: https://github.com/erling6232/imagedata/actions/workflows/python-app.yml

.. |coverage| image:: https://codecov.io/gh/erling6232/imagedata/branch/master/graph/badge.svg?token=GT9KZV2TWT
    :alt: Coverage
    :target: https://codecov.io/gh/erling6232/imagedata

.. |pypi| image:: https://img.shields.io/pypi/v/imagedata.svg
    :target: https://pypi.python.org/pypi/imagedata
    :alt: PyPI Version

.. |joss| image:: https://joss.theoj.org/papers/6a1bc6ea5a200a7a9204cfafcd6e49b8/status.svg
    :target: https://joss.theoj.org/papers/6a1bc6ea5a200a7a9204cfafcd6e49b8
    :alt: JOSS Status

.. |zenodo| image:: https://zenodo.org/badge/123263810.svg
   :target: https://zenodo.org/badge/latestdoi/123263810
   :alt: Zenodo DOI

.. |pyversions| image:: https://img.shields.io/pypi/pyversions/imagedata.svg
   :target: https://pypi.python.org/pypi/imagedata/
   :alt: Supported Python Versions

.. |downloads| image:: https://img.shields.io/pypi/dm/imagedata?color=blue
   :target: https://pypistats.org/packages/imagedata
   :alt: PyPI Downloads

Owner

  • Name: Erling Andersen
  • Login: erling6232
  • Kind: user
  • Location: Bergen, Norway
  • Company: Haukeland University Hospital

MR Physics

JOSS Publication

Imagedata: A Python library to handle medical image data in NumPy array subclass Series
Published
May 25, 2022
Volume 7, Issue 73, Page 4133
Authors
Erling Andersen ORCID
Haukeland University Hospital, Dept. of Clinical Engineering, N-5021 Bergen, Norway, Mohn Medical Imaging and Visualization Centre, Haukeland University Hospital, Dept. of Radiology, N-5021 Bergen, Norway
Editor
Gabriela Alessio Robles ORCID
Tags
dicom python medical imaging pydicom pynetdicom itk nifti

GitHub Events

Total
  • Create event: 22
  • Issues event: 13
  • Release event: 16
  • Watch event: 1
  • Delete event: 8
  • Issue comment event: 11
  • Push event: 56
  • Pull request event: 20
Last Year
  • Create event: 22
  • Issues event: 13
  • Release event: 16
  • Watch event: 1
  • Delete event: 8
  • Issue comment event: 11
  • Push event: 56
  • Pull request event: 20

Committers

Last synced: 7 months ago

All Time
  • Total Commits: 1,897
  • Total Committers: 4
  • Avg Commits per committer: 474.25
  • Development Distribution Score (DDS): 0.008
Past Year
  • Commits: 228
  • Committers: 1
  • Avg Commits per committer: 228.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
Erling Andersen E****n@H****O 1,882
snyk-bot s****t@s****o 10
stacksharebot t****m@s****o 4
Andersen e****n@i****t 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 6 months ago

All Time
  • Total issues: 56
  • Total pull requests: 86
  • Average time to close issues: 3 months
  • Average time to close pull requests: 1 day
  • Total issue authors: 5
  • Total pull request authors: 2
  • Average comments per issue: 0.57
  • Average comments per pull request: 0.26
  • Merged pull requests: 83
  • Bot issues: 0
  • Bot pull requests: 2
Past Year
  • Issues: 8
  • Pull requests: 25
  • Average time to close issues: about 2 months
  • Average time to close pull requests: 3 minutes
  • Issue authors: 2
  • Pull request authors: 1
  • Average comments per issue: 0.5
  • Average comments per pull request: 0.36
  • Merged pull requests: 25
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • erling6232 (41)
  • ehodneland (9)
  • hsang (1)
  • HaukeBartsch (1)
  • mwegrzyn (1)
Pull Request Authors
  • erling6232 (108)
  • stack-file[bot] (1)
Top Labels
Issue Labels
enhancement (12) bug (8)
Pull Request Labels
bug (2) enhancement (2)

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 1,567 last-month
  • Total dependent packages: 4
  • Total dependent repositories: 2
  • Total versions: 148
  • Total maintainers: 1
pypi.org: imagedata

Read/write medical image data

  • Homepage: https://github.com/erling6232/imagedata
  • Documentation: https://imagedata.readthedocs.io
  • License: MIT License Copyright (c) 2013-2024 Erling Andersen, Haukeland University Hospital, Bergen, Norway Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  • Latest release: 3.8.7
    published 6 months ago
  • Versions: 148
  • Dependent Packages: 4
  • Dependent Repositories: 2
  • Downloads: 1,567 Last month
Rankings
Dependent packages count: 7.4%
Downloads: 8.6%
Dependent repos count: 11.8%
Average: 15.1%
Stargazers count: 17.7%
Forks count: 30.0%
Maintainers (1)
Last synced: 6 months ago

Dependencies

.github/workflows/ci.yml actions
  • actions/checkout v3 composite
  • actions/setup-python v4 composite
  • actions/upload-artifact v3 composite
  • codecov/codecov-action v3 composite