?? imagecompressionandsolutioncompression.txt
字號:
?Die Liebe h?ret nimmer auf.: 數字圖象處理一 圖象壓縮與解壓縮
6月2日
數字圖象處理一 圖象壓縮與解壓縮
今天做的數字圖像處理實驗,一張圖片是之前用攝像機采集的,另一張圖片是今天實驗時經過離散沃爾什變換再量化編碼壓縮后又解壓所得,能看出區別嗎?呵呵。flik.m是原圖,newflik.m是新圖。
附上所有MATLAB源程序,有興趣的話,你也可以用這幾個程序對自己的照片“加工”一番。以下6個程序分別保存為6的m文件,文件名與下面給出的一致。待“加工”圖片應該存放在Matlab的Work目錄下。
文件名 compress.m
說明:flik.bmp是512*512的Windows位圖,你只要用你自己的512*512的Windows
bmp位圖的名字替換程序第一行中的參數flik就行了。一定要用512*512的bmp圖。
這是用于圖像壓縮的。
img=imread('flik.bmp');
img=im2double(img);
img2=blkproc(img,[16 16],'walsh(x)');
fileid=fopen('img.dat','w');
fileid2=fopen('data.dat','w');
filedata=[0];
filescaledata=[0];
lut=[8 8 8 8 8 8 8 8 4 4 4 4 4 4 4 4
8 8 4 4 4 4 4 4 4 4 2 2 2 2 2 2
8 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2
8 4 4 4 2 2 2 2 2 2 2 2 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0];
for i=1:16,
for j=1:16,
if lut(i,j)~=0,
[subdata,subscale]=quantizing(img2,lut(i,j),i,j);
filedata=[filedata,subdata];
filescaledata=[filescaledata,subscale];
end
end
end
filedata=filedata(2:length(filedata));
filescaledata=filescaledata(2:length(filescaledata));
fwrite(fileid,filedata,'ubit1');
fwrite(fileid2,filescaledata,'double');
fclose(fileid);
figure,imshow(img2)
文件名 decompress.m
說明:這是用于圖像解壓縮的,運行完畢后可以得到一個經過壓縮、量化、編碼、解碼、反量化、解壓的圖像,與原圖會有些許差異。不用改程序,直接拷貝建立一個新的m文件就行。
fileid=fopen('img.dat','r');
fileid2=fopen('data.dat','r');
filescaledata=fread(fileid2,'double');
filedata=fread(fileid,'ubit1');
filedata=filedata';
filescaledata=filescaledata';
filedata=double(filedata);
img3=zeros(512);
offset1=0;
offset2=0;
m=0;
lut=[8 8 8 8 8 8 8 8 4 4 4 4 4 4 4 4
8 8 4 4 4 4 4 4 4 4 2 2 2 2 2 2
8 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2
8 4 4 4 2 2 2 2 2 2 2 2 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
8 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
4 4 4 2 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 2 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0];
for i=1:16,
for j=1:16,
if lut(i,j)~=0,
img3=dequantizing(img3,filedata,filescaledata,lut(i,j),i,j,offset1,offset2);
m=m+1;
offset1=offset1+1024*lut(i,j);
offset2=2*m;
end
end
end
img4=blkproc(img3,[16 16],'dewalsh(x)');
fclose(fileid);
fclose(fileid2);
imshow(img4);axis off;
imwrite(img4,'newflik.bmp');
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -