-
Notifications
You must be signed in to change notification settings - Fork 0
/
rec_sor.m
108 lines (74 loc) · 2.89 KB
/
rec_sor.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
function []= rec_sor(dir)
%% 输入
% 图像
[filename,pathname]=uigetfile({'*.jpg';'*png'},'选择原图片');
Image_in = imread([pathname,filename]);
% 椭圆
% 坐标顺序 [x_center y_center 长轴 短轴 角度]
load([dir,filename(1:end-4),'_ellipse_top_center.mat']);
load([dir,filename(1:end-4),'_ellipse_bottom_center.mat']);
ellipse_top = ellipse_2_abcdef(ellipse_top_center);
ellipse_bottom = ellipse_2_abcdef(ellipse_bottom_center);
% 轮廓上的点
load([dir,filename(1:end-4),'_xxx.mat']);
load([dir,filename(1:end-4),'_yyy.mat']);
contour_xy=[yyy' xxx'];
contour_xy_sorted=sortrows(contour_xy,1);
contour_image = xy_contour_to_image(contour_xy_sorted, Image_in);
[contour_y, contour_x, hang, lie] = get_side_contour(dir, filename, contour_image, ellipse_top_center, ellipse_bottom_center);
figure;scatter(contour_x,contour_y,'.');
axis([0 lie 0 hang]);
set(gca,'YDir','reverse');
grid on;
contour_xy = [contour_y,contour_x];
contour_xy_sorted=sortrows(contour_xy,1);
%% 分段
fenduan = [0 0 0 0 0 0];
points_count = 0;
fenduan_count = 0;
while(true)
fenduandian=input(['请输入第' int2str(fenduan_count+1) '个分段点:']);
for i = 1:length(contour_x)
if(contour_xy_sorted(i,1) <= fenduandian)
points_count=points_count+1;
end
end
fenduan_count = fenduan_count + 1;
fenduan(fenduan_count) = points_count;
points_count = 0;
shifoujixu=input(['是否继续(1/0):']);
if(shifoujixu==1)
continue;
else
break;
end
end
fenduan(fenduan_count+1) = length(contour_x);
ks_all = [];
xy_sampled_all= [];
%% 拟合
for i = 1:(fenduan_count+1)
if( i == 1)
num_start = 1;
else
num_start = fenduan(i-1)+1;
end
xy_data = [contour_xy_sorted( num_start:fenduan(i), 2), contour_xy_sorted( num_start:fenduan(i), 1)];
nihefangshi=input(['拟合方式:直线/三次/五次:(1/3/5):']);
if (nihefangshi == 1)
[ks, xy_sampled] = line_fitting(xy_data);
elseif(nihefangshi == 3)
[ks, xy_sampled] = poly_fitting_3(xy_data);
elseif(nihefangshi == 5)
[ks, xy_sampled] = poly_fitting_5(xy_data);
end
eval( ['ks_',int2str(i),'=ks']);
eval( ['xy_sampled_',int2str(i),'=xy_sampled']);
ks_all_tmp = ks_all;
ks_all = [ks_all_tmp ks'];
xy_sampled_all = [xy_sampled_all xy_sampled];
clear xydata ks xy_sampled ks_all_tmp;
end
ks_all = ks_all';
all_in_one(dir,filename,ellipse_top, ellipse_bottom,Image_in, ks_all, xy_sampled_all);
end