matlab实现jpeg算法进行图像压缩的源代码(共10页).docx
《matlab实现jpeg算法进行图像压缩的源代码(共10页).docx》由会员分享,可在线阅读,更多相关《matlab实现jpeg算法进行图像压缩的源代码(共10页).docx(10页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、精选优质文档-倾情为你奉上function jpeg % THIS WORK IS SUBMITTED BY:% OHAD GAL%close all; % =% section 1.2 + 1.3% =% the following use of the function: % plot_bases( base_size,resolution,plot_type )% will plot the 64 wanted bases. I will use zero-padding for increased resolution% NOTE THAT THESE ARE THE SAME BAS
2、ES !% for reference I plot the following 3 graphs:% a) 3D plot with basic resolution (64 plots of 8x8 pixels) using surf function% b) 3D plot with x20 resolution (64 plots of 160x160 pixels) using mesh function% c) 2D plot with x10 resolution (64 plots of 80x80 pixels) using mesh function% d) 2D plo
3、t with x10 resolution (64 plots of 80x80 pixels) using imshow function% NOTE: matrix size of pictures (b),(c) and (d), can support higher frequency = higher bases% but I am not asked to draw these (higher bases) in this section !% the zero padding is used ONLY for resolution increase !% get all base
4、 pictures (3D surface figure)plot_bases( 8,1,surf3d ); % get all base pictures (3D surface figure), x20 resolutionplot_bases( 8,20,mesh3d ); % get all base pictures (2D mesh figure), x10 resolutionplot_bases( 8,10,mesh2d ); % get all base pictures (2D mesh figure), x10 resolutionplot_bases( 8,10,gra
5、y2d ); % =% section 1.4 + 1.5% =% for each picture 0.9 perform a 2 dimensional dct on 8x8 blocks.% save the dct inside a cell of the size: 10 cells of 128x128 matrix% show for each picture, its dct 8x8 block transform. for idx = 0:9 % load a picture switch idx case 0,1, input_image_128x128 = im2doub
6、le( imread( sprintf( %d.tif,idx ),tiff ) ); otherwise, input_image_128x128 = im2double( imread( sprintf( %d.tif,idx),jpeg ) ); end % perform DCT in 2 dimension over blocks of 8x8 in the given picture dct_8x8_image_of_128x128idx+1 = image_8x8_block_dct( input_image_128x128 ); if (mod(idx,2)=0) figure
7、; end subplot(2,2,mod(idx,2)*2+1); imshow(input_image_128x128); title( sprintf(image #%d,idx) ); subplot(2,2,mod(idx,2)*2+2); imshow(dct_8x8_image_of_128x128idx+1); title( sprintf(8x8 DCT of image #%d,idx) );end % =% section 1.6% =% do statistics on the cell array of the dct transforms% create a mat
8、rix of 8x8 that will describe the value of each dct-base % over the transform of the 10 given pictures. since some of the values are% negative, and we are interested in the energy of the coefficients, we will% add the abs()2 values into the matrix.% this is consistent with the definition of the Pars
9、eval relation in Fourier Coefficients % initialize the average matrix mean_matrix_8x8 = zeros( 8,8 ); % loop over all the picturesfor idx = 1:10 % in each picture loop over 8x8 elements (128x128 = 256 * 8x8 elements) for m = 0:15 for n = 0:15 mean_matrix_8x8 = mean_matrix_8x8 + . abs( dct_8x8_image_
10、of_128x128idx(m*8+1:8,n*8+1:8) ).2; end endend % transpose the matrix since the order of the matrix is elements along the columns,% while in the subplot function the order is of elements along the rowsmean_matrix_8x8_transposed = mean_matrix_8x8; % make the mean matrix (8x8) into a vector (64x1)mean
11、_vector = mean_matrix_8x8_transposed(:); % sort the vector (from small to big)sorted_mean_vector,original_indices = sort( mean_vector ); % reverse order (from big to small)sorted_mean_vector = sorted_mean_vector(end:-1:1);original_indices = original_indices(end:-1:1); % plot the corresponding matrix
12、 as asked in section 1.6figure;for idx = 1:64 subplot(8,8,original_indices(idx); axis off; h = text(0,0,sprintf(%4d,idx); set(h,FontWeight,bold); text(0,0,sprintf( n_%1.1fdb,20*log10(sorted_mean_vector(idx) );end % add a title to the figuresubplot(8,8,4);h = title( Power of DCT coefficients (section
13、 1.6) );set( h,FontWeight,bold ); % =% section 1.8% =% picture 8 is chosen% In this section I will calculate the SNR of a compressed image againts% the level of compression. the SNR calculation is defined in the header % of the function: which is given below.% if we decide to take 10 coefficients wi
14、th the most energy, we will add% zeros to the other coefficients and remain with a vector 64 elements long% (or a matrix of 8x8) % load the original imageoriginal_image = im2double( imread( 8.tif,jpeg ) ); % I will use this matrix to choose only the wanted number of coefficients% the matrix is initi
15、alized to zeros - dont choose any coefficient at allcoef_selection_matrix = zeros(8,8); % compressed picture set (to show the degrading)compressed_set = 1 3 5 10 15 20 30 40; % this loop will choose each time, the next-most-energetic coefficient, % to be added to the compressed image - and thus to i
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 实现 jpeg 算法 进行 图像 压缩 源代码 10
限制150内