-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtake_patches_from_image.m
58 lines (46 loc) · 1.86 KB
/
take_patches_from_image.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
%
%
% Cropping 29x29 patches
%
% FRANCISCO CARRILLO PÉREZ
% IMAGE ANALYSIS AND COMPUTER VISION
% POLITECNICO DI MILANO (2017)
%
%
%% CROP
clear
I = imread('/media/datos/Dropbox/4ºaño/Image Analysis and Computer Vision/NanoFibers/Anomalous/ITIA1115.tif');
M = imread('/media/datos/Dropbox/4ºaño/Image Analysis and Computer Vision/NanoFibers/Anomalous/ITIA1115_gt.png');
vec = -14:14;
counter_of_normal_patches = 1;
counter_of_anomalous_patches = 1;
counter_of_patches = 17144;
for x=1:1024
for y=1:696
%This is the pixel were the patch is going to be crop around
pixel=I(x,y);
pixel_gt = M(x,y);
if(x < 29 || y < 29)
else
patchI = I(x+vec,y+vec);
patch_gt = M(x+vec,y+vec);
if(all(patch_gt))
if(counter_of_anomalous_patches < 200)
path = strcat('/media/datos/Dropbox/4ºaño/Image Analysis and Computer Vision/NanoFibers/DataSet/Anomalous/New/patch',int2str(counter_of_patches));
imwrite(patchI,strcat(path,'.png'));
counter_of_anomalous_patches = counter_of_anomalous_patches + 1;
counter_of_patches = counter_of_patches + 1;
end
else
if(not(all(patch_gt)))
if(counter_of_normal_patches < 500)
path = strcat('/media/datos/Dropbox/4ºaño/Image Analysis and Computer Vision/NanoFibers/DataSet/Normal/New/patch',int2str(counter_of_patches));
imwrite(patchI,strcat(path,'.png'));
counter_of_normal_patches = counter_of_normal_patches + 1;
counter_of_patches = counter_of_patches + 1;
end
end
end
end
end
end