联系QQ:

2181264433

产品中心
联系我们
联系:张女士
微信:扫一扫右侧二维码
QQ :2181264433
邮箱:2181264433@qq.com
地址:浙江省-嘉兴市-南湖区
网址:www.mhslogic.com
您当前位置:首页 > 产品中心 >  图像处理 > 正文 图像处理
MATLAB代做|FPGA代做|碎片拼接算法的实现
MATLAB代做|FPGA代做|碎片拼接算法的实现
详细介绍:
clc;
clear;
close all;
warning off;
addpath 'func\'
addpath 'func\core_func\'
addpath 'func\core_func\up\'
addpath 'func\core_func\down\'
addpath 'func\core_func\left\'
addpath 'func\core_func\right\'
addpath 'func\core_func\mid\'

STEP = 4;

IAll = rgb2gray(imread('a\1.bmp'));
IC1  = rgb2gray(imread('a\2.bmp'));
IC2  = rgb2gray(imread('a\3.bmp'));

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; 
   load STEP1.mat
   %角度旋转
   load angle1.mat

   [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
   load STEP2.mat
   [Images0s,Images1s]=func_edge_cutting(Images2,Images2_real);
   save STEP3.mat Images0s Images1s Num
end


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

if STEP == 4
   close all; 
   load STEP3.mat
   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





收缩

扫一扫,关注我们