在此SO answer上,建议我使用以下代码:
import SimpleITK as sitk
import numpy as np
# Create a noise Gaussian blob test image
img = sitk.GaussianSource(sitk.sitkFloat32, size=[240,240,48], mean=[120,120,24])
img = img + sitk.AdditiveGaussianNoise(img,10)
# Create a ramp image of the same size
h = np.arange(0.0, 255,1.0666666666, dtype='f4')
h2 = np.reshape(np.repeat(h, 240*48), (48,240,240))
himg = sitk.GetImageFromArray(h2)
print(himg.GetSize())
# Match the histogram of the Gaussian image with the ramp
result=sitk.HistogramMatching(img, himg)
# Display the 3d image
import itkwidgets
itkwidgets.view(result)
为什么我需要两个图像来做直方图均衡?
因为我想做直方图均衡,这就是直方图匹配。在这个article中,解释不同之处。
发布于 2020-01-29 19:04:18
通过直方图匹配实现直方图均衡是一种变通的方法。
‘255’是一个渐变图像,因此强度从0到255。它的所有强度都是相等的,所以它的直方图是扁平的。
因此,我们将图像的直方图与平面直方图进行匹配。最终结果是直方图均衡化。
https://stackoverflow.com/questions/59969339
复制