-
Notifications
You must be signed in to change notification settings - Fork 0
/
dctIMGProcessing.m
48 lines (38 loc) · 1.82 KB
/
dctIMGProcessing.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
%###names of input and output folders###
%path = {'NCSU-CUB_Foram_Images_G-bulloides','NCSU-CUB_Foram_Images_G-ruber','NCSU-CUB_Foram_Images_G-sacculifer','NCSU-CUB_Foram_Images_N-dutertrei','NCSU-CUB_Foram_Images_N-incompta','NCSU-CUB_Foram_Images_N-pachyderma','NCSU-CUB_Foram_Images_Others'};
path = {'NCSU-CUB_Foram_Images_N-incompta','NCSU-CUB_Foram_Images_Others'};
outF = 'DCTIMG';
%create output folder
mkdir(outF);
%start of main loop, goes through all folders of the dataset
for K = 1 : length(path)
%create datastore of the selected folder
imB = imageDatastore(strcat('Dataset/',path{K}), ...
'IncludeSubfolders', true, ...
'LabelSource','foldernames');
%create new folder in the selected output folde that has the same name of the input folder
mkdir(outF,path{K});
%go through each image in the dataStore
while I < length(imB.Labels)
[imgR, imgC] = size(readimage(imB,I));
px = zeros(imgR,imgC,16);
%this loop goes through 16 images at a time and stores the value of
%each pixel in a 3D matrix
for J = 1 : 16
img = readimage(imB,I);
for R = 1 : imgR
for C = 1 : imgC
px(R,C,J) = img(R,C);
end
end
I = I + 1;
end
%reduce dimension of the image matrix from 16 to 3 using dct and convert
%pixel values from double to integers
imgO = dct(px,3,3);
imgO = uint8(imgO);
%save the image in the new folder
nome = strcat(outF,'/',path{K},'/',char(imB.Labels(I-1)),'.png');
imwrite(imgO,nome);
end
end