-
Notifications
You must be signed in to change notification settings - Fork 0
/
TDPS_path.m
59 lines (50 loc) · 1.2 KB
/
TDPS_path.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
clc;clear all;close all;
img=imread('C:\Users\ÎIJ©\Desktop\sÐÍÍäµÀ3.0\l2.jpg');
A=rgb2gray(img);
%% Image blurring
n=16;
height=size(A,1)-mod(size(A,1),n);
length=size(A,2)-mod(size(A,2),n);
A=A(1:height,1:length);
for i=1:n:height
for j=1:n:length
k=mean(A(i:i+n-1,j:j+n-1),'all');
map=repmat(k,[n n]);
A(i:i+n-1,j:j+n-1)=map;
end
end
%% Image division
piece=8;
cuttedC=size(A,1)-rem(size(A,1),piece);
newC=A(1:cuttedC,:);
newsize=cuttedC/piece;
A=zeros([newsize size(A,2) piece]);
for i=1:1:piece
A(:,:,i)=newC(1+(i-1)*newsize:i*newsize,:);
end
%% Geometric center calculation
threshold=70;
for k=1:1:piece
[locationx,locationy]=find(A(:,:,k)<threshold);
fy(k)=floor(mean(locationx))+(k-1)*newsize;
fx(k)=floor(mean(locationy));
end
%% Angle calculation
% for i=1:1:piece-1
% diff(1,i)=fx(i)-fx(i+1);
% diff(2,i)=fy(i+1)-fy(i);
% end
diffx=fx(1)-fx(piece);
diffy=fy(piece)-fy(1);
% pathx=mean(diff(1,:));
% pathy=mean(diff(2,:));
degree=atan2d(diffy,diffx);
%% Visualization
subplot(1,2,1);
hold on;
imshow(img);
plot(fx(:),fy(:),'x');
hold off;
subplot(1,2,2);
compass(diffx,diffy);
title({['course=',num2str(degree)];['correction=',num2str(90-degree)]});