2017年的数学建模比赛已经结束了

A题代码贴出来吧。
收获挺大的。因为,通过这次比赛,我开始接触了Python…
现学现写,各种搜doc、demo、stackoverflow也是没谁了。哈哈。
对了好多库例如skimage等,我用pip怎么装都装不上,cl.exe编译失败,折腾的没辙了,又下了一个好大的Anaconda。心疼/(ㄒoㄒ)/~~
为什么会编译失败,装不上呢?而且,用Conda就可以??

import matplotlib.pyplot as plt
from skimage.transform import iradon, rescale, rotate
import numpy as np
import pyexcel as xls

theta = range(0, 180)
sheet = xls.get_book(file_name="A题附件.xls").to_dict()
projection_data = np.array(sheet.get("附件2"))

# Figure 1, Sinogram
plt.subplot(221)
plt.title("Radon transform\n(Sinogram)")
plt.xlabel("Projection angle (deg)")
plt.ylabel("Projection position (pixels)")
plt.imshow(projection_data, cmap=plt.cm.Greys_r,
           extent=(0, 180, 0, 512), aspect='auto')

# Filtered Back Projection
reconstruction_fbp = iradon(projection_data, theta=theta, circle=True)

# Correction
reconstruction_fbp_corr = rotate(reconstruction_fbp, 29.7338)
xoffset = int(9.1674 * 512 / 100 * 0.5643)
yoffset = int(6.3485 * 512 / 100 * 0.5643)
for x, y in np.ndindex(reconstruction_fbp_corr.shape):
    if x < 512 - xoffset and y < 512 - yoffset:
        reconstruction_fbp_corr[x, y] = reconstruction_fbp_corr[x + xoffset, y + yoffset]
        reconstruction_fbp_corr[x + xoffset, y + yoffset] = 0

# Compress to 256*256
reconstruction_fbp_256 = rescale(reconstruction_fbp_corr, 0.5, mode='reflect')
# np.savetxt("reconstruction_Corr_2.txt", reconstruction_fbp_256)

# Figure 2, No corr recon
plt.subplot(223)
plt.title("Reconstruction\nFiltered back projection")
plt.imshow(reconstruction_fbp, cmap=plt.cm.Greys_r)

# Figure 3, Corr recon
plt.subplot(224)
plt.title("Reconstruction\nCorrection")
plt.imshow(reconstruction_fbp_corr, cmap=plt.cm.Greys_r)

plt.show()
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值