脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服务器之家 - 脚本之家 - Python - Python读取MRI并显示为灰度图像实例代码

Python读取MRI并显示为灰度图像实例代码

2020-12-30 01:08mengwei Python

这篇文章主要介绍了Python读取MRI并显示为灰度图像实例代码,具有一定借鉴价值,需要的朋友可以参考下

本文实例主要关于Python实现读取MRI(核磁共振成像)为numpy数组,使用imshow显示为灰度。

代码如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import matplotlib.pyplot as plt
import matplotlib.cbook as cbook
import matplotlib.cm as cm
import numpy as np
 
 
# Data are 256x256 16 bit integers
with cbook.get_sample_data('s1045.ima.gz') as dfile:
 im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
 
fig, ax = plt.subplots(num="MRI_demo")
ax.imshow(im, cmap=cm.gray)
ax.axis('off')
 
plt.show()

脚本运行时间:(0分0.018秒)

结果展示:

Python读取MRI并显示为灰度图像实例代码

总结

以上就是本文关于Python读取MRI并显示为灰度图像实例代码的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

原文链接:https://matplotlib.org/index.html

延伸 · 阅读

精彩推荐