如何获得图像中使用的一维和二维空间滤镜的光谱? [英] How do I get the spectrum of 1D and 2D spatial filters used in images?

查看:258
本文介绍了如何获得图像中使用的一维和二维空间滤镜的光谱?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



锐化过滤器是:

>

  [ -  1,3,-1]; 
[-1,-1,-1; -1,8,-1; -1,-1,-1];

在MATLAB中,我该如何获得滤波器的频谱,或者如何获得这些过滤器的频率成分?您可以使用Luis Mendo的文章立即确定您的过滤器的光谱。使用。它们之间的区别在于DTFT是应用于离散信号的传统傅立叶变换。从连续的观点来看,我们应用频谱连续的频率的正常傅立叶变换。这里对于离散信号本质上是相同的,但是变换被应用于离散信号。输出频率也是连续的,并且附加的限制是频谱是 2 * pi 周期性的。对于DFT,它本质上是DTFT 频域中的采样版本。因此,它们之间的核心区别在于频域中的一个是连续的,而另一个是连续对应的采样版本。我们需要对DTFT进行采样的原因是,您可以实际上将光谱存储在计算机上,并让程序处理光谱(即MATLAB)。

您的问题要求确定频谱是什么,从理论的角度来看,我将向你展示DTFT。当我们实际绘制谱图时,我们实际上是对DTFT进行采样,所以当我们看到谱图时​​,就会看到DFT(或多或少)。 / p>

有关它们之间差异的非常好的解释可以在DSP StackExchange上找到:,我们有:












cos(x(x))。 ):





回到我们的1D过滤器的转换,我们可以做一些分解:
$ b



请注意,域介于 [ - pi,pi] 之间,因为一维傅里叶变换是 2 * pi symmetric。因此,如果要显示频谱,只需使用上述域进行绘图,并使用刚创建的公式,绘制绝对值值,因为频谱的大小总是正的: p>

  w = linspace(-pi,pi); 
h = abs(3 - 2 * cos(w));
plot(w,h);
title('1D谱的大小');
轴([ - pi,pi,0,5]);

的坐标,这两个坐标之间的距离都在 [ - pi,pi] 之间,我们将在 surf 。请记住采用过滤器的绝对值值来显示大小:

  [w1,w2] = meshgrid(linspace(-pi,pi)); 
h = abs(8-2 * cos(w1 + w2)-2 * cos(w1)-2 * cos(w2)-2 * cos(w1-w2));
surf(w1,w2,h);
title('过滤器的二维谱');

w1 w2 提供在阵列的每个相应空间位置处水平和垂直定义的频率的独特组合。 w1 w2 实际上是二维的。对于 w1 w2 的每个独特组合,我们确定谱图的大小。一旦我们计算出这些,我们可以把所有这些信息放在一个很好的三维表面图中。

我们得到:


请注意,这两个维度跨越 [ - pi,pi] 。如果您检查光谱,您将看到DC分量零值为零,实际上是一个高通滤波器,不是锐化滤波器。看到我下面的注释。




小记



顺便说一句,不是 2D锐化滤镜。它只是一个2D拉普拉斯算子,它是一个边缘检测,因此也是一个高通滤波器。它只检测边缘。如果你想正确地锐化图像,确保你在内核的中心中加1,那么你真的在做什么:

  h2 = [-1 -1 -1; -1 9 -1; -1 -1 -1]; 

偏移量1将确保您保持原始信号不变,在原始信号的顶部传递结果,从而提高您的输入。

I would like to know how to obtain the spectrum of a spatial 1 dimensional and 2 dimensional sharpening filter in image processing.

The sharpening filters are:

[-1, 3, -1];
[-1, -1, -1; -1, 8, -1; -1, -1, -1];

In MATLAB, what should I do to get the spectrum of the filters, or how do I get the frequency components of these filters?

解决方案

You can use Luis Mendo's post to determine the spectrum of your filter right away. Use either freqz for a 1D filter, or freqz2 for a 2D filter. Note that the plot using freqz and freqz2 are in terms of normalized frequency that spans between [-1,1].

However, I'd like to write this post to compliment Luis Mendo's and show you how the spectrum is derived.


Let's start with your first filter:

h1 = [-1,3,-1];

If you recall, the 1D Discrete-Time Fourier Transform (DTFT) is defined as:


Aside: Why the DTFT and not the Discrete Fourier Transform (DFT)?

Take special care that this is different from the Discrete Fourier Transform (DFT). The difference between them is that the DTFT is the traditional Fourier Transform applied to a discrete signal. From the continuous viewpoint, we apply the normal Fourier Transform where the spectrum is continuous in terms of frequency. It is essentially the same thing here for a discrete signal, but the transform is applied to a discrete signal. The output is also continuous in frequency, with the additional constraint that the spectrum is 2*pi periodic. For the DFT, it is essentially a sampled version of the DTFT in frequency domain. Therefore, the core difference between them both is that in the frequency domain, one is continuous while the other is a sampled version of the continuous counterpart. The reason why we need to sample the DTFT is so that you can actually store the spectra on computers and let programs process the spectra (i.e. MATLAB).

Your question asked to determine what the spectrum is, and in terms of a theoretical perspective, I will present the DTFT to you. When we actually plot the spectra, we are actually sampling the DTFT anyway, so when we see the spectra, you would be visualizing the DFT (more or less!).

A very good explanation about the differences between them both can be found on DSP StackExchange: https://dsp.stackexchange.com/questions/16586/difference-between-discrete-time-fourier-transform-and-discrete-fourier-transfor


Back to your question

For the definition of the DTFT, h[k] is a 1D signal, and omega is the angular frequency defined in radians. Therefore, you can consider your filter to be this 1D signal and when you filter in the spatial domain, it is the same as taking this signal, transforming it into the frequency domain and performing multiplication with another input signal in the frequency domain.

Therefore, if we consider that your filter is symmetric, the value of 3 is defined as the centre point. As such, you can think of h[k] as:

h = [-1    3  -1]
      ^    ^   ^
k =   -1   0   1

Therefore, the frequency domain representation is simply a weighted sum of the filter coefficients with complex exponential terms. Substituting h[k] into the Fourier Transform formula, we get:

If you recall Euler's formula, we have:

Similarly:

If we add the two equations together, we can rearrange and solve for cos(x):

Going back to our transform of our 1D filter, we can do some factoring:

Note that the domain is between [-pi,pi], as the 1D Fourier Transform is 2*pi symmetric. As such, if you want to show the spectrum, simply plot using the above domain and use the equation that I just created, plotting the absolute value, as the magnitude of the spectrum is always positive:

w = linspace(-pi,pi);
h = abs(3 - 2*cos(w));
plot(w,h);
title('Magnitude of 1D spectrum');
axis([-pi, pi, 0, 5]);

linspace generates a linearly increasing array from -pi to pi with 100 points in between the ranges. You can override this behaviour by specifying a third parameter that manually tells linspace how many points you want to generate, but the default is 100 if you omit this parameter.

Note that I've made the y-axis extend from 0 so you can see where the curve starts at and it going up to 5 as this is the maximum value that is ever possible for h. This is what we get:

Indeed the above spectrum certainly looks like a high-pass filter, and because the magnitude at the DC frequency (w = 0) is 1, you are essentially adding the original signal on top of the high-pass filtering results, which thus "sharpens" your signal.


You can do the same process with the 2D case, though it will be a bit more involved. In the 2D case, the Discrete-Time Fourier Transform is defined to be:

We have two independent variables to consider, and we will have 2D spatial frequencies. w1 and k1 will operate along the rows of the 2D signal and w2 and k2 will operate along the columns of the 2D signal.

Given your mask:

h2 = [-1 -1 -1; -1 8 -1; -1 -1 -1]

As the shape of h2 is symmetric, the value of 8 will be location (w1,w2) = (0,0). Therefore, when we calculate the spectrum with the above equation, we get:

I'll save you the trouble with the simplification, but doing some rearranging and making use of Euler's formula, we get:

Note that:

I used the above property to make the simplifications possible. For the 2D case, we will define a meshgrid of coordinates that both range between [-pi,pi] for both dimensions, and we will plot this on a surface plot with surf. Remember to take the absolute value of the filter to show the magnitude:

[w1,w2] = meshgrid(linspace(-pi,pi));
h = abs(8 - 2*cos(w1+w2) - 2*cos(w1) - 2*cos(w2) - 2*cos(w1-w2));
surf(w1,w2,h);
title('2D spectrum of filter');

w1 and w2 provide unique combinations of the frequencies defined horizontally and vertically at each respective spatial location of the arrays. w1 and w2 will in fact be two-dimensional. For each unique combination of w1 and w2, we determine what the magnitude of the spectra will be. Once we calculate these, we can put all of this information together in a nice three-dimensional surface plot.

We thus get:

Take note that both dimensions span from [-pi,pi]. If you examine the spectrum, you will see that the DC component gets nulled to 0, which is actually a high-pass filter, and not a sharpening filter. See my note below.


Minor note

BTW, your 2D filter definition is not a 2D sharpening filter. It is simply a 2D Laplacian, which is an edge detection and thus a high-pass filter. It only detects edges. If you want to properly sharpen the image, make sure you add 1 to the centre of the kernel, and so what you're really after is:

h2 = [-1 -1 -1; -1 9 -1; -1 -1 -1];

The offset of 1 will ensure that you are leaving the original signal untouched, but also adding the high-pass results on top of the original signal to thus sharpen your input.

这篇关于如何获得图像中使用的一维和二维空间滤镜的光谱?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆