SimpleITK的直方图均衡

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

关于此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中解释不同之处。

python itk simpleitk
1个回答
2
投票

通过直方图匹配来实现直方图均衡化是一种变通方法。

'himg'是渐变图像,因此强度从0到255。所有强度均等地表示,因此其直方图是平坦的。

因此,我们将图像的直方图与平面直方图进行匹配。最终结果是直方图均衡化。

© www.soinside.com 2019 - 2024. All rights reserved.