-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.m
71 lines (62 loc) · 2.71 KB
/
test.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
68
69
70
71
%% Class Prediction
% Prediction of the patches of the test image
%% Introduction
% Color of the different classes
%%
%
% * Concrete - Red
% * Brick - Black
% * Asphalt - White
% * Soil - Green
% * Timber - Blue
%% Prediction
% dbstop in disp
patchFeaturesTest = struct('Feature',{}, 'Class',{});
[filename, pathname] = uigetfile('*.*');
currentImage = imread([pathname filename]);
% transforming the gray scale to RGB storage format, if any
if size(currentImage,3) == 1
currentImage(:,:,2) = currentImage(:,:,1);
currentImage(:,:,3) = currentImage(:,:,1);
end
testImage = currentImage;
for j = 1:patchSize(1):(size(currentImage,1)-(patchSize(1)-1))
for k = 1:patchSize(1):(size(currentImage,2)-(patchSize(1)-1))
patch = currentImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),:);
fm_test = f(patch);
fm_test = reshape(fm_test{1,1}, [1 64])* p;
label = predict(pred, fm_test);
% Test image for presentation with color changed depending on patch
% class
if isequal(label{1,1},'Concrete')
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),1) = 225;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),2) = 0;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),3) = 0;
else if isequal(label{1,1},'Brick')
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),1) = 0;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),2) = 0;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),3) = 0;
else if isequal(label{1,1},'Asphalt')
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),1) = 225;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),2) = 225;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),3) = 225;
else if isequal(label{1,1},'Soil')
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),1) = 0;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),2) = 225;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),3) = 0;
else
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),1) = 0;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),2) = 0;
testImage(j:j+(patchSize(1)-1),k:k+(patchSize(1)-1),3) = 225;
end
end
end
end
end
end
%% Visualization of original image and predicted results
figure('Name','Test Image and Prediction')
bx = subplot(1, 2, 1);
imshow(currentImage, 'Parent', bx);
bx = subplot(1, 2, 2);
imshow(testImage, 'Parent', bx);