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

时间:2020-12-01 14:54:50

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.

非常感谢你的帮助。

2 个解决方案

#1


0  

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.

我最近一直在研究一个非常相似的问题,试图计算一个阈值,以便在对图像进行其他计算之前,从MRI数据中排除噪声背景像素。我所做的是在直方图上安装一个样条,使其平滑,同时保持形状的精确匹配。我使用来自文件交换的夹板包来进行装配。我计算了一组一起处理的图像的直方图,但对于单个图像,它的工作方式应该类似。我还碰巧使用了直方图数据的对数转换,但这对于应用程序可能是有用的,也可能不是。

[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.

注意,样条是可微的,您可以使用ppdiff来得到导数,这对于找到最大值和最小值来帮助选择合适的阈值非常有用。这个数字被设置为一个相对较低的数字,以便于花键能平滑直方图。我在示例中使用linspace来选择断点,但是如果您知道直方图的某些部分比其他部分的曲率要大得多,那么您将希望在该区域中有更多的断点,而在其他地方少一些,以便准确地捕捉直方图的形状。

#2


0  

To smooth the histogram you need to use a 1-D filter. This is easily done using the filter function. Here is an example:

要平滑直方图,需要使用1-D过滤器。使用filter函数很容易做到这一点。这是一个例子:

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).

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

因为你的目标是找到一个图像二值化的阈值,你可以使用graythresh函数使用Otsu的方法。

#1


0  

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.

我最近一直在研究一个非常相似的问题,试图计算一个阈值,以便在对图像进行其他计算之前,从MRI数据中排除噪声背景像素。我所做的是在直方图上安装一个样条,使其平滑,同时保持形状的精确匹配。我使用来自文件交换的夹板包来进行装配。我计算了一组一起处理的图像的直方图,但对于单个图像,它的工作方式应该类似。我还碰巧使用了直方图数据的对数转换,但这对于应用程序可能是有用的,也可能不是。

[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.

注意,样条是可微的,您可以使用ppdiff来得到导数,这对于找到最大值和最小值来帮助选择合适的阈值非常有用。这个数字被设置为一个相对较低的数字,以便于花键能平滑直方图。我在示例中使用linspace来选择断点,但是如果您知道直方图的某些部分比其他部分的曲率要大得多,那么您将希望在该区域中有更多的断点,而在其他地方少一些,以便准确地捕捉直方图的形状。

#2


0  

To smooth the histogram you need to use a 1-D filter. This is easily done using the filter function. Here is an example:

要平滑直方图,需要使用1-D过滤器。使用filter函数很容易做到这一点。这是一个例子:

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).

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

因为你的目标是找到一个图像二值化的阈值,你可以使用graythresh函数使用Otsu的方法。