在 MATLAB 中使用低通滤波器平滑直方图

发布于 2024-11-23 19:54:51 字数 272 浏览 2 评论 0原文

我有一个图像,我的目标是对图像进行二值化。我使用低通高斯滤波器对图像进行了滤波,并计算了图像的强度直方图。

我现在想要对直方图进行平滑,以便可以获得二值化的阈值。我使用了低通滤波器,但它不起作用。这是我用的过滤器。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

执手闯天涯 2024-11-30 19:54:51

我最近一直在研究一个非常类似的问题,尝试计算一个阈值,以便在对图像执行其他计算之前从 MRI 数据中排除噪声背景像素。我所做的是将样条线拟合到直方图以使其平滑,同时保持形状的精确拟合。我使用文件交换中的 splinefit 包来执行拟合。我计算了一起处理的一堆图像的直方图,但它对于单个图像应该类似。我还碰巧使用了直方图数据的对数转换,但这对于您的应用程序可能是有用的步骤,也可能不是有用的步骤。

[my_histogram, xvals] = hist(reshape(image_volume), 1, []), number_of_bins);
my_log_hist = log(my_histogram);
my_log_hist(~isfinite(my_log_hist)) = 0;   % Get rid of NaN values that arise from empty bins (log of zero = NaN)
figure(1), plot(xvals, my_log_hist, 'b');
hold on
breaks = linspace(0, max_pixel_intensity, numberofbreaks);
xx = linspace(0, max_pixel_intensity, max_pixel_intensity+1);
pp = splinefit(xvals, my_log_hist, breaks, 'r');
plot(xx, ppval(pp, xx), 'r');

请注意,样条曲线是可微分的,您可以使用 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.

[my_histogram, xvals] = hist(reshape(image_volume), 1, []), number_of_bins);
my_log_hist = log(my_histogram);
my_log_hist(~isfinite(my_log_hist)) = 0;   % Get rid of NaN values that arise from empty bins (log of zero = NaN)
figure(1), plot(xvals, my_log_hist, 'b');
hold on
breaks = linspace(0, max_pixel_intensity, numberofbreaks);
xx = linspace(0, max_pixel_intensity, max_pixel_intensity+1);
pp = splinefit(xvals, my_log_hist, breaks, 'r');
plot(xx, ppval(pp, xx), 'r');

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.

灯角 2024-11-30 19:54:51

要平滑直方图,您需要使用一维滤波器。使用 filter 函数可以轻松完成此操作。这是一个示例:

I = imread('pout.tif');
h = imhist(I);
smooth_h = filter(normpdf(-4:4, 0,1),1,h);

当然,您可以使用您选择的任何平滑函数。平均值就是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:

I = imread('pout.tif');
h = imhist(I);
smooth_h = filter(normpdf(-4:4, 0,1),1,h);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文