DIP程序
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
• • • • • • • • • • • • • • • • • • • •
if S(i,j)>=0 & S(i,j)<=0.2 s_bin=0; elseif 0.2<S(i,j) & S(i,j)<=0.7 s_bin=1; elseif S(i,j)>0.7 s_bin=2; end if V(i,j)>=0 & V(i,j)<=0.2 v_bin=0; elseif 0.2<V(i,j) & V(i,j)<=0.7 v_bin=1; elseif V(i,j)>0.7 v_bin=2; end F(h_bin*9+s_bin*3+v_bin+1)=F(h_bin*9+s _bin*3+v_bin+1)+1; end end F2=F/N;
for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); h=1/(1+(d/d0)^(2*n)); result(i,j)=h*g(i,j); end end result=ifftshift(result); X2=ifft2(result); J=uint8(real(X2)); figure,imshow(J);
Optimal Edge Detection: Canny
•gray = imread('Fig0926(a)(rice).tif'); •I=edge(gray,'canny'); •figure, imshow(I);
Hough transform detecting circles
•Input image
• •
• •
•name='circle2.tif'; •x=imread(name); •y=edge(x,'canny');
Color descriptors
• • • • • • • • • • • • • • • • • • • • • • • •
•
function F2=colorFXhist6(x) H=x(:,:,1); S=x(:,:,2); V=x(:,:,3); [m,n]=size(H); N=m*n; t1=1/18; t2=1/9; t3=75/360; t4=155/360; t5=190/360; t6=270/360; t7=295/360; t8=315/360; for i=1:m for j=1:n if H(i,j)<=t1 | H(i,j)>t8 h_bin=0; elseif t1<H(i,j) & H(i,j)<=t2 h_bin=1; elseif t2<H(i,j) & H(i,j)<=t3 h_bin=2; elseif t3<H(i,j) & H(i,j)<=t4 h_bin=3; elseif t4<H(i,j) & H(i,j)<=t5 h_bin=4; elseif t5<H(i,j) & H(i,j)<=t6 h_bin=5; elseif t6<H(i,j) & H(i,j)<=t7 h_bin=6; elseif t7<H(i,j) & H(i,j)<=t8 h_bin=7; end
Gradient Operators in MATLAB
• • • • • • • • • I = imread(‘cameraman.tif'); BW1 = edge(I,'sobel'); %Sobel operators BW2 = edge(I,'roberts'); %Roberts operators BW3 = edge(I,'prewitt'); %Prewitt operators BW4 = edge(I,'log'); %LOG operators subplot(2,3,1),imshow(BW1) subplot(2,3,2),imshow(BW2) subplot(2,3,3),imshow(BW3) subplot(2,3,4),imshow(BW4)
Code of Hu’s Moment
• • • • • • • • • • • • • • • • • • • • • • • • • • function HuF = Hu_moment(image) image=double(image); m00=sum(sum(image)); m10=0;m01=0;m11=0;m20=0;m02=0;m21=0;m12=0; m30=0;m03=0; ux=0;uy=0; [row,col]=size(image); for i=1:row for j=1:col m10=m10+i*image(i,j); m01=m01+j*image(i,j); m11=m11+i*j*image(i,j); m20=m20+(i*i)*image(i,j); m02=m02+(j*j)*image(i,j); m21=m21+(i*i)*j*image(i,j); m12=m12+i*(j*j)*image(i,j); m30=m30+(i*i*i)*image(i,j); m03=m03+(j*j*j)*image(i,j); end end ux=m10/m00; uy=m01/m00; n00=m00; n10=0; n01=0; n11=m11-uy*m10; n20=m20-ux*m10; n02=m02-uy*m01; • • • • • • • • • • • • 43;2*ux*ux*m10; n03=m03-3*uy*m02+2*uy*uy*m01; n21=m21-2*ux*m11-uy*m20+2*ux*ux*m01; n12=m12-2*uy*m11-ux*m02+2*uy*uy*m10; n11=n11/m00^2; n20=n20/m00^2; n02=n02/m00^2; n30=n30/m00^2.5; n03=n03/m00^2.5; n12=n12/m00^2.5; n21=n21/m00^2.5; h1 = n20 + n02; h2 = (n20-n02)^2 + 4*(n11)^2; h3 = (n30-3*n12)^2 + (3*n21-n03)^2; h4 = (n30+n12)^2 + (n21+n03)^2; h5 = (n30-3*n12)*(n30+n12)*((n30+n12)^23*(n21+n03)^2)+(3*n21-n03)*(n21+n03)*(3*(n30+n12)^2(n21+n03)^2); h6 = (n20-n02)*((n30+n12)^2(n21+n03)^2)+4*n11*(n30+n12)*(n21+n03); h7 = (3*n21-n03)*(n30+n12)*((n30+n12)^23*(n21+n03)^2)+(3*n12-n30)*(n21+n03)*(3*(n30+n12)^2(n21+n03)^2); HuF= [h1 h2 h3 h4 h5 h6 h7];
Butterworth Lowpass Filter (cont…)
I=imread('aaa.tif');%将要滤波的图像读到I中 figure,imshow(I); f=double(I); g=fft2(f); g=fftshift(g); [N1,N2]=size(g); n=2; d0=15; %此处d0为截止频率,你可以依次 换成60、70、80进行滤波比较 n1=fix(N1/2); n2=fix(N2/2);
Gray Level Slicing
•a=210; •b=240;
•I=find(x<a); •y(I)=0; •I2=find(x>b); •y(I2)=0; •I3=find(x>=a&x<=b); •y(I3)=255;
•a=210; •b=240;
•I=find(x<a); •y(I)=255; •I2=find(x>b); •y(I2)=255; •I3=find(x>=a&x<=b); •y(I3)=x(I3);
•Exam: grayslicing.m
Ideal Low Pass Filter (cont…)
I=imread('aaa.tif');%将要滤波的图像读到I中 figure,imshow(I); f=double(I); g=fft2(f); g=fftshift(g); [N1,N2]=size(g); n=2; d0=15; %此处d0为截止频率,你可以依次 换成60、70、80进行滤波比较 n1=fix(N1/2); n2=fix(N2/2);
for i=1:N1 for j=1:N2 d=sqrt((i-n1)^2+(j-n2)^2); if d<=d0 result(i,j)=g(i,j); else result(i,j)=0; end end end result=ifftshift(result); X2=ifft2(result); J=uint8(real(X2)); figure,imshow(J,[]);