77范文网 - 专业文章范例文档资料分享平台

matlab实现jpeg算法进行图像压缩的源代码(2)

来源:网络收集 时间:2018-12-21 下载这篇文档 手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:或QQ: 处理(尽可能给您提供完整文档),感谢您的支持与谅解。点击这里给我发消息

% get input matrix size N = size(in,1);

% build the matrix n = 0:N-1; for k = 0:N-1 if (k>0)

C(k+1,n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N)*sqrt(2); else

C(k+1,n+1) = cos(pi*(2*n+1)*k/2/N)/sqrt(N); end end

out = (C')*in*C; %

---------------------------------------------------------------------------------

% plot_bases - use the inverse DCT in 2 dimensions to plot the base pictures %

% Note: we can get resolution be zero pading of the input matrix !!! % that is by calling: in = zeros(base_size*resolution) % where: resolution is an integer > 1 % So I will use zero pading for resolution (same as in the fourier theory) % instead of linear interpolation. %

---------------------------------------------------------------------------------

function plot_bases( base_size,resolution,plot_type )

figure;

for k = 1:base_size for l = 1:base_size

in = zeros(base_size*resolution); in(k,l) = 1; % \for the \(k,l)\ subplot( base_size,base_size,(k-1)*base_size+l ); switch lower(plot_type)

case 'surf3d', surf( pdip_inv_dct2( in ) ); case 'mesh3d', mesh( pdip_inv_dct2( in ) );

case 'mesh2d', mesh( pdip_inv_dct2( in ) ); view(0,90); case 'gray2d', imshow( 256*pdip_inv_dct2( in ) ); end axis off; end end

% add a title to the figure

subplot(base_size,base_size,round(base_size/2));

h = title( 'Bases of the DCT transform (section 1.3)' ); set( h,'FontWeight','bold' ); %

---------------------------------------------------------------------------------

% image_8x8_block_dct - perform a block DCT for an image %

---------------------------------------------------------------------------------

function transform_image = image_8x8_block_dct( input_image )

transform_image = zeros( size( input_image,1 ),size( input_image,2 ) ); for m = 0:15 for n = 0:15

transform_image( m*8+[1:8],n*8+[1:8] ) = ...

pdip_dct2( input_image( m*8+[1:8],n*8+[1:8] ) ); end end %

---------------------------------------------------------------------------------

% image_8x8_block_inv_dct - perform a block inverse DCT for an image %

---------------------------------------------------------------------------------

function restored_image = image_8x8_block_inv_dct( transform_image )

restored_image =

zeros( size( transform_image,1 ),size( transform_image,2 ) ); for m = 0:15 for n = 0:15

restored_image( m*8+[1:8],n*8+[1:8] ) = ...

pdip_inv_dct2( transform_image( m*8+[1:8],n*8+[1:8] ) ); end end %

---------------------------------------------------------------------------------

% calc_snr - calculates the snr of a figure being compressed %

% assumption: SNR calculation is done in the following manner: % the deviation from the original image is considered % to be the noise therefore: %

% noise = original_image - compressed_image %

% the SNR is defined as: %

% SNR = energy_of_image/energy_of_noise %

% which yields: %

% SNR =

energy_of_image/((original_image-compressed_image)^2) %

---------------------------------------------------------------------------------

function SNR = calc_snr( original_image,noisy_image )

original_image_energy = sum( original_image(:).^2 );

noise_energy = sum( (original_image(:)-noisy_image(:)).^2 ); SNR = original_image_energy/noise_energy;

以下是1-9号原图像,放到matlab的.m文件目录里,重命名9个图像名为1、2、3、4、5、6、7、8、9

百度搜索“77cn”或“免费范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,免费范文网,提供经典小说综合文库matlab实现jpeg算法进行图像压缩的源代码(2)在线全文阅读。

matlab实现jpeg算法进行图像压缩的源代码(2).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印 下载失败或者文档不完整,请联系客服人员解决!
本文链接:https://www.77cn.com.cn/wenku/zonghe/380480.html(转载请注明文章来源)
Copyright © 2008-2022 免费范文网 版权所有
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ: 邮箱:tiandhx2@hotmail.com
苏ICP备16052595号-18
× 注册会员免费下载(下载后可以自由复制和排版)
注册会员下载
全站内容免费自由复制
注册会员下载
全站内容免费自由复制
注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: