资源预览内容
第1页 / 共20页
第2页 / 共20页
第3页 / 共20页
第4页 / 共20页
第5页 / 共20页
第6页 / 共20页
第7页 / 共20页
第8页 / 共20页
第9页 / 共20页
第10页 / 共20页
亲,该文档总共20页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
Affinefunction img2 = affine(img, r, sx, sy, a, b, xo, yo)R = cos(r) -sin(r) 0;sin(r) cos(r)0;001;S = sxa0;bsy0;001;T2=10-xo;01-yo;001;T1=10xo;01yo;001;A = T1*R*S*T2;h,w=size(img);x,y = meshgrid(1:h,1:w);x=x(:);y=y(:);XP = x;y;ones(1,length(x);X = A*XP;z = find(X(1,:)w-1);X(1,z) = w-1;z = find(X(1,:)h-1);X(2,z) = h-1;z= find(X(2,:)1.5);X(2,z) = 1.5;x = X(1,:);y = X(2,:);alpha = x - floor(x);%calculate alphas and betas for each pointbeta = y - floor(y);fx = floor(x);fy = floor(y);inw = fy + (fx-1)*h;%create index(索引) for neighboring pixelsine = fy + fx*h;isw = fy+1 + (fx-1)*h;ise = fy+1 + fx*h;img2 = (1-alpha).*(1-beta).*img(inw) + .%interpolate (同样)(1-alpha).*beta.*img(isw) + .alpha.*(1-beta).*img(ine) + .alpha.*beta.*img(ise);img2 = reshape(img2,h,w);imagesc(img2);%build_pyramidfunction pyr,imp = build_pyramid(img,levels,scl)img2 = img;img2 = resample_bilinear(img2,1/2);%img2 = imresize(img2,2,bilinear);sigma=1.5;%variance for laplacian filtersigma2=1.5;%variance for downsampling%expand to retain spatial frequencies %expand to retain spatial frequenciessig_delta = (1.6-.6)/levels;for i=1:levelsif i=1img3 = img2;img2 = filter_gaussian(img2,7,.5); %slightly filter bottom levelendimpi=img2;A = filter_gaussian(img2,7,sigma);%calculate difference of gaussiansB = filter_gaussian(A,7,sigma);pyri = A-B;%store result in cell arrayif i=1img2 = img3;elseB = filter_gaussian(img2,7,sigma2); B = filter_gaussian(B,7,sigma2);%anti-alias for downsamplingendimg2 = resample_bilinear(B,scl);%downsample for next levelend%show_pyramid(pyr)%show pyramid if desired%/function show_pyramid(pyr)close allh,w = size(pyr);for i=1:figureimagesc(pyri);colormap gray;end3function key = construct_key(px, py, img, sz)pct = .75;h,w = size(img);yoff,xoff = meshgrid(-1:1,-1:1);yoff = yoff(:)*pct;xoff = xoff(:)*pct;for i = 1:size(yoff,1)ctrx = px + xoff(i)*sz*2;%method using interpolated valuesctry = py + yoff(i)*sz*2;y,x = meshgrid(ctry-sz:sz/3:ctry+sz,ctrx-sz:sz/3:ctrx+sz);y=y(:);x=x(:);t = 0;c = 0;for k=1:size(y,1)if x(k)1 & y(k)1t = t + interp(img,x(k),y(k);c=c+1;endendif c=0cendt = t/c;key(i) = t;endkey = key/sum(key);4detect_featuresfunction features,pyr,imp,keys = detect_features(img, scl, disp_flag, thresh, radius, radius2, radius3, min_sep, edgeratio)if exist(scl)scl = 1.5;endif exist(thresh)thresh = 3;endif exist(radius)radius = 4;endif exist(radius2)radius2 = 4;endif exist(radius3)radius3 = 4;endif exist(min_sep)min_sep = .04;endif exist(edgeratio)edgeratio = 5;endif exist(disp_flag)disp_flag = 0;endif size(img,3) 1img = rgb2gray(img);end% Computation of the maximum number of levels: Lmax = floor(min(log(2*size(img)/12)/log(scl);%build image pyramid and difference of gaussians filter response pyramid pyr,imp = build_pyramid(img,Lmax,scl);%get the feature pointspts = find_features(pyr,img,scl,thresh,radius,radius2,disp_flag,1); %classify points and create sub-pixel and sub-scale adjustments features,keys = refine_features(img,pyr,scl,imp,pts,radius3,min_sep,edgeratio);5drawboxfunction drawbox(ang,sz,xc,yc,clr)ang=-ang;b = 1 1; -1 1; -1 -1; 1 -1; 1 1 * sz;t = sin(ang) cos(ang);cos(ang) -sin(ang);b = (t*b);b(:,2)=b(:,2)+xc;b(:,1)=b(:,1)+yc;plot(b(:,2),b(:,1),color,clr);6 eliminate_edgesfunction f2,k2 = eliminate_edges( features,keys);% 消除边缘 f2 = features(find(features(:,5)0),:);k2 = keys(find(features(:,5)0),:);7 f_classfunction cl, or=f_class(r)a = r(length(r) r r(1) r(2);b = (a(1:length(r)+1)-a(2:length(r)+2);b = b./abs(b);d = ones(1,length(r).*(b(1:length(r)b(2:length(r)+1);c = find(d);m = (r(c) c;m = sortrows(m,1);or(1) = (m(1,2)-1)*pi/length(r)*2;cl = 2;dst = m(:,1)-m(1,1);i=find(dst .3*(max(r)-min(r);cl = length(i);or = (m(i,2)-1)*pi/length(r)*2;8/ filter_gaussianfunction image_out = filter_gaussian(img,order,sig)img2 = img;for i=1:floor(order/2)%pad image borde
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号