function varargout = imDCT(varargin)
% IMDCT M-file for imDCT.fig
% IMDCT, by itself, creates a new IMDCT or raises the existing
% singleton*.
%
% H = IMDCT returns the handle to a new IMDCT or the handle to
% the existing singleton*.
%
% IMDCT('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in IMDCT.M with the given input arguments.
%
% IMDCT('Property','Value',...) creates a new IMDCT or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before imDCT_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to imDCT_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help imDCT
% Last Modified by GUIDE v2.5 07-Jun-2021 19:54:09
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @imDCT_OpeningFcn, ...
'gui_OutputFcn', @imDCT_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before imDCT is made visible.
function imDCT_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to imDCT (see VARARGIN)
% Choose default command line output for imDCT
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes imDCT wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = imDCT_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
ImgPath=get(handles.edit1,'String');
CompressRate=uint8(fix(str2num(get(handles.edit2,'String'))));
if CompressRate>64
CompressRate=64;
end
if CompressRate<1
CompressRate=1;
end
set(handles.edit2,'String',num2str(CompressRate));
img=imread(ImgPath);
axes(handles.axes1);
imshow(img);
set(handles.text7,'Visible','off');
set(handles.text7,'String','处理状态:正在处理中...');
set(handles.text7,'Visible','on');
pause(0.1);
Block=ceil(size(img)/8);
ImgDCT=zeros(Block*8);
ImgRestoreTemp=zeros(Block*8);
ImgRestore=zeros(size(img));
ImgBlock=zeros(8);
DCTBlock=zeros(8);
vector=zeros(1,64);
for ii=1:Block(1)
for jj=1:Block(2)
ImgBlock(:,:)=zeros(8);
if ii==Block(1)
if jj==Block(2)
ImgBlock(1:size(img,1)-(ii-1)*8,1:size(img,2)-(jj-1)*8)=img((ii-1)*8+1:size(img,1),(jj-1)*8+1:size(img,2));
else
ImgBlock(1:size(img,1)-(ii-1)*8,:)=img((ii-1)*8+1:size(img,1),(jj-1)*8+1:jj*8);
end
else
if jj==Block(2)
ImgBlock(:,1:size(img,2)-(jj-1)*8)=img((ii-1)*8+1:ii*8,(jj-1)*8+1:size(img,2));
else
ImgBlock(:,:)=img((ii-1)*8+1:ii*8,(jj-1)*8+1:jj*8);
end
end
DCTBlock(:,:)=dct2(ImgBlock(:,:));
if CompressRate~=64
vector(1:64)=m2v(DCTBlock(:,:));
vector(CompressRate+1:64)=0;
DCTBlock(:,:)=v2m(vector(1:64));
end
ImgDCT((ii-1)*8+1:ii*8,(jj-1)*8+1:jj*8)=DCTBlock(:,:);
end
end
for ii=1:Block(1)
for jj=1:Block(2)
DCTBlock(:,:)=ImgDCT((ii-1)*8+1:ii*8,(jj-1)*8+1:jj*8);
ImgBlock(:,:)=idct2(DCTBlock(:,:));
ImgRestoreTemp((ii-1)*8+1:ii*8,(jj-1)*8+1:jj*8)=ImgBlock(:,:);
end
end
ImgRestore(:,:)=ImgRestoreTemp(1:size(ImgRestore,1),1:size(ImgRestore,2));
ImgRestore=uint8(ImgRestore);
ErrorTemp=imabsdiff(img,ImgRestore);
MSE=sum(sum(ErrorTemp.*ErrorTemp))/(size(img,1)*size(img,2));
PSNR=10*log(65535/MSE);
strPSNR=['PSNR:',num2str(PSNR)];
axes(handles.axes2);
imshow(ImgRestore);
imwrite(ImgRestore,'GIRL2.BMP','bmp');
set(handles.text7,'String','处理状态:处理完成!');
set(handles.text8,'String',strPSNR);
set(handles.text8,'Visible','on');
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
function vector=m2v(matrix)
subscript=[1,2,6,7,15,16,28,29;...
3,5,8,14,17,27,30,43;...
4,9,13,18,26,31,42,44;...
10,12,19,25,32,41,45,54;...
11,20,24,33,40,46,53,55;...
21,23,34,39,47,52,56,61;...
22,35,38,48,51,57,60,62;...
36,37,49,50,58,59,63,64];
vectorTemp=zeros(1,64);
for ii=1:8
for jj=1:8
vectorTemp(subscript(ii,jj))=matrix(ii,jj);
end
end
vector=vectorTemp;
function matrix=v2m(vector)
subscript=[1,2,6,7,15,16,28,29;...
3,5,8,14,17,27,30,43;...
4,9,13,18,26,31,42,44;...
10,12,19,25,32,41,45,54;...
11,20,24,33,40,46,53,55;...
21,23,34,39,47,52,56,61;...
22,35,38,48,51,57,60,62;...
36,37,49,50,58,59,63,64];
matrixTemp=zeros(8,8);
for ii=1:8
for jj=1:8
matrixTemp(ii,jj)=vector(subscript(ii,jj));
end
end
matrix=matrixTemp;
没有合适的资源?快使用搜索试试~ 我知道了~
图像压缩基于matlab GUI DCT图像压缩(压缩率可调)【含Matlab源码 1049期】.zip
共5个文件
bmp:2个
m:1个
jpg:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 190 浏览量
2023-10-22
23:29:03
上传
评论
收藏 492KB ZIP 举报
温馨提示
CSDN海神之光上传的代码均可运行,亲测可用,直接替换数据即可,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描博客文章底部QQ名片; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作 图像压缩: BP神经网络图像压缩、DCT变换图像压缩、FFT图像压缩、霍夫曼图像压缩、JPEG图像压缩、小波变换图像压缩、分形编码图像压缩 行程编码图像压缩、蚁群算法优化小波变换图像压缩
资源推荐
资源详情
资源评论
收起资源包目录
【图像压缩】基于matlab GUI DCT图像压缩(压缩率可调)【含Matlab源码 1049期】.zip (5个子文件)
【图像压缩】基于matlab GUI DCT图像压缩(压缩率可调)【含Matlab源码 1049期】
imDCT.m 8KB
GIRL2.BMP 257KB
imDCT.fig 9KB
GIRL.bmp 257KB
运行结果.JPG 120KB
共 5 条
- 1
资源评论
- guangtai022024-03-10资源不错,对我启发很大,获得了新的灵感,受益匪浅。
海神之光
- 粉丝: 3w+
- 资源: 2089
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功