logo

How to Use the Shepp-Logan Phantom in Julia, MATLAB, and Python 📂Tomography

How to Use the Shepp-Logan Phantom in Julia, MATLAB, and Python

Julia1

To use the Tomography package Tomography.jl, you can use the phantom() function.

  • phantom(m,n=1): Generates a Shepp-Logan phantom of size m×mm\times m. When n=1, it generates a Shepp-Logan phantom, and when n=2, it generates a Modified Shepp-Logan phantom.
using Tomography
using Plots

# 팬텀 생성
p = phantom(256,2)

# 그림 출력
heatmap(reverse(p, dims=1))

Julia.png

Environment

  • OS: Windows10
  • Version: Julia 1.7.1, Tomography 0.1.5

MATLAB2

You can create a Shepp-Logan phantom with phantom. Without any arguments, an array of size 256×256256 \times 256 is created. The first argument specifies the type of phantom, and the second argument specifies the size to generate an arbitrary phantom. Below are the example code and the result.

%팬텀 생성
p1 = phantom();
p2 = phantom('Modified Shepp-Logan',2^10);

%그림 출력
figure()

%첫번째 그림 p1
subplot(1,2,1)
imagesc(p1)
colorbar
title('p1')

%두번째 그림 p2
subplot(1,2,2)
imagesc(p2)
colorbar
title('p2')

Environment

  • OS: Windows10
  • Version: R2020b

Matlab.png

Python3

In the scikit-image package skimage’s data module, you can use the shepp_logan_phantom function. It generates a phantom of size 400×400400 \times 400. To change the size, you can use resize. Below are the example code and the result.

import matplotlib.pyplot as plt

from skimage.data import shepp_logan_phantom

# 팬텀 생성
P = shepp_logan_phantom() #default size=(400,400)

# 그림 출력
plt.imshow(P)
plt.show()

# 사이즈 변경
from skimage.transform import resize

P = shepp_logan_phantom()
P = resize(P, (256,256))

Python.png

Environment

  • OS: Windows10
  • Version: Python 3.9.2, scikit-image 0.18.1