## Sunday, January 25, 2009

### Matlab: Creating sinusoidal surfaces

2-D sinusoidal surfaces are used in image processing e.g. to evaluate implementation of Gabor filters, Wavelet and Fourier transformations, fractal analysis, etc.. Also they are very useful when one tries to explain how the above operation works, since all of the above are based on trigonometric functions (apart from fractals).

2-D sinusoidal surface is just an sinus function in 2D domain. On the other words, it is image of two-dimensional function sin.`function I=sinSurf(varargin)%create sinusoidal 2D function (image)%INPUT% - theta - angle in radians (default pi/2)% - lambda - frequency (default 0.5)% - Isize - output image size (default 256);% - delta - phase (default 0.0);%OUTPUT% - I - double matrix double (-1..1) of sinusoidal functiontheta=pi/2;Isize = 256;mag=0.5;lambda=0.5;delta=0;if nargin >= 1theta=varargin{1};endif nargin>=2lambda=varargin{2};endif nargin>=3Isize=varargin{3};endif nargin>=4delta=varargin{4};endI=zeros(Isize,Isize);cosa=cos(theta);sina=sin(theta);for x=1:Isizefor y=1:Isizexprime = (x*cosa+y*sina)/Isize;valu = mag*sin(2*pi*(xprime/lambda)-delta);I(x,y)=valu;endend`

Below some examples:

a) For: theta=pi/2;`s=sinSurf();imshow(s,[-1 1]);colormap(jet);colorbar;figure, mesh(s); axis([1 256 1 256 -1 1]); axis square;`

b) For: theta=pi/4;`s=sinSurf(pi/4);imshow(s,[-1 1]);colormap(jet);colorbar;figure, mesh(s); axis([1 256 1 256 -1 1]); axis square;`

c) For: theta=pi/2; lambda=0.25;`s=sinSurf(pi/2,0.25);imshow(s,[-1 1]);colormap(jet);colorbar;figure, mesh(s); axis([1 256 1 256 -1 1]); axis square;`

1. Anonymous9:06 AM

Thank you very much for this great post!

2. Anonymous5:02 AM

Though the code is simple, its very fantastic in what one can do with it. Thanks for the post

3. Thank you very much. It is helpful and so interesting.

4. Undefined function or method 'sinSurf' for input arguments of
type 'double'.

F#CK YOU