边缘检测时先要把其他格式图像转化为灰度图像 >> f=imread('lbxx.bmp'); >> a=rgb2gray(f);
>> [g,t]=edge(a,'canny'); >> imshow(g)
·剪贴(imcrop)、subplot等 imfinfo colormap subimage
imadd imsubtract immultiply imdivide imresize imrotate(旋转)
>> a=imread('onion.png');
>> b=imcrop(a,[75 68 130 112]); % I2 = IMCROP(I,RECT)
% RECT is a 4-element vector with the form [XMIN YMIN WIDTH HEIGHT]; % subplot(121)一行两列的显示,当前显示第一个图片 >> subplot(121);imshow(a); >> subplot(122);imshow(b);
·roipoly选择图像中的多边形区域 >> a=imread('onion.png');
>> c=[200 250 278 248 199 172]; >> r=[21 21 75 121 121 75]; >> 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);
·转化指定的多边形区域为二值掩膜 poly2mask
>> x=[63 186 54 190 63]; >> y=[60 60 209 204 60]; >> b=poly2mask(x,y,256,256); >> imshow(b); >> hold
Current plot held
>> plot(x,y,'b','LineWidth',2)
·roifilt2区域滤波 a=imread('onion.png'); i=rgb2gray(a);
c=[200 250 278 248 199 172]; r=[21 21 75 121 121 75]; 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=[200 250 278 248 199 172]; >> r=[21 21 75 121 121 75]; >> 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))),colorbar >> j(abs(j)<10)=0; >> k=idct2(j);
>> subplot(132);imshow(i);
>> subplot(133);imshow(k,[0,255]); info=imfinfo('trees.tif')%显示图像信息
·edge提取图像的边缘 canny prewitt sobel
radon函数用来计算指定方向上图像矩阵的投影 >> 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('\heta(degrees)'); >> ylabel('x\\prime');
>> title('r_{\heta}(x\\prime)'); >> colorbar
·filter2均值滤波 >> a=imread('onion.png'); >> i=rgb2gray(a); >> imshow(i)
>> k1=filter2(fspecial('average',3),i)/255;%3*3 >> k2=filter2(fspecial('average',5),i)/255;%5*5 >> k3=filter2(fspecial('average',7),i)/255;%7*7 >> figure,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; >> for i=1:2:wid for j=1:2:hei
quarting(i1,j1)=b(i,j); j1=j1+1; end
i1=i1+1; j1=1; end
>> figure
>> imshow(uint8(quarting)) >> title('4倍减采样')
>> quarting=zeros(wid/4+1,hei/4+1); i1=1;j1=1;
for i=1:4:wid for j=1:4:hei
quarting(i1,j1)=b(i,j); j1=j1+1; end
i1=i1+1; j1=1; end
>> figure,imshow(uint8(quarting)); title('16倍减采样')
结论:在采用不同的减采样过程中,其图像的清晰度和尺寸均发生了变化 灰度级转化
>> a=imread('football.jpg'); >> b=rgb2gray(a); >> figure;imshow(b) >> [wid,hei]=size(b); >> img2=zeros(wid,hei); >> for i=1:wid for j=1:hei
img2(i,j)=floor(b(i,j)/128); end end
>> figure;imshow(uint8(img2),[0,2]) %2级灰度图像
图像的基本运算
>> i=imread('football.jpg');
>> figure;subplot(231);imshow(i); >> title('原图');
>> j=imadjust(i,[.3;.6],[.1 .9]);
%Adjust image intensity values or colormap图像灰度值或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,[33 24]) %非比例
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,[5 50]) >> j=imrotate(i,90,'bilinear','crop'); >> figure;imshow(j);
>> j1=fft2(j);f=abs(j1);j2=fftshift(f); >> figure;imshow(j2,[5 50])
边缘检测
>> 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'; >> for i=1:(4/.06+1) xx(i,:)=x; yy(:,i)=y; end
>> r=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:256,257:512)=1; >> rgb_g=zeros(512,512); >> rgb_g(1:256,1:256)=1;
>> rgb_g(257:512,257:512)=1; >> rgb_b=zeros(512,512); >> rgb_b(257:512,1:256)=1; >> rgb=cat(3,rgb_r,rgb_g,rgb_b);
>> figure,imshow(rgb),title('rgb彩色图像')
将上题转化到HIS空间 模糊H分量,得到
rgb=imread('football.jpg'); rgb1=im2double(rgb); r=rgb1(:,:,1); g=rgb1(:,:,2); b=rgb1(:,:,3); i=(r+g+b)/3;
tmp1=min(min(r,g),b);
tmp2=r+g+b;tmp2(tmp2==0)=eps; s=1-3.*tmp1./tmp2; tmp1=.5*((r-g)+(r-b));
tmp2=sqrt((r-g).^2+(r-b).*(g-b)); theta=acos(tmp1./(tmp2+eps)); h=theta;
h(b>g)=2*pi-h(b>g); h=h/(2*pi); h(s==0)=0;
subplot(231);imshow(rgb);title('image') subplot(232);imshow(h),title('h') subplot(233);imshow(s),title('s') subplot(234);imshow(i),title('i')
h1=filter2(fspecial('average',25),h)/255; s1=filter2(fspecial('average',25),s)/255;
subplot(235);imshow(mat2gray(h1)),title('h模糊结果') hsi=cat(3,h1,s,i); h=hsi(:,:,1)*2*pi; s=hsi(:,:,2); i=hsi(:,:,3);
R=zeros(size(hsi,1),size(hsi,2)); G=zeros(size(hsi,1),size(hsi,2)); B=zeros(size(hsi,1),size(hsi,2)); ind=find((h>=0)&(h<2*pi/3)); B(ind)=i(ind).*(1.0-s(ind));
R(ind)=i(ind).*(1.0+s(ind).*cos(h(ind))./cos(pi/3.0-h(ind))); G(ind)=1.0-(R(ind)+B(ind));
ind=find((h>2*pi/3)&(h<4*pi/3)); h(ind)=h(ind)-pi*2/3;
r(ind)=i(ind).*(1.0-s(ind));
g(ind)=i(ind).*(1.0+s(ind).*cos(h(ind))./cos(pi/3.0-h(ind))); b(ind)=1.0-(R(ind)+G(ind)); ind=find((h>4*pi/3)&(h<2*pi)); h(ind)=h(ind)-pi*4/3;
g(ind)=i(ind).*(1.0-s(ind));
b(ind)=i(ind).*(1.0+s(ind).*cos(h(ind))./cos(pi/3.0-h(ind))); r(ind)=1.0-(G(ind)+B(ind)); RGB=cat(3,R,G,B);
subplot(236);imshow(RGB);title('处理后的图像') 结论:图像变柔和 (2)模糊S分量
将hsi=cat(3,h1,s,i);给为hsi=cat(3,h,s1,i);
结论:图像饱和度降低
边缘 clear
rgb_r=zeros(128,128); rgb_r(1:64,1:64)=1;
rgb_g=zeros(128,128); rgb_g(1:64,65:128)=1; rgb_b=zeros(128,128); rgb_b(65:128,1:64)=1;
rgb=cat(3,rgb_r,rgb_g,rgb_b); sob=fspecial('sobel');
rx=imfilter(double(rgb(:,:,1)),sob,'replicate'); ry=imfilter(double(rgb(:,:,1)),sob,'replicate'); gx=imfilter(double(rgb(:,:,2)),sob,'replicate'); gy=imfilter(double(rgb(:,:,2)),sob,'replicate'); bx=imfilter(double(rgb(:,:,3)),sob,'replicate'); by=imfilter(double(rgb(:,:,3)),sob,'replicate'); r_gradiant=mat2gray(max(rx,ry)); g_gradiant=mat2gray(max(gx,gy)); b_gradiant=mat2gray(max(bx,by));
rgb_gradiant=rgb2gray(cat(3,r_gradiant,g_gradiant,b_gradiant)); gxx=rx.^2+gx.^2+bx.^2; gyy=ry.^2+gy.^2+by.^2; gxy=rx.*ry+gx.*gy+bx.*by;
theta=.5*((atan(2*gxy./(gxx-gyy+eps))));
g1=.5*((gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta)); theta=theta+pi/2;
g2=.5*((gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta)); g1=g1.^5; g2=g2.^5;
rgb_vectorgradiant=mat2gray(max(g1,g2)); diff=abs(rgb_vectorgradiant-rgb_gradiant); subplot(331);imshow(rgb);title('彩色原图')
subplot(332);imshow(r_gradiant);title('R分量边缘') subplot(333);imshow(g_gradiant);title('G分量边缘') subplot(334);imshow(b_gradiant);title('B分量边缘') subplot(335);imshow(rgb_gradiant);title('分量合成边缘')
subplot(336);imshow(rgb_vectorgradiant);title('向量梯度边缘') subplot(337);imshow(diff);title('差别')
平滑再合成
锐化
rgb1=imread('football.jpg'); rgb=im2double(rgb1); fr=rgb(:,:,1);
fg=rgb(:,:,2); fb=rgb(:,:,3); lapmatrix=[1 1 1;1 -8 1;1 1 1];
fr_filtered=imfilter(fr,lapmatrix,'replicate'); fg_filtered=imfilter(fg,lapmatrix,'replicate'); fb_filtered=imfilter(fb,lapmatrix,'replicate');
rgb_tmp=cat(3,fr_filtered,fg_filtered,fb_filtered); rgb_filtered=imsubtract(rgb,rgb_tmp); i1=(fr+fg+fb)/3;
tmp1=min(min(fr,fg),fb); tmp2=fr+fg+fb;
tmp2(tmp2==0)=eps;% s=1-3.*tmp1./tmp2;
tmp1=.5*((fr-fg)+(fr-fb));
tmp2=sqrt((fr-fg).^2+(fr-fb).*(fg-fb)); theta=acos(tmp1./(tmp2+eps)); h1=theta;
h1(fb>fg)=2*pi-h1(fb>fg); h1=h1/(2*pi); h1(s==0)=0;
lapmatrix=[1 1 1;1 -8 1;1 1 1]; i=imfilter(i1,lapmatrix,'replicate') i=imfilter(i1,lapmatrix,'replicate'); subplot(331);imshow(rgb1);title('pri')
subplot(332);imshow(fr_flitered);title('fr_flitered') subplot(333);imshow(fg_filtered);title('fg_filtered') subplot(334);imshow(fb_filtered);title('fb_filtered') subplot(335);imshow(h1);title('h1') subplot(336);imshow(s);title('s') subplot(337);imshow(i1);title('i1')
subplot(338);imshow(rgb_tmp);title('mixture')
subplot(339);imshow(cat(3,h1,s,i1));title('hsi mixture')
彩色图像向量梯度的计算 >> rgb=imread('football.jpg'); >> sob=fspecial('sobel');
>> rx=imfilter(double(rgb(:,:,1)),sob,'replicate'); >> ry=imfilter(double(rgb(:,:,1)),sob','replicate'); >> gx=imfilter(double(rgb(:,:,2)),sob,'replicate'); gy=imfilter(double(rgb(:,:,2)),sob','replicate'); bx=imfilter(double(rgb(:,:,3)),sob,'replicate'); by=imfilter(double(rgb(:,:,3)),sob','replicate'); >> gxx=rx.^2+gx.^2+bx.^2; >> gyy=ry.^2+gy.^2+by.^2; >> gxy=rx.*ry+gx.*gy+bx.*by;
>> theta=.5*(atan(2*gxy./(gxx-gyy+eps)));
>> g1=.5*((gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta)); >> theta=theta+pi/2;
>> g2=.5*((gxx+gyy)+(gxx-gyy).*cos(2*theta)+2*gxy.*sin(2*theta)); >> g1=g1.^.5; >> g2=g2.^.5;
>> rgb_gradiant=mat2gray(max(g1,g2)); >> subplot(121);imshow(rgb);title('pri')
>> subplot(122);imshow(rgb_gradiant);title('rgb\\_gradiant')
得到图像边界,并计算周长、面积和重心坐标 >> a=imread('lbxx.bmp'); >> a1=bwperim(a); >> l=0;
>> [m,n]=size(a1); >> for i=1:m*n if(a1(i)==1) l=l+1; end end
>> [m,n]=size(a);s=0; >> for i=1:m*n if(a(i)==1) s=s+1; end end
>> x=0;y=0; >> for i=1:m for j=1:n if(a(i,j)==1) x=i+x;y=j+y; end end end
>> x=x/s;y=y/s; >> l,s,x,y
>> a=imread('trees.tif')%么有加;号
33 33 33 33 33 33 33 19 33 28 33 33 33 33 33 33 33 33 33 19 33 33 19 33 19 33 33 33 19 21 33 33 33 33 33 33 33 33 33 28 33 33 33 19 33 33 33 33 33 21 33 33 33 33 45 57 57 33 33 10 45 33 33 45 45 45 45 33 33 19 33 45 33 33 45 45 33 33 33 19 57 33 33 33 45 33 33 33 33 28 33 33 33 33 57 33 33 33 33 33 57 45 33 45 45 33 33 33 19 19 45 33 45 33 33 45 33 33 33 33 45 45 33 57 45 33 33 33 33 19 。。。。。。。。。。。。。。。。。。。 >> a=imread('trees.tif'); >> imshow(a) >> subplot(211) >> imshow(a) >> subplot(212) >> imshow(~a)
>> [x,map]=imread('trees.tif'); >> image(x);%显示矩阵x图像
>> Colormap(map)%设置颜色映射表,这样才可以将tif文件显示成彩色的
>> i=imread('trees.tif'); >> j=filter2([1 2 -1 -2],i); >> imshow(j,[])
>> i=imread('rice.png'); >> subplot(121)
>> imshow(i,[100 200]);%灰度范围为[100 200] >> subplot(122)
>> imshow(i,20)%灰度等级为20
>> load trees
>> a=[10 60];imagesc(X,a);Colormap(gray)
imshow rice.png %直接从磁盘显示,无需单独读入
>> a=imread('onion.png'); >> i=rgb2gray(a);
>> h=[1 2 1;0 0 0;-1 -2 -1];
>> i2=filter2(h,i);%使用二维滤波器h进行滤波 >> imshow(i2,[]) >> colorbar
显示单帧图像
>> mri=uint8(zeros(128,128,1,27)); >> for frame=1:27
[mri(:,:,:,frame),map]=imread('mri.tif',frame); end
>> imshow(mri(:,:,:,3),map);%显示第三帧
problem:如何知道一幅图像有几帧 显示多帧图像
>> montage(mri,map)
>> mov=immovie(mri,map); >> movie(mov) %播放动画
>> get(0,'ScreenDepth')
%获取计算机系统支持的像素点的位数 ans =
32
同时显示多幅图像,除了使用subplot-imshow外,也可以使用下面的方法 >> [x1,map1]=imread('forest.tif'); >> [x2,map2]=imread('trees.tif'); >> subplot(121),subimage(x1,map1) >> subplot(122),subimage(x2,map2)
纹理映射:2维转化为3维
>> [x,y,z]=cylinder; %新建一个柱形面 >> a=imread('peppers.png'); >> subplot(211)
>> warp(x,y,z,a); %插值映射 >> subplot(212);
>> imshow('peppers.png') >> title('2维') >> subplot(211); >> title('3维')
>> i=imread('rice.png'); >> subplot(121);
>> imshow(i);
>> title('原来的灰度图像') >> subplot(122); >> b=dither(i); %转化成二值图像 >> imshow(b);
>> title('转换后的二值图像')
索引图像转化为灰度图像 >> load trees
>> i=ind2gray(X,map); >> figure(1)
>> imshow(X,map) >> hold
Current plot held >> figure(2) >> imshow(i)
注意:不能再一个窗口的不同子窗口中既绘制灰度图像,又要绘制彩色图像 >> i=imread('rice.png'); >> figure(1) >> imshow(i)
>> title('原灰度图像') >> figure
>> [X,map]=gray2ind(i,6); >> imshow(X,map)
>> title('转换后的索引图像')
grayslice函数通过设定阈值将灰度图像转化为索引图像 >> i=imread('snowflakes.png'); >> x=grayslice(i,16); >> imshow(i) >> figure
>> imshow(x,jet(16))
mat2gray函数将一个数据矩阵转化为一个灰度图像 >> i=imread('rice.png');
>> j=filter2(fspecial('sobel'),i); >> k=mat2gray(j); >> imshow(i)
>> figure,imshow(k)
rgb2gary函数将真彩色图像转化为灰度图像 >> [x,map]=imread('rice.png'); >> np=rgb2gray(map);
Error using ==> rgb2gray>parse_inputs MAP must be a m x 3 array.
Error in ==> rgb2gray at 35 X = parse_inputs(varargin{:}); >> rgb=imread('peppers.png');
>> [X_nodither,map]=rgb2ind(rgb,8,'nodither'); >> [X_dither,map]=rgb2ind(8,'dither'); >> subplot(131),imshow(rgb);
>> subplot(132),imshow(X_nodither,map); %无抖动 >> subplot(133),imshow(X_dither,map) %有抖动
im2bw函数通过设定阈值将真彩、索引和灰度图像转化为二值图像 >> load trees
>> b=im2bw(X,map,.4); >> imshow(X,map) >> figure,imshow(b)
>> rgb=reshape(ones(64,1)*reshape(jet(64),1,192),[64,64,3]); >> hsv=rgb2hsv(rgb); >> h=hsv(:,:,1); >> s=hsv(:,:,2); >> v=hsv(:,:,3);
>> subplot(221)
>> imshow(h),title('色调')
>> subplot(222),imshow(s),title('饱和度') >> subplot(223),imshow(v),title('亮度')
>> subplot(224),imshow(h),title('原真彩色调色板')
>> rgb=imread('peppers.png'); >> yiq=rgb2ntsc(rgb);
>> subplot(121),imshow(rgb),title('原始rgb图像')
>> subplot(122),imshow(yiq(:,:,1)),title('变换后的ntsc图像')
>> rgb=imread('peppers.png'); >> hsv=rgb2hsv(rgb);
>> subplot(121),imshow(rgb),title('原始rgb图像') >> subplot(122),imshow(hsv),title('变换后的hsv图像')
>> rgb=imread('peppers.png'); >> ycbcr=rgb2ycbcr(rgb);
>> subplot(121),imshow(rgb),title('原始rgb图像')
>> subplot(122),imshow(ycbcr),title('变换后的ycbcr图像')
色彩重排
>> [x,map]=imread('canoe.tif'); >> [y,newmap]=cmpermute(x,map);
>>map
。。。。。。。。 >>newmap
。。。。。。。。
褪色前后
>> [x,map]=imread('canoe.tif'); >> [y,newmap]=imapprox(x,map,20); >> imshow(x,map)
>> figure,imshow(y,newmap)
>> [x,map]=imread('canoe.tif'); >> [y,newmap]=cmunique(x,map);
%由相同图像产生索引图像y和调色板newmap >> size(map)
ans =
256 3
>> size(newmap)
ans =
248 3
绘制调色板
>> [x,map]=imread('canoe.tif'); >> rgbplot(map)
图像轮廓线及直方图计算 >> i=imread('rice.png'); >> subplot(221) >> imshow(i);
>> title('原始图像') >> subplot(223) >> imcontour(i)
>> title('图像的轮廓线') >> subplot(122) >> imhist(i,64)
>> title('图像的直方图')
灰度倒置线性变换
>> d=imread('trees.tif'); >> colormap;
>> j=imadjust(d,[0 1],[1 0],1.5); >> subplot(121) >> imshow(d) >> subplot(122) >> subimage(j)
灰度直方图
>> i=imread('cameraman.tif'); >> subplot(121) >> imshow(i) >> subplot(122) >> imhist(i) >> axis square
imadjust示例
>> i=imread('cameraman.tif'); >> j=imadjust(i,[.15 .9],[0 1]); >> subplot(121) >> imshow(j) >> subplot(122) >> imhist(j) >> axis square
>> i=imread('cameraman.tif'); >> j=imadjust(i,[0 .2],[0.5 1]); >> subplot(221),imshow(i), >> subplot(222),imshow(j), >> subplot(223),imhist(i) >> subplot(224),imhist(j)
>> [x,map]=imread('forest.tif'); >> j=ind2gray(x,map);
>> j=imadjust(x,[],[],.5);
>> imshow(x) >> hold
Current plot held >> figure,imshow(j)
>> i=imread('tire.tif'); >> j=histeq(i);
>> subplot(221),imshow(i) >> title('原始图像')
>> subplot(222),imshow(j)
>> title('直方图均衡化处理以后的图像') >> subplot(223),imhist(i,64) >> title('原始图像直方图') >> subplot(224),imhist(j,64)
>> i=imread('pout.tif'); >> j=adapthisteq(i);
>> subplot(221),imshow(i) >> subplot(222),imshow(j) >> subplot(223),imhist(i) >> subplot(224),imhist(j)
>> i=imread('rice.png');
>> subplot(221),imshow(i),title('原图') >> i1=imnoise(i,'gaussian',0,.02);
>> subplot(222),imshow(i1),title('加入高斯噪声') >> i2=imnoise(i,'speckle',.02);
>> subplot(223),imshow(i2),title('加入乘性噪声') >> i3=imnoise(i,'salt',.02);
>> subplot(224),imshow(i3),title('加入椒盐噪声')
>> i=imread('rice.png');
>> i1=imnoise(i,'gaussian',0,.02);
>> subplot(121),imshow(i1),title('含噪图片') >> h=[1 1 1;1 1 1;1 1 1]; >> H=h/9;
>> j=conv2(i1,H);
Warning: CONV2 on values of class UINT8 is obsolete.
Use CONV2(DOUBLE(A),DOUBLE(B)) or CONV2(SINGLE(A),SINGLE(B)) instead. > In uint8.conv2 at 11 >> i=uint16(j);
>> subplot(122),imshow(j,[]) >> title('3*3均值滤波结果')
>> i=imread('eight.tif'); >> j=imnoise(i,'salt',.02); >> k=medfilt2(j);
>> subplot(121),imshow(j),title('含噪图片')
>> subplot(122),imshow(k),title('3*3中值滤波结果')
>> i=imread('eight.tif'); >> j=imnoise(i,'salt',.02); >> domain=[1 1 1;1 1 1;1 1 1]; >> k=ordfilt2(j,1,domain);
>> subplot(121),imshow(j),title('含噪图片')
>> subplot(122),imshow(k),title('3*3邻域的最小值滤波图片')
注意:找不到wiener函数
>> i=imread('eight.tif'); >> i=double(i); >> imshow(i,[])
>> h=[0 1 0;1 -4 0;0 1 0]; >> j=conv2(i,h,'same'); >> k=i-j; >> hold
Current plot held >> figure
>> imshow(k,[])
i=imread('eight.tif');
>> subplot(211),imshow(i),title('pri')
>> H=fspecial('laplacian');%应用laplacian滤波进行图像锐化 >> laplacianH=filter2(H,i);%在5*5邻域内进行维纳滤波 >> subplot(223),imshow(laplacianH) >> title('laplacian算子锐化图像') >> H=fspecial('prewitt'); >> prewittH=filter2(H,i);
>> subplot(224),imshow(prewittH)
>> title('prewitt模板锐化图像')
>> i=imread('saturn.png'); >> j=imnoise(i,'salt',.02);
>> subplot(121),imshow(j),title('含噪图片') >> j=double(j);f=fft2(j); >> g=fftshift(f); >> [m,n]=size(f); >> n=3;d0=20;
>> n1=floor(m/2);n2=floor(n/2); >> for i=1:m for j=1:n
d=sqrt((i-n1)^2+(j-n2)^2);h=1/(1+.414*(d/d0)^(2*n)); g(i,j)=h*g(i,j); end end
>> g=ifftshift(g);
>> g=uint8(real(ifft2(g))); >> subplot(122),imshow(g)
>> title('三阶巴特沃斯滤波结果')
>> rgb=imread('peppers.png');
>> subplot(221),imshow(rgb),title('pri')
>> subplot(222),imshow(rgb(:,:,1)),title('red part') >> subplot(223),imshow(rgb(:,:,2)),title('green part') >> subplot(224),imshow(rgb(:,:,3)),title('blue part')
因篇幅问题不能全部显示,请点此查看更多更全内容