码迷,mamicode.com
首页 > 其他好文 > 详细

2013B题碎纸片拼接

时间:2018-08-27 21:58:21      阅读:209      评论:0      收藏:0      [点我收藏+]

标签:highlight   end   ima   class   atl   dir   5*   show   图像   

Photo1_1:

clear;clc;
path=‘E:\B\附件1\‘;
files=dir(‘E:\B\附件1\*.bmp‘);
% objdir=‘E:\B\附件1\‘;
% bgfile=[objdir,[‘00‘ int2str(i)],‘.bmp‘];
% lengthf=length(files);
% for i=1:lengthf
%     img=imread(strcat(‘E:\B\附件1\‘,files(i).name));
%     imshow(img);
% end
% bg=imread([path,files(1).name]);
% imshow(bg);
% imageinfo([path,files(1).name])
xsmat=ones(19,19);
for i=1:19
    imi=imread([path,files(i).name]);
    [mrow,mcol]=size(imi);
    for j=1:19
        imj=imread([path,files(j).name]);
        timi=im2double(imi);
        timj=im2double(imj);
        xssum=sum(abs(timi(:,mcol)-timj(:,1)));%计算图像i和图像j的相似度。
        xsmat(i,j)=xssum;
    end
end
first=0;last=0;
for i=1:19
    img=imread([path,files(i).name]);
   [ro,co]=size(img);
   tot=0;
   for j=1:ro
       if(img(j,1)==255)
           tot=tot+1;
       end
   end
   if tot==ro
       first=i;
       break;
   end
end
que=[];
que=[que first];
flag=1;
pos=1;
tf=first;
while(flag==1)
    t=255*255*254;
    tp=0;
    for i=1:19
        if i~=tf
            if t>xsmat(tf,i)
                t=xsmat(tf,i);
                tp=i;
            end
        end
    end
    tf=tp;
    pos=pos+1;
    que=[que tp];
    if pos==19
        flag=0;
    end
    
end

tim=[];
for i=1:19
    im=imread([path files(que(i)).name]);
    tim=[tim im];
end
imshow(tim);

  Photo1_2:

clear;clc;
path=‘E:\B\附件2\‘;
files=dir(‘E:\B\附件2\*.bmp‘);
xsmat=ones(19,19);
for i=1:19
    imi=imread([path,files(i).name]);
    [mrow,mcol]=size(imi);
    for j=1:19
        imj=imread([path,files(j).name]);
        timi=im2double(imi);
        timj=im2double(imj);
        xssum=sum((timi(:,mcol)-timj(:,1)).^2);%计算图像i和图像j的相似度。
        xsmat(i,j)=xssum;
    end
end
first=0;last=0;
for i=1:19
    img=imread([path,files(i).name]);
   [ro,co]=size(img);
   tot=0;
   for j=1:ro
       if(img(j,1)==255)
           tot=tot+1;
       end
   end
   if tot==ro
       first=i;
       break;
   end
end
que=[]
que=[que first];
flag=1;
pos=1;
tf=first;
while(flag==1)
    t=255*255*254;
    tp=0;
    for i=1:19
        if i~=tf
            if t>xsmat(tf,i)
                t=xsmat(tf,i);
                tp=i;
            end
        end
    end
    tf=tp;
    pos=pos+1;
    que=[que tp];
    if pos==19
        flag=0;
    end
    
end

tim=[];
for i=1:19
    im=imread([path files(que(i)).name]);
    tim=[tim im];
end
imshow(tim);

  

2013B题碎纸片拼接

标签:highlight   end   ima   class   atl   dir   5*   show   图像   

原文地址:https://www.cnblogs.com/zxhyxiao/p/9544132.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!