-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathextract_patch.m
57 lines (43 loc) · 1.68 KB
/
extract_patch.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
function [x,y] = extract_patch(image,block_size)
%function to extract patch
ind_y = 0;
x=[];y=[];x_val=[];y_val=[];c_val=[];
e=1;
while(ind_y + block_size <= size(image,1))
ind_x = 0;
while(ind_x + block_size<= size(image,2))
block_im = image(ind_y+1:ind_y+block_size,ind_x+1:ind_x+block_size,:);
e = e + 1;
x = [x;ind_y+1 ind_y+block_size];
y = [y;ind_x+1 ind_x+block_size];
ind_x = ind_x + block_size;
end
block_im = image(ind_y+1:ind_y+block_size,ind_x+1:size(image,2),:);
%border case, if the border patch is less than half the size of block_size it is rejected
if(size(block_im,1)>=.5*block_size && size(block_im,2)>=.5*block_size)
e = e + 1;
x = [x;ind_y+1 ind_y+block_size];
y = [y;ind_x+1 size(image,2)];
end
ind_y = ind_y + block_size;
end
ind_x = 0;
while(ind_x + block_size<= size(image,2))
block_im = image(ind_y+1:size(image,1),ind_x+1:ind_x+block_size,:);
%border case, if the border patch is less than half the size of block_size it is rejected
if(size(block_im,1)>=0.5*block_size && size(block_im,2)>=0.5*block_size)
e = e + 1;
x = [x;ind_y+1 size(image,1)];
y = [y;ind_x+1 ind_x+block_size];
end
ind_x = ind_x + block_size;
end
block_im = image(ind_y+1:size(image,1),ind_x+1:size(image,2),:);
%border case, if the border patch is less than half the size of
%block_size it is rejected
if(size(block_im,1)>=0.5*block_size && size(block_im,2)>=0.5*block_size)
e = e + 1;
x = [x;ind_y+1 size(image,1)];
y = [y;ind_x+1 size(image,2)];
end
end