⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 imagecompressionandsolutioncompression.txt

📁 一张图片是之前用摄像机采集的
💻 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 + -