This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
procedure.m
82 lines (66 loc) · 2.23 KB
/
procedure.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
72
73
74
75
76
77
78
79
80
% a sample procedure illustrating how images are processed and detected
% without trim
template = im2bw(imresize(imread('template_f.jpg'), 0.1), 0.5); % 0.35p
imshow(template);
% sample = imresize(imread('f_c.jpg'), 0.1);
% sample = imresize(imread('f_ur.jpg'), 0.1);
sample = imresize(imread('f_ll.jpg'), 0.1);
% sample = imresize(imread('f_lr.jpg'), 0.1);
%
% sample = rgb2gray(imresize(imread('p_ur.jpg'), 0.1));
% sample = rgb2gray(imresize(imread('p_ll.jpg'), 0.1));
% sample = rgb2gray(imresize(imread('p_lr.jpg'), 0.1));
% sample = rgb2gray(imresize(imread('p_c.jpg'), 0.1));
% sample = imresize(imread('p_ur.jpg'), 0.1);
% sample = imresize(imread('p_ll.jpg'), 0.1);
% sample = imresize(imread('p_lr.jpg'), 0.1);
% sample = imresize(imread('p_c.jpg'), 0.1);
c = normxcorr2(template,sample);
figure, surf(c), shading flat
[ypeak, xpeak] = find(c==max(c(:)));
ypeak = ypeak(1); % make sure the dimension is 1
xpeak = xpeak(1); % same
yoffSet = ypeak-size(template,1);
xoffSet = xpeak-size(template,2);
xPos = xoffSet + 0.5*size(template,2);
yPos = yoffSet + 0.5*size(template,1);
hAx = axes;
imshow(sample,'Parent', hAx);
disp('kkk');
disp(xoffSet);
% imrect(hAx, [xoffSet, yoffSet, size(template,2), size(template,1)]);
% imrect(hAx, [xPos, yPos, 10, 10]);
% imrect(hAx, [5, 5, 10, 10]);
% display all centroids
s = regionprops(logical(sample), 'centroid');
centroids = cat(1, s.Centroid);
imshow(sample)
hold on
plot(centroids(:,1), centroids(:,2), 'b*')
% compute sum of all horizontal values
hVal = nansum(centroids(:,1))
% compute sum of all vertical values
vVal = nansum(centroids(:,2))
% compute overall centroid
cen = [hVal/size(centroids,1), vVal/size(centroids,2)]
% display overall centroid
imrect(hAx, [int8(cen(1)), int8(cen(2)), 20, 20]);
hold off
r = 0.25*(size(template, 2) + size(template, 1))/2;
% center region
imellipse(hAx, [0.5*size(sample, 2) - r, 0.5*size(sample, 1) - r, 2*r, 2*r]);
if (xPos - 0.5*size(sample, 2))^2 + (yPos - 0.5*size(sample, 1))^2 < r^2
disp('center');
else
if (0 < yPos) & (yPos < (size(sample, 1)/2))
disp('upper');
end
if size(sample, 1)/2 <= yPos
disp('lower');
end
if 0 < xPos & xPos < size(sample, 2)/2
disp('left');
else
disp('right');
end
end