在 MATLAB 中使用低通滤波器平滑直方图
我有一个图像,我的目标是对图像进行二值化。我使用低通高斯滤波器对图像进行了滤波,并计算了图像的强度直方图。
我现在想要对直方图进行平滑,以便可以获得二值化的阈值。我使用了低通滤波器,但它不起作用。这是我用的过滤器。
h = fspecial('gaussian', [8 8],2);
谁能帮我解决这个问题吗?直方图平滑的过程是什么?
imhist(Ig);
非常感谢您的帮助。
I have an image and my aim is to binarize the image. I have filtered the image with a low pass Gaussian filter and have computed the intensity histogram of the image.
I now want to perform smoothing of the histogram so that I can obtain the threshold for binarization. I used a low pass filter but it did not work. This is the filter I used.
h = fspecial('gaussian', [8 8],2);
Can anyone help me with this? What is the process with respect to smoothing of a histogram?
imhist(Ig);
Thanks a lot for all your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最近一直在研究一个非常类似的问题,尝试计算一个阈值,以便在对图像执行其他计算之前从 MRI 数据中排除噪声背景像素。我所做的是将样条线拟合到直方图以使其平滑,同时保持形状的精确拟合。我使用文件交换中的 splinefit 包来执行拟合。我计算了一起处理的一堆图像的直方图,但它对于单个图像应该类似。我还碰巧使用了直方图数据的对数转换,但这对于您的应用程序可能是有用的步骤,也可能不是有用的步骤。
请注意,样条曲线是可微分的,您可以使用 ppdiff 获取导数,这对于查找最大值和最小值以帮助选择合适的阈值非常有用。
numberofbreaks
设置为一个相对较低的数字,以便样条曲线可以平滑直方图。我在示例中使用 linspace 来选取断点,但如果您知道直方图的某些部分比其他部分表现出更大的曲率,那么您会希望在该区域有更多的断点,而在其他地方有更少的断点,以便准确捕获直方图。I've been working on a very similar problem recently, trying to compute a threshold in order to exclude noisy background pixels from MRI data prior to performing other computations on the images. What I did was fit a spline to the histogram to smooth it while maintaining an accurate fit of the shape. I used the splinefit package from the file exchange to perform the fitting. I computed a histogram for a stack of images treated together, but it should work similarly for an individual image. I also happened to use a logarithmic transformation of my histogram data, but that may or may not be a useful step for your application.
Note that the spline is differentiable and you can use ppdiff to get the derivative, which is useful for finding maxima and minima to help pick an appropriate threshold. The
numberofbreaks
is set to a relatively low number so that the spline will smooth the histogram. I used linspace in the example to pick the breaks, but if you know that some portion of the histogram exhibits much greater curvature than elsewhere, you'd want to have more breaks in that region and less elsewhere in order to accurately capture the shape of the histogram.要平滑直方图,您需要使用一维滤波器。使用 filter 函数可以轻松完成此操作。这是一个示例:
当然,您可以使用您选择的任何平滑函数。平均值就是
ones(1,8)
。由于您的目标只是找到二值化图像的阈值,因此您可以使用 graythresh 函数使用了大津的方法。
To smooth the histogram you need to use a 1-D filter. This is easily done using the filter function. Here is an example:
Of course you can use any smoothing function you choose. The mean would simply be
ones(1,8)
.Since your goal here is just to find the threshold to binarize an image you could just use the graythresh function which uses Otsu's method.