-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathprepare_twodgrid_dataset.m
61 lines (49 loc) · 1.4 KB
/
prepare_twodgrid_dataset.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
clear all
I=imread('peppers.png');
I=I(4:383,66:66+379,:);
I=rgb2gray(I);
I=imresize(I,1/4);
% calculate centered frequcy of given image
F=fftshift(fft2(I));
[U V]=meshgrid(-fix(size(F,2)/2):fix(size(F,2)/2),-fix(size(F,1)/2):fix(size(F,1)/2));
U=0.5*U/max(U(:));
V=0.5*V/max(V(:));
p=sqrt(U.^2+V.^2);
% create band pass filter
f=exp(-1000*(p-0.25).^2);
% filter image in frequency domain
FD=F.*f;
% transform the filtered image in to spatial domain
fI=ifft2(ifftshift(FD));
% normalize it
fI1=(fI-min(fI(:)))/(max(fI(:))-min(fI(:)));
% create low-pass filter
f=exp(-100*(p-0).^2);
% filter image in frequency domain
FD=F.*f;
% transform the filtered image in to spatial domain and normalize it
fI2=ifft2(ifftshift(FD));
fI2=(fI2-min(fI2(:)))/(max(fI2(:))-min(fI2(:)));
% create high-pass filter
f=1-exp(-10*(p-0).^2);
FD=F.*f;
fI3=ifft2(ifftshift(FD));
fI3=(fI3-min(fI3(:)))/(max(fI3(:))-min(fI3(:)));
F=double(I)/255;
F=F(:);
Y=[fI1(:) fI2(:) fI3(:)];
% create 2D adjacency using gspbox library.
% basically A shows 4 neighborhood connection to the concerned node
% download gspbox and be sure the path is true, then run its gsp_start
% script in the library folder
run ../gspbox/gsp_start
G=gsp_2dgrid(size(I,1));
A=full(G.W);
A=A+A';
A(A>0)=1;
% create mask to avoid inconsistency of nodes near to borders
mask=zeros(size(I,1),size(I,1));
mask(3:end-2,3:end-2)=1;
mask=mask(:);
% save dataset
save 2Dgrid A F Y mask