資源描述:
《數(shù)字圖像處理實(shí)驗(yàn)程序matlab》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、實(shí)驗(yàn)一內(nèi)容(一)(1)彩色圖像變灰度圖像A=imread('1.jpg');B=rgb2gray(A);figuresubplot(1,2,1),imshow(A)title('原圖')subplot(1,2,2),imshow(B)title('原圖灰度圖像')(2)彩色圖像變索引圖像A=imread('1.jpg');figuresubplot(1,2,1),imshow(A)title('原圖')[X,map]=rgb2ind(A,128);subplot(1,2,2),imshow(X,map)title('原圖索引圖像')(3)彩色圖像變二值圖像A=imread('1.jp
2、g');figuresubplot(1,2,1),imshow(A)title('原圖')C=im2bw(A,0.2);subplot(1,2,2),imshow(C)title('原圖二值圖像')(4)灰度圖像變索引圖像(一)A=imread('1.jpg');figureB=rgb2gray(A);subplot(1,2,1),imshow(B)title('灰度圖像')C=grayslice(B,39);subplot(1,2,2),imshow(C)title('灰度變索引圖像')(5)灰度圖像變索引圖像(二)A=imread('1.jpg');figureB=rgb2gra
3、y(A);subplot(1,2,1),imshow(B)title('灰度圖像')[X,map]=gray2ind(B,63);subplot(1,2,2),imshow(X,map)title('灰度變索引圖像')(6)灰度圖像變彩色圖像A=imread('1.jpg');figureB=rgb2gray(A);subplot(1,2,1),imshow(B)title('灰度圖像')C=gray2rgb(B,map);subplot(1,2,2),imshow(C)title('灰度變彩色圖像')內(nèi)容(二)(1)灰度平均值A(chǔ)=imread('1.jpg');figureB=rg
4、b2gray(A);subplot(1,2,1),imshow(B)title('灰度圖像')B=double(B);[m,n]=size(B);sumg=0.0;fori=1:m;forj=1:n;sumg=sumg+B(i,j);endendavg=sumg/(m*n)%均值maxg=max(max(B))%區(qū)域最大灰度ming=min(min(B))%區(qū)域最小灰度(2)彩色平均值A(chǔ)=imread('1.jpg');figureimshow(A)title('彩色圖像')A=double(A);[m,n]=size(A);sumg=0.0;fori=1:m;forj=1:n;su
5、mg=sumg+A(i,j);endendavg=sumg/(m*n)squre=m*nmaxg=max(max(A))ming=min(min(A))內(nèi)容(三)采樣量化實(shí)驗(yàn)二圖像變換傅里葉變換、反變換、I=imread('19.jpg');A=rgb2gray(I);x1=fft2(A);x2=fftshift(x1);x3=ifft(x1)/10;figure,subplot(1,4,1);imshow(A)title('原圖');subplot(1,4,2);imshow(x1)title('頻譜圖');subplot(1,4,3);imshow(log(abs(x2)+1),
6、[010]);title('直流分量移至頻譜圖中心');subplot(1,4,4);imshow(x3,[010])title('傅里葉反變換');DCT變換、反變換X=imread('19.jpg');I=rgb2gray(X);subplot(1,3,1);imshow(I);title('原圖');subplot(1,3,2);J=dct2(I);imshow(log(abs(J)),[020]);title('二維離散余弦變換');subplot(1,3,3);K=idct2(J)/20;imshow(K,[020]);title('二維離散反余弦變換');利用DCT變換壓
7、縮圖像I=imread('19.jpg');A=rgb2gray(I);B=DCT2(A);B(abs(B)<0.1)=0;C=idct2(B)/255;figure,subplot(1,3,1);imshow(A);title('原圖');subplot(1,3,2);imshow(B);title('二維離散余弦變換頻譜圖');subplot(1,3,3);imshow(C);title('壓縮后圖像');實(shí)驗(yàn)三圖像增強(qiáng)(一)灰度圖像增強(qiáng)(1)線性變換