如何获得3D图像的直方图

时间:2017-12-20 07:02:37

标签: matplotlib deep-learning simpleitk

我正在进行大脑分割项目,需要对MRI进行预处理(来自BRATS2015)。 我想看看我的3D图片的直方图。 我的代码:

#-*- coding:utf-8 -*-
import SimpleITK as sitk
import numpy as np
from matplotlib import pyplot
import matplotlib.pyplot as plt

url = r'H:\myfile\VSD.Brain.XX.O.MR_T1.54525.mha'
image = sitk.ReadImage(url)
result = sitk.GetArrayFromImage(image)
print(type(result))
print(result.shape)
plt.figure('historgram')
result = result.flatten()
n, bins, patches = plt.hist(result, bins=256, normed=0, facecolor='red', alpha=0.75)
plt.show()

但这有点不对。我想这样: enter image description here

1 个答案:

答案 0 :(得分:1)

哦,我处理它。

#-*- coding:utf-8 -*-
import SimpleITK as sitk
import numpy as np
from matplotlib import pyplot
import matplotlib.pyplot as plt

url = r'H:\deepfortest\brats2015_train\HGG\brats_2013_pat0003_1\VSD.Brain.XX.O.MR_T1.54525.mha'
image = sitk.ReadImage(url)
result = sitk.GetArrayFromImage(image)
print(type(result))
print(result.shape)
plt.figure('historgram')
result = result.flatten()
n, bins, patches = plt.hist(result, bins=256, range= (1,result.max()),normed=0, facecolor='red', alpha=0.75,histtype = 'step')
plt.show()