簡體   English   中英

了解 NIFTI 圖像的圖像數據的值范圍

[英]Know the value range for the image data of a NIFTI image

我正在使用 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

而且,當我單擊 Image => Properties 時,我發現圖像是一個通道。

如果我想知道圖像數據的取值范圍,我怎么知道呢? 因為每像素的位數是 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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM