CT典型数据——shepp_logan体模数据的生成 python版本

phantominator包介绍

基本用法:生成shepp_logan体模

import phantominator
from phantominator import shepp_logan

import matplotlib.pyplot as plt

2D体模

# 基本用法
# 2D CT
# 输出典型的体模,取值为[0,1] 参数为:
"""
E = np.zeros((10, 6)) # (10, [A, a, b, xc, yc, theta])
    E[:, 0] = [2, -.98, -.02, -.02, .01, .01, .01, .01, .01, .01]
    E[:, 1] = [
        .69, .6624, .11, .16, .21, .046, .046, .046, .023, .023]
    E[:, 2] = [.92, .874, .31, .41, .25, .046, .046, .023, .023, .046]
    E[:, 3] = [0, 0, .22, -.22, 0, 0, 0, -.08, 0, .06]
    E[:, 4] = [0, -.0184, 0, 0, .35, .1, -.1, -.605, -.605, -.605]
    E[:, 5] = np.deg2rad([0, 0, -18, 18, 0, 0, 0, 0, 0, 0])
    return E
"""

ph = shepp_logan(512)
print(ph.shape)
print(ph)

plt.imshow(ph, cmap='gray')
plt.show()
(512, 512)
[[0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 ...
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]
 [0. 0. 0. ... 0. 0. 0.]]

在这里插入图片描述

3D体模

# 3D CT
ph3d = shepp_logan((512, 512, 6), zlims=(-.25, .25))
print(ph3d.shape)

plt.figure(figsize=(15, 15))
n = ph3d.shape[-1]
for i in range(n):
    img = ph3d[:,:,i]
    plt.subplot(1, n, i + 1)
    plt.imshow(img, cmap="gray")
plt.show()
(512, 512, 6)

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wqeA0bvw-1610505201695)(output_6_1.png)]

生成震荡的同心圆

from phantominator import dynamic
import math

phd = dynamic(128, 20)
print(ph.shape)
(128, 128, 20)
cols = 6
rows = math.ceil(phd.shape[-1] / cols)

n = phd.shape[-1]
plt.figure(figsize=(15, 15))
for i in range(n):
    img = phd[:,:,i]
    plt.subplot(rows, cols, i + 1)
    plt.imshow(img, cmap="gray")
plt.show()

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-ZpS5lMTB-1610505201696)(output_9_0.png)]

好的,以下是基于MATLAB的Shepp-Logan体模实验代码。首先,我们需要生成Shepp-Logan体模: ```matlab % Shepp-Logan体模参数设置 N = 256; % 图像大小 a = 1; % 长轴大小 b = 0.6; % 短轴大小 c = 0.2; % 密度 phi = [0, 0, 0, 0, 0, 0, 0]; % 旋转角度 theta = [0, pi/6, pi/3, pi/2, 2*pi/3, 5*pi/6, pi]; % 旋转方向 % 生成Shepp-Logan体模 [X,Y] = meshgrid(-1:2/(N-1):1); m = zeros(N,N); for i = 1:length(theta) t = ((X*cos(theta(i))+Y*sin(theta(i))).^2)/a^2 + ((Y*cos(theta(i))-X*sin(theta(i))).^2)/b^2; idx = t <= 1; m(idx) = m(idx) + c*((-1)^i)*((phi(i)*pi/180)*ones(size(t(idx)))); end ``` 接下来,我们将生成Shepp-Logan体模进行投影,模拟CT扫描: ```matlab % 投影角度设置 theta = 0:179; % 投影得到sinogram sinogram = radon(m, theta); % 显示sinogram figure; imagesc(theta, linspace(-1, 1, size(sinogram, 1)), sinogram); colormap(gray); xlabel('Projection angle (degrees)'); ylabel('Projection position (normalized)'); title('Sinogram of Shepp-Logan phantom'); ``` 最后,我们可以将投影结果进行反投影,重建原始图像: ```matlab % 反投影重建图像 reconstructed = iradon(sinogram, theta, 'linear', 'Ram-Lak', 1, N); % 显示重建图像 figure; imagesc(reconstructed); colormap(gray); axis square; title('Reconstructed image of Shepp-Logan phantom'); ``` 完整的代码如下所示: ```matlab % Shepp-Logan体模参数设置 N = 256; % 图像大小 a = 1; % 长轴大小 b = 0.6; % 短轴大小 c = 0.2; % 密度 phi = [0, 0, 0, 0, 0, 0, 0]; % 旋转角度 theta = [0, pi/6, pi/3, pi/2, 2*pi/3, 5*pi/6, pi]; % 旋转方向 % 生成Shepp-Logan体模 [X,Y] = meshgrid(-1:2/(N-1):1); m = zeros(N,N); for i = 1:length(theta) t = ((X*cos(theta(i))+Y*sin(theta(i))).^2)/a^2 + ((Y*cos(theta(i))-X*sin(theta(i))).^2)/b^2; idx = t <= 1; m(idx) = m(idx) + c*((-1)^i)*((phi(i)*pi/180)*ones(size(t(idx)))); end % 投影角度设置 theta = 0:179; % 投影得到sinogram sinogram = radon(m, theta); % 显示sinogram figure; imagesc(theta, linspace(-1, 1, size(sinogram, 1)), sinogram); colormap(gray); xlabel('Projection angle (degrees)'); ylabel('Projection position (normalized)'); title('Sinogram of Shepp-Logan phantom'); % 反投影重建图像 reconstructed = iradon(sinogram, theta, 'linear', 'Ram-Lak', 1, N); % 显示重建图像 figure; imagesc(reconstructed); colormap(gray); axis square; title('Reconstructed image of Shepp-Logan phantom'); ``` 希望对您有所帮助!
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值