在线等,急,图像拼接的问题,要去除重叠区域,大侠们啊
大侠们,怎么我源图像是彩色,拼接后就编程灰度了啊.我们老师叫我们要得出彩色的,大侠们帮帮我吧,在此非常感谢A6=imread('D:/upperpart.bmp');
A=imrotate(A6,90,'nearest');
subplot(1,2,1),imshow(A); title('源图像A');
B6=imread('D:/lowerpart2.bmp');
B=imrotate(B6,90,'nearest');
subplot(1,2,2),imshow(B); title('源图象B');
A1=im2double(A);
=size(A1);%在图A取特征块
B1=im2double(B);
sub_A=A1((high-1)/2-18:(high-1)/2,3*(wid-1)/4:3*(wid-1)/4+18);
sub_B1=B1(116:134,54:72);
mod1=sub_A-sub_B1;
mat1=sum(mod1.*mod1); %匹配模板对应像素差的平方和
mat_best=mat1;%在B图中搜寻对应匹配
%第一步粗匹配
for x1=1:19:wid-19
for y1=1:19:high-19
sub_B=B1(y1:y1+18,x1:x1+18);
mod=sub_A-sub_B;
mat=sum(mod.*mod);%匹配模板对应像素差的平方和
if mat<mat_best
mat_best=mat; xx=x1; yy=y1;
end
end
end
x=1.2;
y=1.2;%第二步细匹配
for x2=xx-9:xx+9
for y2=yy-9:yy+9
sub_B2=B1(y2-9:y2+9,x1-9:x1+9);
mod2=sub_A-sub_B2;
mat2=sum(mod2.*mod2);
if mat2<mat_best
mat_best=mat2; x=x2; y=y2;
end
end
end
%拼接
if y==0
AA=A1(1:high-1,1:wid-x); BB=B1(1:high-1,x:wid-1);
else if y>=(high-1)/2
AA=A1(1:high-y,1:wid-x); BB=B1(y:high-1,x:wid-1);
else
AA=A1(y:high-1,1:wid-x); BB=B1(1:high-y,x:wid-1);
end
end
C=;
figure,imshow(C); title('直接拼接的图像')
%融合
if y==0
A2=A(1:high-1,:); B2=B(1:high,:);
else if y>=50
A2=A(1:high-y,:); B2=B(y:high-1,:);
else
A2=A(y:high-1,:); B2=B(1:high-y,:);
end
end
=size(A2);
%基于像素平均值
a2=A2(1:high2,wid2-x+1:wid2);
b2=B2(1:high2,1:x);
c2=imadd(a2,b2);
cc=imdivide(c2,2);
aa=A2(1:high2,1:wid2-x);
bb=B2(1:high2,x:wid2);
D1=;
figure,imshow(D1)
title('基于重叠象素平均的融合');
%基于渐变因子
a1=A2(1:high2,wid-x+1:wid);
b1=B2(1:high2,1:x);
a=double(a1); b=double(b1);
d10=linspace(1,0,x);
d=1:x; %列数,即渐变矩阵有X行
d1=d10; %列向量,X个
=meshgrid(d1,d);
im1=a*X1;
d20=linspace(0,1,x); %行向量,X个
d2=d20;
=meshgrid(d2,d);
im2=b*X2;
im11=uint8(im1); im22=uint8(im2);
im3=imadd(im11,im22);
figure,imshow(im3)
title('融合区')
a_b=imadd(im11,im22);
a_c=20*a_b;
aa=A2(1:high2,1:wid-x);
bb=B2(1:high2,x:wid);
D2=;
figure,imshow(D2)
title('拼接图像');
我q是511304010,可以私聊.非常急等...........希望大哥们帮帮我这个学生
[ 本帖最后由 ChaChing 于 2010-5-23 21:03 编辑 ]
页:
[1]