SSDA 算法的matlab程序
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
%SSDAÒÔ×î´óµã¶ÔÊýΪ׼Ôò,ËٶȱÈÒÔ×îСeΪ׼ÔòÂý£¬µ«µ±Ä£°åÓÐÔëÉùʱ£¬ÈÔÄܵõ½ÕýÈ·Æ¥Åäµã
%[FileName2,PathName2] = uigetfile('*.jpg');
%pic= imread(FileName2);
%[FileName,PathName] = uigetfile('*.jpg');
%moban=imread(FileName);
%pic = imread('D:\matching algorithm\matching\2.jpg');%%%%%%%%%%ºÄʱ12Ãëpic =imread('D:\matching
algorithm\matching\lena.jpg') %%%%%%%%%%ºÄʱ15Ãë
pic=pic(:,:,1);
rect_pic = [256 178 145 167]
moban = imcrop(pic,rect_pic);
moban=imnoise(moban,'gaussian',0.005);
pic=im2double(pic);
moban=im2double(moban);
subplot(2,2,1);
imshow(pic);%2
subplot(2,2,2);
imshow(moban);%3
pic1=pic;
[M,N]=size(pic);
[m,n]=size(moban);
d=zeros(M-m,N-n);
times=zeros(M-m,N-n);
Tnum=0;
tic;
for x=1:M-m
for y=1:N-n
Temp=0;
num=0;
for i=0:m-1
for j=0:n-1
Temp = Temp+abs(pic(i+x,j+y)-moban(i+1,j+1));
num=num+1;
end
if Temp>m
Tnum=num;
break
end
end
d(x,y)=Temp/(m*n);
times(x,y)=Tnum;
end
end
%[min_d, icmin] = min(d(:));
[max_t, itmax] = max(times(:));
%[p,q] = ind2sub(size(d),icmin(1));
[p,q] = ind2sub(size(times),itmax(1));
toc;
pic1(:,:)=255;
%pic1(p:p+m,q:q+n)=pic(p:p+m,q:q+n);
pic1(p:p+m-1,q:q+n-1)=moban(1:m,1:n);
msgbox(num2str([p,q]), 'location');
subplot(2,2,3);
imshow(pic1);%4
[M,N,k] = size(pic);
mask = ones(M,N);
i = find(pic1(:,:,1)==255);
mask(i) = .45; % try experimenting
subplot(2,2,4);
imshow(pic(:,:,1)) % show only red plane of flowers %7 hold on
h = imshow(pic1); % overlay recovered_lily %8
set(h,'AlphaData',mask)