Coder Social home page Coder Social logo

phantominator's Introduction

Installation

python -m pip install phantominator

The goal is to have easy installation and usage for everyone. If something doesn't work, please open an issue and/or submit a pull request. We'll get it figured out.

pygrappa is an optional dependency required to run the phantominator.examples.radial_coil_sens example.

About

Python package for easy generation of numerical phantoms. I often need a simple image to try something out on. In MATLAB, I would use the phantom command to quickly get something to work with. In Python, it's not always quite so easy, so I made this package that's quick to install and use so there's as little friction as possible. There are other implementations of Shepp-Logan available from other projects, but they are usually not as easy to install or include other things that I don't want for this project.

This package offers both CT and MR versions.

Going forward, this module will support Python >= 3.8.

Usage

Also see the examples module and docstrings. The interface for CT phantom generation is similar to MATLAB's phantom function.

Examples can be run as:

# python -m phantominator.examples.[example-name], e.g.:
python -m phantominator.examples.shepp_logan

Basic usage:

# CT phantom
from phantominator import shepp_logan
ph = shepp_logan(128)

# MR phantom (returns proton density, T1, and T2 maps)
M0, T1, T2 = shepp_logan((128, 128, 20), MR=True)

The Shepp-Logan 3D phantom has ellipsoids in [-1, 1] along the z-axis. The 2D Shepp-Logan exists at z=-0.25, so if we want just a subset along the z-axis with the first slice being the traditional 2D phantom, we can use the zlims option:

from phantominator import shepp_logan
M0, T1, T2 = shepp_logan((64, 64, 5), MR=True, zlims=(-.25, .25))

We can also generate simple oscillating concentric circles:

# Dynamic (concentric circles), 20 time frames
from phantominator import dynamic
ph = dynamic(128, 20)

If we want to modify ellipse/ellipsoid parameters or we just want to see what they are. For example, we can get the MR ellipsoid parameters like this:

from phantominator import mr_ellipsoid_parameters
E = mr_ellipsoid_parameters()

See docstrings for ct_shepp_logan, and mr_shepp_logan for how the array E is structured. It follows conventions from MATLAB's phantom function.

Arbitrary k-space sampling is supported for the single coil 2D Shepp-Logan phantom:

# Given k-space coordinates (kx, ky), where kx and ky are 1D
# arrays using the same unit conventions as BART's traj command,
# we can find the corresponding k-space measurements:
from phantominator import kspace_shepp_logan
k = kspace_shepp_logan(kx, ky)

phantominator's People

Contributors

gaopinghai avatar mckib2 avatar tronic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

gaopinghai zongjg

phantominator's Issues

kx, ky scaling

It seems that BART's traj command uses different unit convention than mriphantom. Which scaling is better to use? Can we accommodate both? Currently kspace_shepp_logan uses mriphantom convention @Tronic

I don't feel very strongly either way, just need something that is consistent through the project and can be clearly communicated to users.

`numpy.complex` is deprecated

Running the example in kspace.py raises the following error:

AttributeError: module 'numpy' has no attribute 'complex'.
`np.complex` was a deprecated alias for the builtin `complex`. To avoid this error in existing code, use `complex` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.complex128` here.
The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:
    https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations

Fix would appear to be replacing every instance of dtype=np.complex with dtype=complex. Happy submit a PR for this!

Running in a clean environment with only pygrappa, phantominator, and jupyter installed:

# Name                    Version                   Build  Channel
_libgcc_mutex             0.1                 conda_forge    conda-forge
_openmp_mutex             4.5                       2_gnu    conda-forge
asttokens                 2.2.1              pyhd8ed1ab_0    conda-forge
backcall                  0.2.0              pyh9f0ad1d_0    conda-forge
backports                 1.0                pyhd8ed1ab_3    conda-forge
backports.functools_lru_cache 1.6.4              pyhd8ed1ab_0    conda-forge
bzip2                     1.0.8                h7f98852_4    conda-forge
ca-certificates           2022.12.7            ha878542_0    conda-forge
comm                      0.1.3              pyhd8ed1ab_0    conda-forge
contourpy                 1.0.7                    pypi_0    pypi
cycler                    0.11.0                   pypi_0    pypi
debugpy                   1.6.7            py39h227be39_0    conda-forge
decorator                 5.1.1              pyhd8ed1ab_0    conda-forge
ellipsinator              0.2.1                    pypi_0    pypi
executing                 1.2.0              pyhd8ed1ab_0    conda-forge
fonttools                 4.39.3                   pypi_0    pypi
imageio                   2.27.0                   pypi_0    pypi
importlib-metadata        6.1.0              pyha770c72_0    conda-forge
importlib-resources       5.12.0                   pypi_0    pypi
importlib_metadata        6.1.0                hd8ed1ab_0    conda-forge
ipykernel                 6.22.0             pyh210e3f2_0    conda-forge
ipython                   8.12.0             pyh41d4057_0    conda-forge
jedi                      0.18.2             pyhd8ed1ab_0    conda-forge
jupyter_client            8.1.0              pyhd8ed1ab_0    conda-forge
jupyter_core              5.3.0            py39hf3d152e_0    conda-forge
kiwisolver                1.4.4                    pypi_0    pypi
lazy-loader               0.2                      pypi_0    pypi
ld_impl_linux-64          2.40                 h41732ed_0    conda-forge
libffi                    3.4.2                h7f98852_5    conda-forge
libgcc-ng                 12.2.0              h65d4601_19    conda-forge
libgomp                   12.2.0              h65d4601_19    conda-forge
libnsl                    2.0.0                h7f98852_0    conda-forge
libsodium                 1.0.18               h36c2ea0_1    conda-forge
libsqlite                 3.40.0               h753d276_0    conda-forge
libstdcxx-ng              12.2.0              h46fd767_19    conda-forge
libuuid                   2.38.1               h0b41bf4_0    conda-forge
libzlib                   1.2.13               h166bdaf_4    conda-forge
matplotlib                3.7.1                    pypi_0    pypi
matplotlib-inline         0.1.6              pyhd8ed1ab_0    conda-forge
ncurses                   6.3                  h27087fc_1    conda-forge
nest-asyncio              1.5.6              pyhd8ed1ab_0    conda-forge
networkx                  3.1                      pypi_0    pypi
numpy                     1.24.2                   pypi_0    pypi
openssl                   3.1.0                h0b41bf4_0    conda-forge
packaging                 23.0               pyhd8ed1ab_0    conda-forge
parso                     0.8.3              pyhd8ed1ab_0    conda-forge
pexpect                   4.8.0              pyh1a96a4e_2    conda-forge
phantominator             0.6.4                    pypi_0    pypi
pickleshare               0.7.5                   py_1003    conda-forge
pillow                    9.5.0                    pypi_0    pypi
pip                       23.0.1             pyhd8ed1ab_0    conda-forge
platformdirs              3.2.0              pyhd8ed1ab_0    conda-forge
prompt-toolkit            3.0.38             pyha770c72_0    conda-forge
prompt_toolkit            3.0.38               hd8ed1ab_0    conda-forge
psutil                    5.9.4            py39hb9d737c_0    conda-forge
ptyprocess                0.7.0              pyhd3deb0d_0    conda-forge
pure_eval                 0.2.2              pyhd8ed1ab_0    conda-forge
pygments                  2.14.0             pyhd8ed1ab_0    conda-forge
pygrappa                  0.26.0                   pypi_0    pypi
pyparsing                 3.0.9                    pypi_0    pypi
python                    3.9.16          h2782a2a_0_cpython    conda-forge
python-dateutil           2.8.2              pyhd8ed1ab_0    conda-forge
python_abi                3.9                      3_cp39    conda-forge
pywavelets                1.4.1                    pypi_0    pypi
pyzmq                     25.0.2           py39h0be026e_0    conda-forge
readline                  8.2                  h8228510_1    conda-forge
scikit-image              0.20.0                   pypi_0    pypi
scipy                     1.9.1                    pypi_0    pypi
setuptools                67.6.1             pyhd8ed1ab_0    conda-forge
six                       1.16.0             pyh6c4a22f_0    conda-forge
ssfp                      1.0.0                    pypi_0    pypi
stack_data                0.6.2              pyhd8ed1ab_0    conda-forge
tifffile                  2023.3.21                pypi_0    pypi
tk                        8.6.12               h27826a3_0    conda-forge
tornado                   6.2              py39hb9d737c_1    conda-forge
tqdm                      4.65.0                   pypi_0    pypi
traitlets                 5.9.0              pyhd8ed1ab_0    conda-forge
typing-extensions         4.5.0                hd8ed1ab_0    conda-forge
typing_extensions         4.5.0              pyha770c72_0    conda-forge
tzdata                    2023c                h71feb2d_0    conda-forge
wcwidth                   0.2.6              pyhd8ed1ab_0    conda-forge
wheel                     0.40.0             pyhd8ed1ab_0    conda-forge
xz                        5.2.6                h166bdaf_0    conda-forge
zeromq                    4.3.4                h9c3ff4c_1    conda-forge
zipp                      3.15.0             pyhd8ed1ab_0    conda-forge

Missing explanation in ct_shepp_logan.py, line 28

First of all, thanks for your great work! I am new to CT reconstruction. I read many times about the Shepp-Logan Dataset in many places. But I never managed to download this Dataset until I got this package. This is the Shepp-Logan Dataset!

In the commit of ct_shepp_logan function, I think there is a missing line explaning the sixth column of E:

E : array_like, optional
        For 2D: ex6 numeric matrix defining e ellipses.  The six
        columns of E are:
            - Length of the horizontal semiaxis of the ellipse
            - Length of the vertical semiaxis of the ellipse
            - x-coordinate of the center of the ellipse (in [-1, 1])
            - y-coordinate of the center of the ellipse (in [-1, 1])
            - Angle between the horizontal semiaxis of the ellipse
              and the x-axis of the image (in rad)
            - Gray value of this ellipse (int [0, 1])    # <<<<<<<<<<<<<<< I think this is the missing line

is it right? It will be my great honor if I can help to propose a pull requests afterwords. @mckib2

import error

CT phantom

from phantominator import shepp_logan
ph = shepp_logan(128)

MR phantom (returns proton density, T1, and T2 maps)

M0, T1, T2 = shepp_logan((128, 128, 20), MR=True)
while i had runing the example i got this error although the liberary installed correctly

Traceback (most recent call last):
File "c:/Users/pc/Desktop/mri/task1/phantom.py", line 2, in
from phantominator import shepp_logan
File "C:\Users\pc\Anaconda3\lib\site-packages\phantominator_init_.py", line 10, in
from .kspace import kspace_shepp_logan
File "C:\Users\pc\Anaconda3\lib\site-packages\phantominator\kspace.py", line 7, in
from scipy.special import j1 # pylint: disable=E0611
File "C:\Users\pc\Anaconda3\lib\site-packages\scipy\special_init_.py", line 634, in
from . import _ufuncs
ImportError: DLL load failed: The specified module could not be found.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.