-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreprocess.m
More file actions
41 lines (28 loc) · 1.21 KB
/
Copy pathpreprocess.m
File metadata and controls
41 lines (28 loc) · 1.21 KB
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
function [cleanedImages, digitLabels] = preprocess(samplesPerClass, imageSize)
cleanedImages = [];
digitLabels = [];
original_digits = prnist([0:9], [1:samplesPerClass]);
for classIndex = 0:9
randomIndex = randi([1 samplesPerClass]);
for imageIndex = 1:samplesPerClass
i = classIndex * samplesPerClass + imageIndex;
im = data2im(original_digits(i));
if imageIndex == randomIndex
imwrite(im, sprintf('output\\%s_%d.jpg',"orig",classIndex));
end
se = strel('disk',1);
im = imclose(im, se);
im = imerode(im,se);
im = imdilate(im,se);
im = im_box(im, 0, 1);
im = im_resize(im, [imageSize - 2,imageSize - 2]);
im = im_box(im, 1, 0);
if imageIndex == randomIndex
imwrite(im, sprintf('output\\%s_%d.jpg',"proc",classIndex));
end
cleanedImages = [cleanedImages; reshape(im, 1, [])];
digitLabels = [digitLabels; strcat('digit_', num2str(classIndex))];
end
disp(classIndex);
end
end