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

问题描述 投票:-1回答:1

我正在处理一个大脑分割项目,需要预处理我的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

matplotlib deep-learning simpleitk
1个回答
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()
© www.soinside.com 2019 - 2024. All rights reserved.