diff options
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/TUTORIALS/matlabPyrTools.m')
-rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/TUTORIALS/matlabPyrTools.m | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/TUTORIALS/matlabPyrTools.m b/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/TUTORIALS/matlabPyrTools.m new file mode 100755 index 0000000..44c27ce --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/matlabPyrTools/TUTORIALS/matlabPyrTools.m | |||
@@ -0,0 +1,145 @@ | |||
1 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
2 | %%% Some examples using the tools in this distribution. | ||
3 | %%% Eero Simoncelli, 2/97. | ||
4 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | ||
5 | |||
6 | %% Add directory to path (YOU'LL NEED TO ADJUST THIS): | ||
7 | path('/lcv/matlab/lib/matlabPyrTools',path); | ||
8 | |||
9 | %% Load an image, and downsample to a size appropriate for the machine speed. | ||
10 | oim = pgmRead('einstein.pgm'); | ||
11 | tic; corrDn(oim,[1 1; 1 1]/4,'reflect1',[2 2]); time = toc; | ||
12 | imSubSample = min(max(floor(log2(time)/2+3),0),2); | ||
13 | im = blurDn(oim, imSubSample,'qmf9'); | ||
14 | clear oim; | ||
15 | |||
16 | %%% ShowIm: | ||
17 | %% 3 types of automatic graylevel scaling, 2 types of automatic | ||
18 | %% sizing, with or without title and Range information. | ||
19 | help showIm | ||
20 | clf; showIm(im,'auto1','auto','Al') | ||
21 | clf; showIm('im','auto2') | ||
22 | clf; showIm(im,'auto3',2) | ||
23 | |||
24 | %%% Statistics: | ||
25 | mean2(im) | ||
26 | var2(im) | ||
27 | skew2(im) | ||
28 | kurt2(im) | ||
29 | entropy2(im) | ||
30 | imStats(im) | ||
31 | |||
32 | %%% Synthetic images. First pick some parameters: | ||
33 | sz = 200; | ||
34 | dir = 2*pi*rand(1) | ||
35 | slope = 10*rand(1)-5 | ||
36 | int = 10*rand(1)-5; | ||
37 | orig = round(1+(sz-1)*rand(2,1)); | ||
38 | expt = 0.8+rand(1) | ||
39 | ampl = 1+5*rand(1) | ||
40 | ph = 2*pi*rand(1) | ||
41 | per = 20 | ||
42 | twidth = 7 | ||
43 | |||
44 | clf; | ||
45 | showIm(mkRamp(sz,dir,slope,int,orig)); | ||
46 | showIm(mkImpulse(sz,orig,ampl)); | ||
47 | showIm(mkR(sz,expt,orig)); | ||
48 | showIm(mkAngle(sz,dir)); | ||
49 | showIm(mkDisc(sz,sz/4,orig,twidth)); | ||
50 | showIm(mkGaussian(sz,(sz/6)^2,orig,ampl)); | ||
51 | showIm(mkZonePlate(sz,ampl,ph)); | ||
52 | showIm(mkAngularSine(sz,3,ampl,ph,orig)); | ||
53 | showIm(mkSine(sz,per,dir,ampl,ph,orig)); | ||
54 | showIm(mkSquare(sz,per,dir,ampl,ph,orig,twidth)); | ||
55 | showIm(mkFract(sz,expt)); | ||
56 | |||
57 | |||
58 | %%% Point operations (lookup tables): | ||
59 | [Xtbl,Ytbl] = rcosFn(20, 25, [-1 1]); | ||
60 | plot(Xtbl,Ytbl); | ||
61 | showIm(pointOp(mkR(100,1,[70,30]), Ytbl, Xtbl(1), Xtbl(2)-Xtbl(1), 0)); | ||
62 | |||
63 | |||
64 | %%% histogram Modification/matching: | ||
65 | [N,X] = histo(im, 150); | ||
66 | [mn, mx] = range2(im); | ||
67 | matched = histoMatch(rand(size(im)), N, X); | ||
68 | showIm(im + sqrt(-1)*matched); | ||
69 | [Nm,Xm] = histo(matched,150); | ||
70 | nextFig(2,1); | ||
71 | subplot(1,2,1); plot(X,N); axis([mn mx 0 max(N)]); | ||
72 | subplot(1,2,2); plot(Xm,Nm); axis([mn mx 0 max(N)]); | ||
73 | nextFig(2,-1); | ||
74 | |||
75 | %%% Convolution routines: | ||
76 | |||
77 | %% Compare speed of convolution/downsampling routines: | ||
78 | noise = rand(400); filt = rand(10); | ||
79 | tic; res1 = corrDn(noise,filt(10:-1:1,10:-1:1),'reflect1',[2 2]); toc; | ||
80 | tic; ires = rconv2(noise,filt); res2 = ires(1:2:400,1:2:400); toc; | ||
81 | imStats(res1,res2) | ||
82 | |||
83 | %% Display image and extension of left and top boundaries: | ||
84 | fsz = [9 9]; | ||
85 | fmid = ceil((fsz+1)/2); | ||
86 | imsz = [16 16]; | ||
87 | |||
88 | % pick one: | ||
89 | im = eye(imsz); | ||
90 | im = mkRamp(imsz,pi/6); | ||
91 | im = mkSquare(imsz,6,pi/6); | ||
92 | |||
93 | % pick one: | ||
94 | edges='reflect1'; | ||
95 | edges='reflect2'; | ||
96 | edges='repeat'; | ||
97 | edges='extend'; | ||
98 | edges='zero'; | ||
99 | edges='circular'; | ||
100 | edges='dont-compute'; | ||
101 | |||
102 | filt = mkImpulse(fsz,[1 1]); | ||
103 | showIm(corrDn(im,filt,edges)); | ||
104 | line([0,0,imsz(2),imsz(2),0]+fmid(2)-0.5, ... | ||
105 | [0,imsz(1),imsz(1),0,0]+fmid(1)-0.5); | ||
106 | title(sprintf('Edges = %s',edges)); | ||
107 | |||
108 | %%% Multi-scale pyramids (see pyramids.m for more examples, | ||
109 | %%% and explanations): | ||
110 | |||
111 | %% A Laplacian pyramid: | ||
112 | [pyr,pind] = buildLpyr(im); | ||
113 | showLpyr(pyr,pind); | ||
114 | |||
115 | res = reconLpyr(pyr, pind); % full reconstruction | ||
116 | imStats(im,res); % essentially perfect | ||
117 | |||
118 | res = reconLpyr(pyr, pind, [2 3]); %reconstruct 2nd and 3rd levels only | ||
119 | showIm(res); | ||
120 | |||
121 | %% Wavelet/QMF pyramids: | ||
122 | filt = 'qmf9'; edges = 'reflect1'; | ||
123 | filt = 'haar'; edges = 'qreflect2'; | ||
124 | filt = 'qmf12'; edges = 'qreflect2'; | ||
125 | filt = 'daub3'; edges = 'circular'; | ||
126 | |||
127 | [pyr,pind] = buildWpyr(im, 5-imSubSample, filt, edges); | ||
128 | showWpyr(pyr,pind,'auto2'); | ||
129 | |||
130 | res = reconWpyr(pyr, pind, filt, edges); | ||
131 | clf; showIm(im + i*res); | ||
132 | imStats(im,res); | ||
133 | |||
134 | res = reconWpyr(pyr, pind, filt, edges, 'all', [2]); %vertical only | ||
135 | clf; showIm(res); | ||
136 | |||
137 | %% Steerable pyramid: | ||
138 | [pyr,pind] = buildSpyr(im,4-imSubSample,'sp3Filters'); | ||
139 | showSpyr(pyr,pind); | ||
140 | |||
141 | %% Steerable pyramid, constructed in frequency domain: | ||
142 | [pyr,pind] = buildSFpyr(im,5-imSubSample,4); %5 orientation bands | ||
143 | showSpyr(pyr,pind); | ||
144 | res = reconSFpyr(pyr,pind); | ||
145 | imStats(im,res); | ||