1 | clc;clear; |
---|
2 | % Load execution times for: |
---|
3 | % FFTrv FFT execution times for real 1D vectors |
---|
4 | % FFTiv FFT execution times for complex 1D vectors |
---|
5 | % IFFTiv IFFT execution times for complex 1D vectors |
---|
6 | % These times have been calculated with the script provatempo2.m |
---|
7 | % from length N = 3 up to length N = 2048. |
---|
8 | % A finer determination of such times can be done using PAPI for Matlab |
---|
9 | % http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=5445&objectType=File |
---|
10 | % or http://icl.cs.utk.edu/papi/ |
---|
11 | load fftexecutiontimes |
---|
12 | %-------------------------------------------------------------------------- |
---|
13 | %------------------------------------------------------ FAST 2D CONVOLUTION |
---|
14 | % Two arbitrary 2D matrices |
---|
15 | a = rand(234,222); |
---|
16 | b = rand(222,333); |
---|
17 | % Add a complex part |
---|
18 | % a=a+i*rand(size(a)); |
---|
19 | % b=b+i*rand(size(b)); |
---|
20 | |
---|
21 | % Optimized parameters for 2D convolution |
---|
22 | opt = detbestlength2(FFTrv,FFTiv,IFFTiv,size(a),size(b),isreal(a),isreal(b)); |
---|
23 | |
---|
24 | tic; |
---|
25 | y0 = fftolamopt2(a,b,opt); |
---|
26 | t = toc; |
---|
27 | % equivalent to do y0 = conv2(a,b,'full'); |
---|
28 | % Another example |
---|
29 | % y1 = fftolamopt2(a,b,opt,'same'); |
---|
30 | % equivalent to do y1 = conv2(a,b,'same'); |
---|
31 | disp('Time required for fast 2D convolution'); |
---|
32 | disp(t); |
---|
33 | %-------------------------------------------------------------------------- |
---|
34 | %-------------------------------------------------------------------------- |
---|
35 | |
---|
36 | %-------------------------------------------------------------------------- |
---|
37 | %-------------------------------------------------------- FAST 2D FILTERING |
---|
38 | I = imread('board.tif'); |
---|
39 | I = rgb2gray(I); |
---|
40 | I = double(I); |
---|
41 | |
---|
42 | % If the kernel filter is too small it is convenient to work in time domain, |
---|
43 | % without any FFT! |
---|
44 | myfilter = rand(60,50); |
---|
45 | tic; |
---|
46 | If = filter2(myfilter,I,'same'); |
---|
47 | t0 = toc; |
---|
48 | |
---|
49 | % Rot90 of myfilter to make results consistent |
---|
50 | mf = fliplr(flipud(myfilter)); |
---|
51 | % equivalent to do mf = rot90(myfilter); |
---|
52 | |
---|
53 | % Optimized parameters for 2D filtering |
---|
54 | opt = detbestlength2(FFTrv,FFTiv,IFFTiv,size(I),size(mf),isreal(I),isreal(mf)); |
---|
55 | tic; |
---|
56 | If1 = fftolamopt2(I,mf,opt,'same'); |
---|
57 | t1 = toc; |
---|
58 | |
---|
59 | disp('Time required by filter2'); |
---|
60 | disp(t0); |
---|
61 | disp('Time required by fftolamopt2'); |
---|
62 | disp(t1); |
---|
63 | disp('Max abs error'); |
---|
64 | disp(max(max(abs(If-If1)))); |
---|
65 | %-------------------------------------------------------------------------- |
---|
66 | %---------------------------------------- FAST NORMALIZED CROSS-CORRELATION |
---|
67 | % This function can easily be used also for a fast |
---|
68 | % normalized cross-correlation. |
---|
69 | % See normxcorr2 function (Matlab Image Processing Toolbox) for more details. |
---|
70 | %-------------------------------------------------------------------------- |
---|
71 | %-------------------------------------------------------------------------- |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | |
---|
77 | |
---|