在python中读取没有标题的.img医学图像 [英] Read .img medical image without header in python

查看:1467
本文介绍了在python中读取没有标题的.img医学图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个没有头文件的放射线照片.img文件。但是,已发布该文件的研究人员已提供此信息

 高分辨率(2048×2048矩阵尺寸,0.175mm像素大小)
宽密度范围(12位,4096灰度)
通用图像格式(无标题,大端原始数据)

我试图用Python打开文件,但无法这样做。有人可以建议任何方法来阅读这个图像文件吗?

解决方案

我通过下载



我希望我已经回答了你的问题。
快乐编码!


I have a radiograph .img file without the header file. However, the researchers who have published the file have given this information about it

High resolution (2048 × 2048 matrix size, 0.175mm pixel size)
Wide density range (12-bit, 4096 gray scale)
Universal image format (no header, big-endian raw data)

I am trying to open the file using Python but unable to do so. Could someone suggest any method to read this image file?

解决方案

I found some radiograph images, like yours, by downloading the JSRT database. I have tested the following code on the first image of this database: JPCLN001.IMG.

import matplotlib.pyplot as plt
import numpy as np

# Parameters.
input_filename = "JPCLN001.IMG"
shape = (2048, 2048) # matrix size
dtype = np.dtype('>u2') # big-endian unsigned integer (16bit)
output_filename = "JPCLN001.PNG"

# Reading.
fid = open(input_filename, 'rb')
data = np.fromfile(fid, dtype)
image = data.reshape(shape)

# Display.
plt.imshow(image, cmap = "gray")
plt.savefig(output_filename)
plt.show()

It produces an output file JPCLN001.PNG which looks like this:

I hope I have answered to your question. Happy coding!

这篇关于在python中读取没有标题的.img医学图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆