2181264433

QQ ：2181264433  MATLAB代做|FPGA代做|碎片拼接算法的实现

clc;
clear;
close all;
warning off;

STEP = 4;

figure;
subplot(221)
imshow(IAll);title('原始图像');
subplot(222)
imshow(IC1);title('碎片1');
subplot(223)
imshow(IC2);title('碎片2');
%步骤一：分离出小的碎片
if STEP == 1
Images1 = func_get_debris(IC1);
Images2 = func_get_debris(IC2);
for i = 1:length(Images1)+length(Images2)
if i<= length(Images1)
Images{i} = Images1{i};
else
Images{i} = Images2{i-length(Images1)};
end
end
save STEP1.mat Images
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%步骤二：角度调整
if STEP == 2
close all;
%角度旋转

[Images2,Images2_real,Num]=func_angle(Images,angle);
figure
for i = 1:Num
subplot(5,5,i);
imshow(Images2{i});
str = ['纠正角度后的碎片',num2str(i)];
title(str);
end
figure
for i = 1:Num
subplot(5,5,i);
imshow(Images2_real{i});
str = ['纠正角度后的碎片',num2str(i)];
title(str);
end
%进行拼接
save STEP2.mat Images2 Images2_real Num
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%步骤三：边缘修正
if STEP == 3
[Images0s,Images1s]=func_edge_cutting(Images2,Images2_real);
save STEP3.mat Images0s Images1s Num
end

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

if STEP == 4
close all;
figure
for i = 1:Num
subplot(5,5,i);
imshow(Images0s{i});
str = ['进行拼接的使用碎片',num2str(i)];
title(str);
end
Cycle        = 1:Num;

%提取左边的碎片
[Left,Left_ind]   = func_left(Images0s,Num);

%提取右边的碎片
[Right,Right_ind] = func_right(Images0s,Num);

%提取上面边的碎片
[Up,Up_ind]       = func_up(Images0s,Num);

%提取下面边的碎片
[Down,Down_ind]   = func_down(Images0s,Num);

%提取四个顶点
LU_ind = find_point([Left_ind,Up_ind]);
LU     = Images0s{LU_ind};
LD_ind = find_point([Left_ind,Down_ind]);
LD     = Images0s{LD_ind};
RU_ind = find_point([Right_ind,Up_ind]);
RU     = Images0s{RU_ind};
RD_ind = find_point([Right_ind,Down_ind]);
RD     = Images0s{RD_ind};

%获得中间碎片
Index  = unique([Left_ind,Right_ind,Up_ind,Down_ind]);
Mid    = Cycle;
Mid(Index) = [];

%由内而外进行拼接，从左上开始，上述步骤完成了，纸张的顶点拼接
%Step1：顶部match
Up_match   = func_up_match(Images0s,Up_ind,LU_ind,RU_ind,1);

%Step2：底部match
Down_match = func_down_match(Images0s,Down_ind,LD_ind,RD_ind,1);

%Step3：左边match
Left_match = func_left_match(Images0s,Left_ind,LU_ind,LD_ind,1);

%Step4：右边match
Rigth_match = func_right_match(Images0s,Right_ind,RU_ind,RD_ind,1);

%Step5：中间match
Mid_match   = func_Mid(Images0s,Mid,1);

%Step6：合并，为中间拼接建立外围匹配多边形
Image4line = func_whole(Up_match,Down_match,Left_match,Rigth_match,Mid_match,1);
end 