0

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

我已使用此代码显示标题信息(您可以在此处找到标题信息):

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.

4

1 回答 1

3

您可以使用 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

于 2020-01-30T20:04:34.700 回答