-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathq5.m
67 lines (55 loc) · 2.01 KB
/
q5.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
61
62
63
64
65
66
67
% Question 5
% Write in an Excel File, in a format like the one given below
resultFile = 'image_features.xls';
labels = [
"Image Name",...
"Red Mean", "Red Variance", "Red Standard Deviation",...
"Red Skewness", "Red Kurtosis",...
"Green Mean", "Green Variance", "Green Standard Deviation",...
"Green Skewness", "Green Kurtosis",...
"Blue Mean", "Blue Variance", "Blue Standard Deviation",...
"Blue Skewness", "Blue Kurtosis",...
"No. of Rows", "No. of Columns", "No. of Channels",...
];
writematrix(labels, resultFile);
for idx = 0:19
imgName = sprintf("img%d.jpg", idx);
filePath = sprintf('../image_set_1/%s', imgName);
img = imread(filePath);
redChannel = img(:,:,1);
greenChannel = img(:,:,2);
blueChannel = img(:,:,3);
% Get size, height, width, no. of channels
imgSize = size(img);
imgHeight = imgSize(1);
imgWidth = imgSize(2);
numOfChannels = imgSize(3);
% Get Mean for all channels
meanRed = mean2(redChannel);
meanGreen = mean2(greenChannel);
meanBlue = mean2(blueChannel);
% Get Standard Deviation for all channels
stdRed = std2(redChannel);
stdGreen = std2(greenChannel);
stdBlue = std2(blueChannel);
% Get Variance for all channels
varRed = var(double(redChannel(:)));
varGreen = var(double(greenChannel(:)));
varBlue = var(double(blueChannel(:)));
% Get skewness for all channels
skewRed = skewness(redChannel(:));
skewGreen = skewness(greenChannel(:));
skewBlue = skewness(blueChannel(:));
% Get kurtosis for all channnels
kurtRed = kurtosis(redChannel(:));
kurtGreen = kurtosis(greenChannel(:));
kurtBlue = kurtosis(blueChannel(:));
imgData = [
imgName, ...
meanRed, varRed, stdRed, skewRed, kurtRed, ...
meanGreen, varGreen, stdGreen, skewGreen, kurtGreen, ...
meanBlue, varBlue, stdBlue, skewBlue, kurtBlue, ...
imgHeight, imgWidth, numOfChannels, ...
];
writematrix(imgData, resultFile, 'WriteMode','append');
end