【问题标题】:Know the value range for the image data of a NIFTI image了解 NIFTI 图像的图像数据的取值范围
【发布时间】:2020-01-30 19:50:22
【问题描述】:

我正在使用 Python 3.7 和 SimpleITK 1.2.4 读取 NIFTI 文件。

我已经用这段代码展示了头信息(可以找到头信息here):

import SimpleITK as sitk
flair_file = '/content/gdrive/My Drive/Colab Notebooks/.../FLAIR.nii.gz'

reader = sitk.ImageFileReader()
reader.SetFileName(flair_file)

reader.LoadPrivateTagsOn()
reader.ReadImageInformation()
for k in reader.GetMetaDataKeys():
  v = reader.GetMetaData(k)
  print("({0}) = =\"{1}\"".format(k,v))

print("Image Size: {0}".format(reader.GetSize()))
print("Image PixelType: {0}".format(sitk.GetPixelIDValueAsString(reader.GetPixelID())))

这是它的输出:

(ITK_FileNotes) = =""
(aux_file) = =""
(bitpix) = ="32"
(cal_max) = ="0"
(cal_min) = ="0"
(datatype) = ="16"
(descrip) = =""
(dim[0]) = ="3"
(dim[1]) = ="240"
(dim[2]) = ="240"
(dim[3]) = ="48"
(dim[4]) = ="1"
(dim[5]) = ="1"
(dim[6]) = ="1"
(dim[7]) = ="1"
(dim_info) = ="�"
(intent_code) = ="0"
(intent_name) = =""
(intent_p1) = ="0"
(intent_p2) = ="0"
(intent_p3) = ="0"
(pixdim[0]) = ="1"
(pixdim[1]) = ="0.958333"
(pixdim[2]) = ="0.958333"
(pixdim[3]) = ="3"
(pixdim[4]) = ="0"
(pixdim[5]) = ="0"
(pixdim[6]) = ="0"
(pixdim[7]) = ="0"
(qform_code) = ="2"
(qform_code_name) = ="NIFTI_XFORM_ALIGNED_ANAT"
(qoffset_x) = ="118.611"
(qoffset_y) = ="127.182"
(qoffset_z) = ="13.3168"
(quatern_b) = ="0.0315572"
(quatern_c) = ="-0.216054"
(quatern_d) = ="0.975691"
(scl_inter) = ="0"
(scl_slope) = ="1"
(sform_code) = ="1"
(sform_code_name) = ="NIFTI_XFORM_SCANNER_ANAT"
(slice_code) = ="�"
(slice_duration) = ="0"
(slice_end) = ="0"
(slice_start) = ="0"
(srow_x) = ="-0.955749 -0.048177 0.160403 118.611"
(srow_y) = ="0.0220411 -0.868189 -1.26837 127.182"
(srow_z) = ="0.0667887 -0.402902 2.71395 13.3168"
(toffset) = ="0"
(vox_offset) = ="352"
(xyzt_units) = =""
Image Size: (240, 240, 48)
Image PixelType: 32-bit float

使用 imageJ 程序,当我点击 Image => Show info...时,我得到了这个结果...

Title: FLAIR.nii.gz
Width:  230.0000 mm (240)
Height:  230.0000 mm (240)
Depth:  144.0000 mm (48)
Size:  11MB
X Resolution:  1.0435 pixels per mm
Y Resolution:  1.0435 pixels per mm
Voxel size: 0.9583x0.9583x3.0000 mm^3
ID: -2
Bits per pixel: 32 (float)
Display range: 0 - 1980.8942
Image: 1/48
No threshold
ScaleToFit: false
Uncalibrated
Path: /FLAIR.nii.gz
Screen location: 927,131 (1920x1080)
Coordinate origin:  0,0,0
No overlay
No selection

而且,当我点击图像 => 属性时,我发现图像是一个通道。

如果我想知道图像数据的取值范围,我怎么知道呢?因为每像素的位数是32,而且图像只有一个通道,但我不知道它们的值是从0.0到1.0,还是从0.0到255.0。

对于图像数据,我指的是每个像素的值。

更新

我已经使用 Numpy 通过以下代码从图像数据中了解最大值和最小值:

import SimpleITK as sitk
flair_file = '/content/gdrive/My Drive/Colab Notebooks/.../FLAIR.nii.gz'

images = sitk.ReadImage(flair_file)

images_array = sitk.GetArrayFromImage(images)
print("Images Array Shape: ", images_array.shape)
print(np.amin(images_array),np.amax(images_array))

这是它的输出:

Images Array Shape:  (48, 240, 240)
0.0 2380.6191

也许,我正在寻找的最小值和最大值是:0.02380.6191

【问题讨论】:

    标签: python dicom itk simpleitk nifti


    【解决方案1】:

    您可以使用 SimpleITK 的 StatisticsImageFilter 来计算图像的最小值、最大值、总和、均值、方差 sigma。将以下行添加到您的代码中:

    img = reader.Execute()
    stats = sitk.StatisticsImageFilter()
    stats.Execute(img)
    print("Minimum:", stats.GetMinimum())
    print("Maximum:", stats.GetMaximum())
    

    这是过滤器的文档:https://itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1StatisticsImageFilter.html

    【讨论】:

    • 谢谢。我已经安装了 SimpleITK-1.2.4。我认为,这个版本没有方法 StatisticImageFilter() 因为我得到了错误:AttributeError: module 'SimpleITK' has no attribute 'StatisticImageFilter'
    • 我的错。我拼错了过滤器名称。统计数据末尾有一个“s”。
    • 非常感谢。现在它可以工作了,我得到的值与 Numpy Array 版本相同。
    猜你喜欢
    • 2019-06-14
    • 1970-01-01
    • 2023-02-24
    • 2021-04-10
    • 1970-01-01
    • 2017-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多