MedPy


NameMedPy JSON
Version 0.5.1 PyPI version JSON
download
home_pagehttps://github.com/loli/medpy
SummaryMedical image processing in Python
upload_time2024-04-03 15:53:56
maintainerNone
docs_urlNone
authorOskar Maier
requires_python<4,>=3.5
licenseLICENSE.txt
keywords medical image processing dicom itk insight tool kit mri ct us graph cut max-flow min-cut
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MedPy

[GitHub](https://github.com/loli/medpy/) | [Documentation](http://loli.github.io/medpy/) | [Tutorials](http://loli.github.io/medpy/) | [Issue tracker](https://github.com/loli/medpy/issues)

**MedPy** is a library and script collection for medical image processing in Python, providing basic functionalities for **reading**, **writing** and **manipulating** large images of **arbitrary dimensionality**.
Its main contributions are n-dimensional versions of popular **image filters**, a collection of **image feature extractors**, ready to be used with [scikit-learn](http://scikit-learn.org), and an exhaustive n-dimensional **graph-cut** package.

* [Installation](#installation)
* [Getting started with the library](#getting-started-with-the-library)
* [Getting started with the scripts](#getting-started-with-the-scripts)
* [Support of medical image formats](#support-of-medical-image-formats)
* [Requirements](#requirements)
* [License](#license)

## Installation

```bash
sudo apt-get install libboost-python-dev build-essential
pip3 install medpy
```

**MedPy** requires **Python 3** and officially supports Ubuntu as well as other Debian derivatives.
For installation instructions on other operating systems see the [documentation](http://loli.github.io/medpy/).
While the library itself is written purely in Python, the **graph-cut** extension comes in C++ and has [it's own requirements](http://loli.github.io/medpy/installation/graphcutsupport.html).

## Getting started with the library

If you already have a medical image at hand in [one of the supported formats](http://loli.github.io/medpy/information/imageformats.html), you can use it for this introduction. If not, navigate to http://www.nitrc.org/projects/inia19, click on the *Download Now* button, unpack and look for the *inia19-t1.nii* file. Open it in your favorite medical image viewer (I personally fancy [itksnap](http://www.itksnap.org)) and beware: the INIA19 primate brain atlas.

Load the image

```python
from medpy.io import load
image_data, image_header = load('/path/to/image.xxx')
```

The data is stored in a numpy ndarray, the header is an object containing additional metadata, such as the voxel-spacing. Now lets take a look at some of the image metadata

```python
image_data.shape
```

`(168, 206, 128)`

```python
image_data.dtype
```

`dtype(float32)`

And the header gives us

```python
image_header.get_voxel_spacing()
```

`(0.5, 0.5, 0.5)`

```python
image_header.get_offset()
```

`(0.0, 0.0, 0.0)`

Now lets apply one of the **MedPy** filter, more exactly the [Otsu thresholding](https://en.wikipedia.org/wiki/Otsu%27s_method), which can be used for automatic background removal

```python
from medpy.filter import otsu
threshold = otsu(image_data)
output_data = image_data > threshold
```

And save the binary image, marking the foreground

```python
from medpy.io import save
save(output_data, '/path/to/otsu.xxx', image_header)
```

After taking a look at it, you might want to dive deeper with the tutorials found in the [documentation](http://loli.github.io/medpy/information/commandline_tools_listing.html).

## Getting started with the scripts

**MedPy** comes with a range of read-to-use commandline scripts, which are all prefixed by `medpy_`.
To try these examples, first get an image as described in the previous section. Now call

```bash
medpy_info.py /path/to/image.xxx
```

will give you some details about the image. With

```bash
medpy_diff.py /path/to/image1.xxx /path/to/image2.xxx
```

you can compare two image. And

```bash
medpy_anisotropic_diffusion.py /path/to/image.xxx /path/to/output.xxx
```

lets you apply an edge preserving anisotropic diffusion filter. For a list of all scripts, see the [documentation](http://loli.github.io/medpy/).

## Support of medical image formats

MedPy relies on SimpleITK, which enables the power of ITK for image loading and saving.
The supported image file formats should include at least the following. Note that not all might be supported by your machine.

**Medical formats:**

* ITK MetaImage (.mha/.raw, .mhd)
* Neuroimaging Informatics Technology Initiative (NIfTI) (.nia, .nii, .nii.gz, .hdr, .img, .img.gz)
* Analyze (plain, SPM99, SPM2) (.hdr/.img, .img.gz)
* Digital Imaging and Communications in Medicine (DICOM) (.dcm, .dicom)
* Digital Imaging and Communications in Medicine (DICOM) series (<directory>/)
* Nearly Raw Raster Data (Nrrd) (.nrrd, .nhdr)
* Medical Imaging NetCDF (MINC) (.mnc, .MNC)
* Guys Image Processing Lab (GIPL) (.gipl, .gipl.gz)

**Microscopy formats:**

* Medical Research Council (MRC) (.mrc, .rec)
* Bio-Rad (.pic, .PIC)
* LSM (Zeiss) microscopy images (.tif, .TIF, .tiff, .TIFF, .lsm, .LSM)
* Stimulate / Signal Data (SDT) (.sdt)

**Visualization formats:**

* VTK images (.vtk)

**Other formats:**

* Portable Network Graphics (PNG) (.png, .PNG)
* Joint Photographic Experts Group (JPEG) (.jpg, .JPG, .jpeg, .JPEG)
* Tagged Image File Format (TIFF) (.tif, .TIF, .tiff, .TIFF)
* Windows bitmap (.bmp, .BMP)
* Hierarchical Data Format (HDF5) (.h5 , .hdf5 , .he5)
* MSX-DOS Screen-x (.ge4, .ge5)

## Requirements

MedPy comes with a number of dependencies and optional functionality that can require you to install additional packages.

### Main dependencies

* [scipy](http://www.scipy.org)
* [numpy](http://www.numpy.org)
* [SimpleITK](https://simpleitk.readthedocs.io)

### Optional functionalities

* compilation with `max-flow/min-cut` (enables the GraphCut functionalities)

## License

MedPy is distributed under the GNU General Public License, a version of which can be found in the LICENSE.txt file.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/loli/medpy",
    "name": "MedPy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4,>=3.5",
    "maintainer_email": null,
    "keywords": "medical image processing dicom itk insight tool kit MRI CT US graph cut max-flow min-cut",
    "author": "Oskar Maier",
    "author_email": "oskar.maier@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/79/8d/f7366f8f76518e2e7683b945bac4191c702deafb9db40ec6c1ca4fcdbf8c/MedPy-0.5.1.tar.gz",
    "platform": null,
    "description": "# MedPy\n\n[GitHub](https://github.com/loli/medpy/) | [Documentation](http://loli.github.io/medpy/) | [Tutorials](http://loli.github.io/medpy/) | [Issue tracker](https://github.com/loli/medpy/issues)\n\n**MedPy** is a library and script collection for medical image processing in Python, providing basic functionalities for **reading**, **writing** and **manipulating** large images of **arbitrary dimensionality**.\nIts main contributions are n-dimensional versions of popular **image filters**, a collection of **image feature extractors**, ready to be used with [scikit-learn](http://scikit-learn.org), and an exhaustive n-dimensional **graph-cut** package.\n\n* [Installation](#installation)\n* [Getting started with the library](#getting-started-with-the-library)\n* [Getting started with the scripts](#getting-started-with-the-scripts)\n* [Support of medical image formats](#support-of-medical-image-formats)\n* [Requirements](#requirements)\n* [License](#license)\n\n## Installation\n\n```bash\nsudo apt-get install libboost-python-dev build-essential\npip3 install medpy\n```\n\n**MedPy** requires **Python 3** and officially supports Ubuntu as well as other Debian derivatives.\nFor installation instructions on other operating systems see the [documentation](http://loli.github.io/medpy/).\nWhile the library itself is written purely in Python, the **graph-cut** extension comes in C++ and has [it's own requirements](http://loli.github.io/medpy/installation/graphcutsupport.html).\n\n## Getting started with the library\n\nIf you already have a medical image at hand in [one of the supported formats](http://loli.github.io/medpy/information/imageformats.html), you can use it for this introduction. If not, navigate to http://www.nitrc.org/projects/inia19, click on the *Download Now* button, unpack and look for the *inia19-t1.nii* file. Open it in your favorite medical image viewer (I personally fancy [itksnap](http://www.itksnap.org)) and beware: the INIA19 primate brain atlas.\n\nLoad the image\n\n```python\nfrom medpy.io import load\nimage_data, image_header = load('/path/to/image.xxx')\n```\n\nThe data is stored in a numpy ndarray, the header is an object containing additional metadata, such as the voxel-spacing. Now lets take a look at some of the image metadata\n\n```python\nimage_data.shape\n```\n\n`(168, 206, 128)`\n\n```python\nimage_data.dtype\n```\n\n`dtype(float32)`\n\nAnd the header gives us\n\n```python\nimage_header.get_voxel_spacing()\n```\n\n`(0.5, 0.5, 0.5)`\n\n```python\nimage_header.get_offset()\n```\n\n`(0.0, 0.0, 0.0)`\n\nNow lets apply one of the **MedPy** filter, more exactly the [Otsu thresholding](https://en.wikipedia.org/wiki/Otsu%27s_method), which can be used for automatic background removal\n\n```python\nfrom medpy.filter import otsu\nthreshold = otsu(image_data)\noutput_data = image_data > threshold\n```\n\nAnd save the binary image, marking the foreground\n\n```python\nfrom medpy.io import save\nsave(output_data, '/path/to/otsu.xxx', image_header)\n```\n\nAfter taking a look at it, you might want to dive deeper with the tutorials found in the [documentation](http://loli.github.io/medpy/information/commandline_tools_listing.html).\n\n## Getting started with the scripts\n\n**MedPy** comes with a range of read-to-use commandline scripts, which are all prefixed by `medpy_`.\nTo try these examples, first get an image as described in the previous section. Now call\n\n```bash\nmedpy_info.py /path/to/image.xxx\n```\n\nwill give you some details about the image. With\n\n```bash\nmedpy_diff.py /path/to/image1.xxx /path/to/image2.xxx\n```\n\nyou can compare two image. And\n\n```bash\nmedpy_anisotropic_diffusion.py /path/to/image.xxx /path/to/output.xxx\n```\n\nlets you apply an edge preserving anisotropic diffusion filter. For a list of all scripts, see the [documentation](http://loli.github.io/medpy/).\n\n## Support of medical image formats\n\nMedPy relies on SimpleITK, which enables the power of ITK for image loading and saving.\nThe supported image file formats should include at least the following. Note that not all might be supported by your machine.\n\n**Medical formats:**\n\n* ITK MetaImage (.mha/.raw, .mhd)\n* Neuroimaging Informatics Technology Initiative (NIfTI) (.nia, .nii, .nii.gz, .hdr, .img, .img.gz)\n* Analyze (plain, SPM99, SPM2) (.hdr/.img, .img.gz)\n* Digital Imaging and Communications in Medicine (DICOM) (.dcm, .dicom)\n* Digital Imaging and Communications in Medicine (DICOM) series (<directory>/)\n* Nearly Raw Raster Data (Nrrd) (.nrrd, .nhdr)\n* Medical Imaging NetCDF (MINC) (.mnc, .MNC)\n* Guys Image Processing Lab (GIPL) (.gipl, .gipl.gz)\n\n**Microscopy formats:**\n\n* Medical Research Council (MRC) (.mrc, .rec)\n* Bio-Rad (.pic, .PIC)\n* LSM (Zeiss) microscopy images (.tif, .TIF, .tiff, .TIFF, .lsm, .LSM)\n* Stimulate / Signal Data (SDT) (.sdt)\n\n**Visualization formats:**\n\n* VTK images (.vtk)\n\n**Other formats:**\n\n* Portable Network Graphics (PNG) (.png, .PNG)\n* Joint Photographic Experts Group (JPEG) (.jpg, .JPG, .jpeg, .JPEG)\n* Tagged Image File Format (TIFF) (.tif, .TIF, .tiff, .TIFF)\n* Windows bitmap (.bmp, .BMP)\n* Hierarchical Data Format (HDF5) (.h5 , .hdf5 , .he5)\n* MSX-DOS Screen-x (.ge4, .ge5)\n\n## Requirements\n\nMedPy comes with a number of dependencies and optional functionality that can require you to install additional packages.\n\n### Main dependencies\n\n* [scipy](http://www.scipy.org)\n* [numpy](http://www.numpy.org)\n* [SimpleITK](https://simpleitk.readthedocs.io)\n\n### Optional functionalities\n\n* compilation with `max-flow/min-cut` (enables the GraphCut functionalities)\n\n## License\n\nMedPy is distributed under the GNU General Public License, a version of which can be found in the LICENSE.txt file.\n",
    "bugtrack_url": null,
    "license": "LICENSE.txt",
    "summary": "Medical image processing in Python",
    "version": "0.5.1",
    "project_urls": {
        "Homepage": "https://github.com/loli/medpy"
    },
    "split_keywords": [
        "medical",
        "image",
        "processing",
        "dicom",
        "itk",
        "insight",
        "tool",
        "kit",
        "mri",
        "ct",
        "us",
        "graph",
        "cut",
        "max-flow",
        "min-cut"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "798df7366f8f76518e2e7683b945bac4191c702deafb9db40ec6c1ca4fcdbf8c",
                "md5": "9b633cde37cdc402d60464ced6aa34c0",
                "sha256": "eb9040c2c01bcddbe63176d8d29fd1fdcaee79e269054ce1f4f3a48882b1f4d4"
            },
            "downloads": -1,
            "filename": "MedPy-0.5.1.tar.gz",
            "has_sig": false,
            "md5_digest": "9b633cde37cdc402d60464ced6aa34c0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4,>=3.5",
            "size": 156244,
            "upload_time": "2024-04-03T15:53:56",
            "upload_time_iso_8601": "2024-04-03T15:53:56.320536Z",
            "url": "https://files.pythonhosted.org/packages/79/8d/f7366f8f76518e2e7683b945bac4191c702deafb9db40ec6c1ca4fcdbf8c/MedPy-0.5.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-03 15:53:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "loli",
    "github_project": "medpy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "medpy"
}
        
Elapsed time: 0.22377s