Code covered by the BSD License  

Highlights from
Compression (shannon fano)

image thumbnail

Compression (shannon fano)

by

 

Compression (shannon fano) gui

codificacion(varargin)
function varargout = codificacion(varargin)

% CODIFICACION M-file for codificacion.fig
%      CODIFICACION, by itself, creates a new CODIFICACION or raises the existing
%      singleton*.
%
%      H = CODIFICACION returns the handle to a new CODIFICACION or the handle to
%      the existing singleton*.
%
%      CODIFICACION('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in CODIFICACION.M with the given input arguments.
%
%      CODIFICACION('Property','Value',...) creates a new CODIFICACION or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before codificacion_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to codificacion_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 codificacion

% Last Modified by GUIDE v2.5 09-Oct-2011 10:09:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @codificacion_OpeningFcn, ...
                   'gui_OutputFcn',  @codificacion_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 codificacion is made visible.
function codificacion_OpeningFcn(hObject, eventdata, handles, varargin)

jade=imread('marcojade.png');
image(jade)
axis off
% 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 codificacion (see VARARGIN)

% Choose default command line output for codificacion
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes codificacion wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = codificacion_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 caracteres_Callback(hObject, eventdata, handles)
% hObject    handle to caracteres (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 caracteres as text
%        str2double(get(hObject,'String')) returns contents of caracteres as a double


% --- Executes during object creation, after setting all properties.
function caracteres_CreateFcn(hObject, eventdata, handles)
% hObject    handle to caracteres (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 togglebutton1.
function togglebutton1_Callback(hObject, eventdata, handles)



captura=get(handles.caracteres,'string'); % se obtienen los caracteres
%letras=str2num(captura); % conversion----> NOTA: utilizando variables
%simbolicas, obtenidas directamente no es necesrio
vector=captura; % se almacena "captura" en la variable vector
syms X

cont1=0;
cont2=0;
cont3=0;
cont4=0;
cont5=0;
cont6=0;
cont7=0;
for n=1:1:7
    
    if vector(1)==vector(n)
        cont1=cont1+1;
    end
    
       if vector(2)==vector(1)
        cont2=0;
    
       elseif vector(2)==vector(n)
        cont2=cont2+1;
       end
       
           if (vector(3)==vector(2))||((vector(3)==vector(1)))
            cont3=0;
    
           elseif vector(3)==vector(n)
             cont3=cont3+1;
           end
           
                if (vector(4)==vector(3))||(vector(4)==vector(2))||(vector(4)==vector(1))
                cont4=0;
    
                elseif vector(4)==vector(n)
                 cont4=cont4+1;
                end
                
                     if (vector(5)==vector(4))||(vector(5)==vector(3))||(vector(5)==vector(2))||(vector(5)==vector(1))
                     cont5=0;
    
                     elseif vector(5)==vector(n)
                       cont5=cont5+1;
                     end   
                     
                     
                         if (vector(6)==vector(5))||(vector(6)==vector(4))||(vector(6)==vector(3))||(vector(6)==vector(2))||(vector(6)==vector(1))
                           cont6=0;
    
                         elseif vector(6)==vector(n)
                            cont6=cont6+1;
                         end
                         
                             if (vector(7)==vector(6))||(vector(7)==vector(5))||(vector(7)==vector(4))||(vector(7)==vector(3))||(vector(7)==vector(2))||(vector(7)==vector(1))
                                 cont7=0;
    
                             elseif vector(7)==vector(n)
                                 cont7=cont7+1;
                             end
                     
                     
end
       dig1=cont1;
       dig2=cont2;
       dig3=cont3;  
       dig4=cont4;
       dig5=cont5; 
       dig6=cont6; 
       dig7=cont7; 

  contadores=[dig1 dig2 dig3 dig4 dig5 dig6 dig7];
 
 if (dig1 ~= 0)
     car1=dig1*vector(1);
      
 else car1=0;
 end
 
 if (dig2 ~= 0)
    car2=dig2*vector(2);
 else car2=0;
 end
 
 if (dig3 ~= 0)
    car3=dig3*vector(3);
 else car3=0;
 end
 
 if (dig4 ~= 0)
    car4=dig4*vector(4);
 else car4=0;
 end
 
 if (dig5 ~= 0)
    car5=dig5*vector(5);
 else car5=0;
 end
 
 if (dig6 ~= 0)
    car6=dig6*vector(6);
 else car6=0;
 end
 
 if (dig7 ~= 0)
    car7=dig7*vector(7);
 else car7=0;
 end

 
res=[car1 car2 car3 car4 car5 car6 car7]

%convertir de ASCII a caracter el resultado anterior
  ca1=car1/dig1;
  cca1=char(ca1);
  
  ca2=car2/dig2;
  cca2=char(ca2);
  
  ca3=car3/dig3;
  cca3=char(ca3);
  
  ca4=car4/dig4;
  cca4=char(ca4);
  
  ca5=car5/dig5;
  cca5=char(ca5);
  
  ca6=car6/dig6;
  cca6=char(ca6);
  
  ca7=car7/dig7;
  cca7=char(ca7);
  
  letras=[cca1; cca2; cca3; cca4; cca5; cca6; cca7];
  
set(handles.visualiza,'string',letras)
set(handles.visualiza2,'string',contadores)

%desc=fliplr(contadores); ordena de forma descendente ---> NOTA: no
%funciono, no organiza de forma adecuada... no usar en una proxima ocacion
%utilizar comando de abajo funciona correctamente ;)
desc=fliplr(sort(contadores));
CrtOrd=[];%para visualizar
crtord=[0 0 0 0 0 0 0]; %para trabajar
contb=0; % contador para la codificacion binaria
for k=1:1:7
   
    if (desc(k)~=0)
    CrtOrd=[CrtOrd desc(k)];
    crtord(k)=desc(k);
    end
    if contadores(k)~=0
        contb=contb+1;
    end
    end
set(handles.visualiza3,'string',CrtOrd)

XX=inf;
if contb==7
    display('no se puede comprimir, todos los caracteres son diferentes')

elseif contb==6
  %  CrtOrd=[CrtOrd(1);CrtOrd(2);CrtOrd(3);CrtOrd(4);CrtOrd(5);CrtOrd(6)]
    codificacion=[0 0 XX; 0 1 XX; 0 0 1; 1 0 XX; 1 1 0; 1 1 1];
    set(handles.b1,'string',0)
    set(handles.b2,'string',0)
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',1)
    set(handles.b5,'string',1)
    set(handles.b6,'string',1)
    set(handles.b7,'string',1)
    set(handles.b8,'string',1)
    set(handles.b9,'string',0)
    set(handles.b10,'string',0)
    bistcod=[2 2 3 2 3 3];
elseif contb==5
   % CrtOrd=[CrtOrd(1);CrtOrd(2);CrtOrd(3);CrtOrd(4);CrtOrd(5)]
    codificacion=[0 0 XX; 0 1 XX; 1 0 XX; 1 1 0; 1 1 1];
    set(handles.b1,'string',0)
    set(handles.b2,'string',0)
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',1)
    set(handles.b5,'string',char(126))
    set(handles.b6,'string',1)
    set(handles.b7,'string',1)
    set(handles.b8,'string',1)
    set(handles.b9,'string',0)
    set(handles.b10,'string',0)
    bistcod=[2 2 2 3 3];
elseif contb==4
  %  CrtOrd=[CrtOrd(1);CrtOrd(2);CrtOrd(3);CrtOrd(4)]
    if crtord(1)==3
        codificacion=[0 XX XX; 1 0 XX; 1 1 0; 1 1 1];
    set(handles.b1,'string',0)
    set(handles.b2,'string',char(126))
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',char(126))
    set(handles.b5,'string',char(126))
    set(handles.b6,'string',1)
    set(handles.b7,'string',1)
    set(handles.b8,'string',1)
    set(handles.b9,'string',0)
    set(handles.b10,'string',0)
        bistcod=[1 2 3 3];
    else
        codificacion=[0 0; 0 1; 1 0; 1 1];
    set(handles.b1,'string',0)
    set(handles.b2,'string',0)
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',1)
    set(handles.b5,'string',char(126))
    set(handles.b6,'string',1)
    set(handles.b7,'string',1)
    set(handles.b8,'string',char(126))
    set(handles.b9,'string',char(126))
    set(handles.b10,'string',0)
        bistcod=[2 2 2 2];
    end
    
elseif contb==3
  %  CrtOrd=[CrtOrd(1);CrtOrd(2);CrtOrd(3)]
    codificacion=[0 XX ; 1 0; 1 1];
    set(handles.b1,'string',0)
    set(handles.b2,'string',char(126))
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',char(126))
    set(handles.b5,'string',char(126))
    set(handles.b6,'string',1)
    set(handles.b7,'string',1)
    set(handles.b8,'string',char(126))
    set(handles.b9,'string',char(126))
    set(handles.b10,'string',0)
    bistcod=[1 2 2];    
elseif contb==2
  %  CrtOrd=[CrtOrd(1);CrtOrd(2)]
    codificacion=[0;1];
    set(handles.b1,'string',0)
    set(handles.b2,'string',char(126))
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',char(126))
    set(handles.b5,'string',char(126))
    set(handles.b6,'string',1)
    set(handles.b7,'string',char(126))
    set(handles.b8,'string',char(126))
    set(handles.b9,'string',char(126))
    set(handles.b10,'string',char(126))
    bistcod=[1 1];
elseif contb==1
  %  CrtOrd=[CrtOrd(1)]
    codificacion=[0];
    set(handles.b1,'string',0)
    set(handles.b2,'string',char(126))
    set(handles.b3,'string',char(126))
    set(handles.b4,'string',char(126))
    set(handles.b5,'string',char(126))
    set(handles.b6,'string',char(126))
    set(handles.b7,'string',char(126))
    set(handles.b8,'string',char(126))
    set(handles.b9,'string',char(126))
    set(handles.b10,'string',char(126))
    bistcod=[1];
end
rf=num2str(codificacion);
set(handles.visualiza4,'string',rf)

entropia=[];
entropMSJ=[];
BTMSJ=[];
for k=1:1:contb    
    entropia=[entropia log2(7/CrtOrd(k))];
    entropMSJ(k)=[(CrtOrd(k))*(entropia(k))];
    BTMSJ(k)=CrtOrd(k)*bistcod(k);
   
end

set(handles.visualiza5,'string',entropia)

set(handles.visualiza6,'string',entropMSJ)

set(handles.visualiza7,'string',bistcod)

set(handles.visualiza8,'string',BTMSJ)

% hObject    handle to togglebutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton1


% --- Executes on button press in togglebutton3.
function togglebutton3_Callback(hObject, eventdata, handles)
    set(handles.b1,'string',char(32))
    set(handles.b2,'string', char(32))
    set(handles.b3,'string', char(32))
    set(handles.b4,'string', char(32))
    set(handles.b5,'string', char(32))
    set(handles.b6,'string', char(32))
    set(handles.b7,'string', char(32))
    set(handles.b8,'string', char(32))
    set(handles.b9,'string', char(32))
    set(handles.b10,'string', char(32))
    set(handles.visualiza,'string',char(32))
    set(handles.visualiza2,'string',char(32))
    set(handles.visualiza3,'string',char(32))
    set(handles.visualiza4,'string',char(32))
    set(handles.visualiza5,'string',char(32))
    set(handles.visualiza6,'string',char(32))
    set(handles.visualiza7,'string',char(32))
    set(handles.visualiza8,'string',char(32))

% hObject    handle to togglebutton3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hint: get(hObject,'Value') returns toggle state of togglebutton3

Contact us