·边缘检测(edge)边缘检测时先要把其他格式图像转化为灰度图像f=imread('lbxx.bmp');a=rgb2gray(f);[g,t]=edge(a,'canny');imshow(g)·剪贴(imcrop)、subplot等imfinfocolormapsubimageimaddimsubtractimmultiplyimdivideimresizeimrotate(旋转)a=imread('onion.png');b=imcrop(a,[7568130112]);%I2=IMCROP(I,RECT)%RECTisa4-elementvectorwiththeform[XMINYMINWIDTHHEIGHT];%subplot(121)一行两列的显示,当前显示第一个图片subplot(121);imshow(a);subplot(122);imshow(b);·roipoly选择图像中的多边形区域a=imread('onion.png');c=[200250278248199172];r=[21217512112175];b=roipoly(a,c,r);subplot(121);imshow(a);subplot(122);imshow(b);·roicolor按灰度值选择的区域a=imread('onion.png');i=rgb2gray(a);b=roicolor(i,128,255);subplot(121);imshow(a);subplot(122);imshow(b);·转化指定的多边形区域为二值掩膜poly2maskx=[631865419063];y=[606020920460];b=poly2mask(x,y,256,256);imshow(b);holdCurrentplotheldplot(x,y,'b','LineWidth',2)·roifilt2区域滤波a=imread('onion.png');i=rgb2gray(a);c=[200250278248199172];r=[21217512112175];b=roipoly(i,c,r);h=fspecial('unsharp');j=roifilt2(h,i,b);subplot(121),imshow(i);subplot(122),imshow(j);·roifill区域填充a=imread('onion.png');i=rgb2gray(a);c=[200250278248199172];r=[21217512112175];j=roifill(i,c,r);subplot(211);imshow(i);subplot(212);imshow(j);·FFT变换f=zeros(100,100);f(20:70,40:60)=1;imshow(f);F=fft2(f);F2=log(abs(F));imshow(F2),colorbar·补零操作和改变图像的显示象限f=zeros(100,100);f(20:70,40:60)=1;subplot(121);imshow(f);F=fft2(f,256,256);F2=fftshift(F);subplot(122);imshow(log(abs(F2)))·离散余弦变换(dct)a=imread('onion.png');i=rgb2gray(a);j=dct2(i);subplot(131);imshow(log(abs(j))),colorbarj(abs(j)10)=0;k=idct2(j);subplot(132);imshow(i);subplot(133);imshow(k,[0,255]);info=imfinfo('trees.tif')%显示图像信息·edge提取图像的边缘cannyprewittsobelradon函数用来计算指定方向上图像矩阵的投影a=imread('onion.png');i=rgb2gray(a);b=edge(i);theta=0:179;[r,xp]=radon(b,theta);figure,imagesc(theta,xp,r);colormap(hot);xlabel('\theta(degrees)');ylabel('x\prime');title('r_{\theta}(x\prime)');colorbar·filter2均值滤波a=imread('onion.png');i=rgb2gray(a);imshow(i)k1=filter2(fspecial('average',3),i)/255;%3*3k2=filter2(fspecial('average',5),i)/255;%5*5k3=filter2(fspecial('average',7),i)/255;%7*7figure,imshow(k1)figure,imshow(k2)figure,imshow(k3)wiener2滤波eg:k=wiener(I,[3,3]))medfilt2中值滤波同上deconvwnr维纳滤波??????????马赫带效应(同等差色带条)·减采样a=imread('football.jpg');b=rgb2gray(a);[wid,hei]=size(b);quarting=zeros(wid/2+1,hei/2+1);i1=1;j1=1;fori=1:2:widforj=1:2:heiquarting(i1,j1)=b(i,j);j1=j1+1;endi1=i1+1;j1=1;endfigureimshow(uint8(quarting))title('4倍减采样')quarting=zeros(wid/4+1,hei/4+1);i1=1;j1=1;fori=1:4:widforj=1:4:heiquarting(i1,j1)=b(i,j);j1=j1+1;endi1=i1+1;j1=1;endfigure,imshow(uint8(quarting));title('16倍减采样')结论:在采用不同的减采样过程中,其图像的清晰度和尺寸均发生了变化灰度级转化a=imread('football.jpg');b=rgb2gray(a);figure;imshow(b)[wid,hei]=size(b);img2=zeros(wid,hei);fori=1:widforj=1:heiimg2(i,j)=floor(b(i,j)/128);endendfigure;imshow(uint8(img2),[0,2])%2级灰度图像图像的基本运算i=imread('football.jpg');figure;subplot(231);imshow(i);title('原图');j=imadjust(i,[.3;.6],[.1.9]);%Adjustimageintensityvaluesorcolormap图像灰度值或colormap调整%J=IMADJUST(I,[LOW_IN;HIGH_IN],[LOW_OUT;HIGH_OUT])subplot(232);imshow(j);title('线性扩展');i1=double(i);i2=i1/255;c=2;k=c*log(1+i2);subplot(233);imshow(k);title('非线性扩展');m=255-i;subplot(234);imshow(m)title('灰度倒置')n1=im2bw(i,.4);n2=im2bw(i,.7);subplot(235);imshow(n1);title('二值化阈值0.4')subplot(236);imshow(n2);title('二值化阈值0.7')图像的代数运算加。减,乘法(获取感兴趣的区域)imresize放大a=imresize(I,2)%比例a=imresize(I,[3324])%非比例imrotate旋转a=imrotate(I,45)时域旋转多少度,频域也就旋转多少度i=zeros(256,256);i(88:168,124:132)=1;imshow(i)j=fft2(i);f=abs(j);j1=fftshift(f);figure;imshow(j1,[550])j=imrotate(i,90,'bilinear','crop');figure;imshow(j);j1=fft2(j);f=abs(j1);j2=fftshift(f);figure;imshow(j2,[550])边缘检测a=imread('kids.tif');subplot(211);imshow(a);title('pri')b=edge(a,'canny');subplot(212);imshow(b);title('by')figure,c=edge(a,'prewitt');imshow(c)腐蚀和膨胀a=imread('football.jpg');subplot(231);imshow(a);title('原灰度图像')t=graythresh(a);bw1=im2bw(a,t);se1=strel('square',3);se2=strel('square',5);bw2=imerode(bw1,se1);subplot(232);imshow(bw2)title('3*3腐蚀')bw3=imdilate(bw1,se1);subplot(233);imshow(bw3);title('3*3膨胀')bw4=imerode(bw1,se2);subplot(234);imshow(bw4);title('5*5腐蚀')bw5=imdilate(bw1,se2);subplot(235);imshow(bw5);title('5*5膨胀')log算子x=-2:.06:2;y=-2:.06:2;sigma=.6;y=y';fori=1:(4/.06+1)xx(i,:)=x;yy(:,i)=y;endr=1/(2*pi*sigma^4)*((xx.^2+yy.^2)/(sigma^2)-2).*exp(-(xx.^2+yy.^2)/(sigma^2));colormap(jet(16));mesh(xx,yy,r)分水岭算法分割图像f=imread('lbxx.bmp');f=rgb2gray(f);subplot(221);imshow(f)title('pri')subplot(222);f=double(f);hv=fspecial('prewitt');hh=hv.';gv=abs(imfilter(f,hv,'replicate'));gh=abs(imfilter(f,hh,'replicate'));g=sqrt(gv.^2+gh.^2);subplot(222);l=watershed(g);wr=l==0;imshow(wr);title('分水岭')f(wr)=255;subplot(223);imshow(uint8(f));title('(c)分割结果')rm=imregionalmin(g);subplot(224);imshow(rm);title('(d)局部极小值')区域生长法彩色基础rgb_r=zeros(512,512);rgb_r(1