Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1805965
  • 博文数量: 195
  • 博客积分: 4227
  • 博客等级: 上校
  • 技术积分: 2835
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-04 10:39
文章分类

全部博文(195)

文章存档

2013年(1)

2012年(26)

2011年(168)

分类: C/C++

2012-06-13 09:48:54

Spatial Frequency of an Image

When we deal with a one dimensional signal (time series), it is quite easy to understand what the concept of frequency is. Frequency is the number of occurrences of a repeating event per unit time. For example, in the figure below, we have 3 cosine functions with increasing frequencies cos(t), cos(2t), and cos(3t).

Here is the Matlab code for this experiment.

clear all;

close all;

clc;

t=0:0.05:2*pi;

figure, plot(cos(t),'r','LineWidth',2),hold on

plot(cos(2*t),'g','LineWidth',2),

plot(cos(3*t),'b','LineWidth',2),

grid on;

hleg1 = legend('cos(t)', 'cos(2t)', 'cos(3t)')

 

Intuitively, we can conclude that for a function , when  increases, the frequency of the function increases. However, when it comes to an image, it is quite difficult to understand what a low or high frequency means. We do not know what a low or high frequency correspond to in an image.

 

Our mistake is that we focus on the actual image and try to figure out the things although we do not have any example of images with different frequency components. Human is like a machine learning algorithm (actually machine learning algorithms are like human J). To be able to recognize an object, we first need to be trained on that object (God knows). Therefore, let us try to visualize low frequency and high frequency signals. Start with an example of low frequency, that is . First of all, we randomly (this is a lie) take 13 samples of  at

 

}.

 

The corresponding  values are:

 

.

 

Here is the Matlab code for this experiment.

clear all;

close all;

clc;

t_continuous=0:0.01:2*pi;

t_discrete  =0:0.5:2*pi;

plot(t_continuous,cos(t_continuous),'b','LineWidth',2),hold on

plot(  t_discrete,cos(t_discrete)  ,'r+','LineWidth',3),

y= cos(t_discrete);

grid on;

hleg1 = legend('cos(t)','samples')

 

 

So, we know that a sequence of such numbers gives us the feeling that  is a low frequency signal. How we can create an image of these numbers? Let scale the numbers to the range 0 and 255:

 

. Considering that values are intensity values, we can obtain the following image.

 

 

 

Here is the Matlab code for this experiment.

clear all;

close all;

clc;

t_discrete  =0:0.5:2*pi;

y= cos(t_discrete);%imshow(y,[])

y1=y;

y1=y1+abs(min(y1));

y1=y1/max(y1);

y1=uint8(y1*255);

 

figure,imshow(y1)

grid on;

hleg1 = legend('cos(t)','samples')

 

 

This is our first image with a low frequency component. We have a smooth transition from white to black and black to white. However, it is still difficult to say anything since we have not seen an image with high frequency. If we repeat all the steps for   , we obtain the following image:

 

 

 

where we have sudden jumps to black. You can try the same experiment for different cosines. By looking at two examples, we can say that if there are sharp intensity changes in an image, those regions correspond to high frequency components. On the other hand, regions with smooth transitions correspond to low frequency components.

We now have an idea for one dimensional image.  It is time to switch to two dimensional representation of a signal. Let us first define a kind of two dimensional signal: . For example, the signal for =1, we have: .

Here is the Matlab code for this experiment.

clear all;

close all;

clc;

t_continuous=0:0.01:2*pi;

t_discrete  =0:0.5:2*pi;

 

cost1 = cos(1*t_continuous);

cost2 = cos(1*t_continuous);

 

plot(t_continuous,cost1,'r','LineWidth',3),hold on

plot(t_continuous,cost2,'g','LineWidth',3)

plot(t_continuous,cost1.*cost2,'b','LineWidth',3),

 

grid on;

hleg1 = legend('cos(x)','cos(y)', 'cos(x)*cos(y)' )

 

If you wonder, you can assign different k values () for the base cosine functions, and plot the result. Our goal is to create an image containing a single frequency component as much as possible. Let us pick a cosine signal with a low frequency: . Our corresponding two dimensional function will be . How we will obtain a two dimensional image from this function? This is the question! We are going to define a matrix and store the values of for different  pairs.

 



 

 

 

 

 

 

 

 

 

 

 

 

 


Basically, we divide the angle range 0-2 into M and N regions for x and y, respectively. Here is the images obtained using this approach and Matlab code.

 

1D Function

Plot

Function 2D

2D Image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Here are images for different k values. Values of k represents the level of frequency (from low to high) for k=0,….,20


 

1D Function

Plot

Function 2D

2D Image

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 


 

 

 

Here is the Matlab code for this experiment.

clear all;

close all;

clc;

 

row=512;

col=512;

x  =0:(2*pi/(col-1)):2*pi;

y  =0:(2*pi/(row-1)):2*pi

k=1;

coskx  = cos(k*x);

cosky  = cos(k*y);

cosval = zeros(size(y,2),size(x,2));

 

for i=1:size(y,2)

    for j=1:size(x,2)

        cosval(i,j) = coskx(j)*coskx(i);       

    end

end

 

imshow(cosval,[])

figure, plot(x,coskx,'LineWidth',3)

hleg1 = legend('cos(x)');

grid on;

 

Similar to the 1D case, we can say that if the intensity values in an image changes dramatically, that image has high frequency components.

阅读(4686) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~