Codes HUFFMAN compression and decompression GUI

조회 수: 2 (최근 30일)
Jean Marcellino
Jean Marcellino 2016년 8월 20일
답변: aimad oumansour 2022년 11월 12일
can anyone tell me , or teach me about huffman compression and decompression in gui matlab , because i can't find it anywhere about turtorial to make coding about huffman compression or decompression. thanks , and forgive my bad english .
  댓글 수: 5
Jean Marcellino
Jean Marcellino 2016년 9월 7일
sir i have made some coding in GUI Matlab but i have trouble i can't show the images at axes 2 and idk how to fit the images in axes
Jean Marcellino
Jean Marcellino 2016년 9월 7일
편집: Walter Roberson 2016년 9월 7일
function varargout = test(varargin)
% TEST MATLAB code for test.fig
% TEST, by itself, creates a new TEST or raises the existing
% singleton*.
%
% H = TEST returns the handle to a new TEST or the handle to
% the existing singleton*.
%
% TEST('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TEST.M with the given input arguments.
%
% TEST('Property','Value',...) creates a new TEST or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before test_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to test_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 test
% Last Modified by GUIDE v2.5 20-Aug-2016 19:59:38
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @test_OpeningFcn, ...
'gui_OutputFcn', @test_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 test is made visible.
function test_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 test (see VARARGIN)
% Choose default command line output for test
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes test wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = test_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;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% 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)
[nama_file,nama_path] = uigetfile({'*.jpg','File Citra(*.jpg)';
'*.png','File PNG(*.png)';...
'*.tif','File TIF(*.tif)';...
'*.*','Semua File(*.*)'},...
'buka file citra asli');
if ~isequal(nama_file,0);
handles.citra=imread(fullfile(nama_path,nama_file));
red=handles.citra(:,:,1); %memisahkan warna merah dari image
r=red.';
green = handles.citra(:,:,2); % memisahkan warna hijau dari image
g=green.';
blue = handles.citra(:,:,3); % memisahkan warna biru dari image
b=blue.';
gbr = cat (3,r,g,b);
isequal(handles.citra,gbr)
gbr=double(gbr);
[handles.baris handles.kolom handles.layer]=size(gbr);
handles.jum=handles.baris*handles.kolom*handles.layer;
handles.data=(reshape(gbr,1,handles.jum));
handles.pjgasli=(length(handles.data))*8;
guidata(hObject,handles);
axes(handles.axes1);
imshow(handles.citra);
else
return;
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[nama_file_simpan, path_simpan]=uiputfile(...
{'*.huff','File kompres(*.huff)'},...
'Menyimpan File Citra Hasil Kompresi JPEG');
tic
h = waitbar(0,'Harap Tunggu...');
for i=1:100,
waitbar(i/100)
end
close(h)
%kompresihuff
[frek,nil]=hist(handles.data,unique(handles.data));
frek=frek/sum(frek);
handles.dict = huffmandict(nil,frek); % Create the dictionary.
hcode = huffmanenco(handles.data,handles.dict);
if ~isequal(nama_file_simpan,0)
shuff=strcat(path_simpan, nama_file_simpan);
save (shuff,'hcode');
else
return;
end
guidata(hObject,handles);
pjghuff=length(hcode);
ratio2=100-((pjghuff/handles.pjgasli)*100);
t2=toc;
set(handles.huf_rat,'String',ratio2);
set(handles.huf_pro,'String',t2);
set(handles.huff_size,'String',pjghuff);
% --- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[nama_file_huff,nama_path_huff] = uigetfile(...
{'*.huff','File kompres(*.huff)'},...
'Buka File Huffman');
if ~isequal(nama_file_huff,0)
hcode=importdata(fullfile(nama_path_huff, nama_file_huff));
else
return;
end
tic
h = waitbar(0,'Harap Tunggu...');
for i=1:100,
waitbar(i/100)
end
close(h)
%kompresihuff decode
dhsig = huffmandeco(hcode,handles.dict); % Decode the code.
hsl=uint8(reshape(dhsig,handles.baris,handles.kolom,handles.layer));
red = hsl(:,:,1); % memisahkan warna merah dari image
r=red.';
green = hsl(:,:,2); % memisahkan warna hijau dari image
g=green.';
blue = hsl(:,:,3); % memisahkan warna biru dari image
b=blue.';
hslhuff = cat (3,r,g,b);
isequal(hsl,hslhuff)
axes(handles.axes3);
imshow(hslhuff);
guidata(hObject,handles);
pjgdehuff=length(hslhuff);
ratio3=100-((pjgdehuff/handles.pjgasli)*100);
t3=toc;
set(handles.dehuff_rat,'String',ratio3);
set(handles.dehuff_pro,'String',t3);
set(handles.dehuff_size,'String',pjgdehuff);

댓글을 달려면 로그인하십시오.

답변 (1개)

aimad oumansour
aimad oumansour 2022년 11월 12일
Hi, we can sharing the interface GUI?

카테고리

Help CenterFile Exchange에서 Display Image에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by