-
Notifications
You must be signed in to change notification settings - Fork 1
/
query.m
66 lines (50 loc) · 1.85 KB
/
query.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
queryImage = imread(imdb.images.name{1, 366});
[h, s, v] = rgb2hsv(queryImage);
[width, height, none] = size(queryImage);
rand_a = randi([10, width - 10], 1, 300);
rand_b = randi([10, height - 10], 1, 300);
queryFeature = zeros(1, 9);
for i = 1:300
maskH = h(rand_a(i):rand_a(i) + 9, rand_b(i):rand_b(i) + 9);
meanH = mean(mean(maskH));
stdH = std(std(double(maskH)));
grayMatrixH = graycomatrix(maskH);
grayPropertiesH = graycoprops(grayMatrixH);
homogeneityH = grayPropertiesH.Homogeneity;
maskS = s(rand_a(i):rand_a(i) + 9, rand_b(i):rand_b(i) + 9);
meanS = mean(mean(maskS));
stdS = std(std(double(maskS)));
grayMatrixS = graycomatrix(maskS);
grayPropertiesS = graycoprops(grayMatrixS);
homogeneityS = grayPropertiesS.Homogeneity;
maskV = v(rand_a(i):rand_a(i) + 9, rand_b(i):rand_b(i) + 9);
meanV = mean(mean(maskV));
stdV = std(std(double(maskV)));
grayMatrixV = graycomatrix(maskV);
grayPropertiesV = graycoprops(grayMatrixV);
homogeneityV = grayPropertiesV.Homogeneity;
queryFeature(i, :) = [meanH stdH homogeneityH meanS stdS homogeneityS meanV stdV homogeneityV];
end
[indexQ, centerQ] = kmeans(queryFeature, 10);
modelQ = fitcknn(queryFeature, indexQ, 'NumNeighbors', 1);
queryIndexedDatabase = zeros(1, 10);
for i = 1:300
class = predict(modelQ, queryFeature(i, :));
queryIndexedDatabase(1, class) = queryIndexedDatabase(1, class) + 1;
end
[x, y] = size(ICs);
distance = zeros(x, 1);
for i = 1:x
distance(i, 1) = sqrt(sum((ICs(i,:) - queryIndexedDatabase).^2));
end
[sortedValue, sortedIndex] = sort(distance);
for i = 25:50
finalImage = imread(imdb.images.name{1, sortedIndex(i)});
subplot(5,10,i)
imshow(finalImage)
title(i-30)
end
subplot(5,10,1:25)
imshow(queryImage)
title("Query Image")
suptitle("Arash Hatami - Self Organizing Natural Scene .::. 2018")