各种亚像素的边缘检测算法,比如矩,拟合,

  • 虫虫123456
    了解作者
  • matlab
    开发工具
  • 1.5KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 5 积分
    下载积分
  • 0
    下载次数
  • 2022-06-27 23:20
    上传日期
各种亚像素的边缘检测算法,比如矩,拟合,
grayju.rar
  • grayju.m
    6.4KB
内容介绍
%function [vp,hp,subvp,subhp] = grayju(ori,T,q) clear; clc; ori=imread('1.bmp'); ori=rgb2gray(ori); % ori=im2bw(ori,0.25); imshow(ori); tic; T1=25; q=0.5; I=double(ori); flag=0; % I=medfilt2(I); [h,v]=size(I); %load('w.mat'); w=[ 0 0.00913767235 0.021840193 0.02567188 0.021840193 0.00913767235 0 0.00913767235 0.02595156 0.025984481 0.025984481 0.025984481 0.02595156 0.00913767235 0.021840193 0.025984481 0.025984481 0.025984481 0.025984481 0.025984481 0.021840193 0.02567188 0.025984481 0.025984481 0.025984481 0.025984481 0.025984481 0.02567188 0.021840193 0.025984481 0.025984481 0.025984481 0.025984481 0.025984481 0.021840193 0.00913767235 0.02595156 0.025984481 0.025984481 0.025984481 0.02595156 0.00913767235 0 0.00913767235 0.021840193 0.02567188 0.021840193 0.00913767235 0 ]; k=1; z=1; Pi=3.1415926; % m0=conv2(w,I.^0); % m1=conv2(w,I); % m2=conv2(w,I.^2); % m3=conv2(w,I.^3); m0=imfilter(I.^0,w,'conv');%计算0123阶灰度矩 m1=imfilter(I,w,'conv'); m2=imfilter(I.^2,w,'conv'); m3=imfilter(I.^3,w,'conv'); A=abs(sqrt(m2-m1.^2)); s=(m3+2*m1.^3-3*m1.*m2)./A.^3; p1=0.5*(1+s.*sqrt(1./(4+s.^2))); p2=0.5*(1-s.*sqrt(1./(4+s.^2))); h1=m1-A.*sqrt(p2./p1); h2=m1+A.*sqrt(p1./p2); P=min(p1,p2); J=zeros(size(A)); T1=A>15; T2=abs(h2-h1)>2*A; J(T1&T2)=255; % imshow(J); for i=4:h-3 for j=4:v-3 if(J(i,j)>0) fun=@(t)t-0.5*sin(2*t)-Pi*P(i,j); t(z)=fzero(fun,1); r=cos(t(z)); z=z+1; if r<=2*0.5/7, II=I(i-3:i+3,j-3:j+3); sumI=sum(II(:))-I(i-3,j-3)-I(i+3,j+3)-I(i-3,j+3)-I(i+3,j-3); y0=imfilter(II,[ 0 ,i-3,i-3,i-3,i-3,i-3, 0 ; i-2,i-2,i-2,i-2,i-2,i-2,i-2; i-1,i-1,i-1,i-1,i-1,i-1,i-1; i , i , i , i , i , i , i ; i+1,i+1,i+1,i+1,i+1,i+1,i+1; i+2,i+2,i+2,i+2,i+2,i+2,i+2; 0 ,i+3,i+3,i+3,i+3,i+3, 0 ],'conv'); y0=y0(3,3)/sumI; x0=imfilter(II,[0 ,j-2,j-1,j,j+1,j+2, 0 ; j-3,j-2,j-1,j,j+1,j+2,j+3; j-3,j-2,j-1,j,j+1,j+2,j+3; j-3,j-2,j-1,j,j+1,j+2,j+3; j-3,j-2,j-1,j,j+1,j+2,j+3; j-3,j-2,j-1,j,j+1,j+2,j+3; 0, j-2,j-1,j,j+1,j+2, 0 ],'conv'); x0=x0(3,3)/sumI; sinQ=y0/sqrt(x0.^2+y0.^2); cosQ=x0/sqrt(x0.^2+y0.^2); vp(k)=j+7*r*cosQ/2; flag=1; hp(k)=i+7*r*sinQ/2; k=k+1; end end % % a=abs(sqrt(m2(i,j)-m1(i,j).^2)); % if a>15 % %计算p1,p2,h1,h2 % s=(m3(i,j)+2*m1(i,j).^3-3*m1(i,j)*m2(i,j))/a.^3; % p1=0.5*(1+s*sqrt(1/(4+s.^2))); % p2=0.5*(1-s*sqrt(1/(4+s.^2))); % h1=m1(i,j)-a*sqrt(p2/p1); % h2=m1(i,j)+a*sqrt(p1/p2); % if abs(h2-h1)>2*a % p(z)=min(p1,p2); % fun=@(t)t-0.5*sin(2*t)-Pi*p(z); % t(z)=fzero(fun,1); % r=cos(t(z)); % z=z+1; % if r<=2*0.5/7, % II=I(i-3:i+3,j-3:j+3); % sumI=sum(II(:))-I(i-3,j-3)-I(i+3,j+3)-I(i-3,j+3)-I(i+3,j-3); % y0=imfilter(II,[ 0 ,i-3,i-3,i-3,i-3,i-3, 0 ; % i-2,i-2,i-2,i-2,i-2,i-2,i-2; % i-1,i-1,i-1,i-1,i-1,i-1,i-1; % i , i , i , i , i , i , i ; % i+1,i+1,i+1,i+1,i+1,i+1,i+1; % i+2,i+2,i+2,i+2,i+2,i+2,i+2; % 0 ,i+3,i+3,i+3,i+3,i+3, 0 ],'conv'); % y0=y0(3,3)/sumI; % x0=imfilter(II,[0 ,j-2,j-1,j,j+1,j+2, 0 ; % j-3,j-2,j-1,j,j+1,j+2,j+3; % j-3,j-2,j-1,j,j+1,j+2,j+3; % j-3,j-2,j-1,j,j+1,j+2,j+3; % j-3,j-2,j-1,j,j+1,j+2,j+3; % j-3,j-2,j-1,j,j+1,j+2,j+3; % 0, j-2,j-1,j,j+1,j+2, 0 ],'conv'); % x0=x0(3,3)/sumI; % sinQ=y0/sqrt(x0.^2+y0.^2); % cosQ=x0/sqrt(x0.^2+y0.^2); % % vp(k)=j+7*r*cosQ/2; % flag=1; % hp(k)=i+7*r*sinQ/2; % k=k+1; % end % end % end end end toc; if flag==1 com=zeros(h,v); for b=1:k-1 com(round(hp(b)),round(vp(b)))=255; end com=uint8(com); figure(3);imshow(com);title('singlepixel outline'); % subvp=min(vp):0.01:max(vp); % subhp=interp1(vp,hp,subvp,'linear'); % figure();plot(subvp,subhp);str=sprintf('subposition(interp) T= %d,q=%d.',T1,q);title(str);%'T=',strcat(num2str(T)),'q=',strcat(num2str(q)), %figure();plot(vp,hp); else vp='inproper T or q'; hp='NO'; subhp=hp; subvp=vp; disp(vp); end %end
评论
    相关推荐