Está en la página 1de 55

Instituto Politécnico Nacional

Escuela Superior de Ingeniería


Mecánica y Eléctrica
Unidad Culhuacán

Teoría de la Información y Codificación


Practica 6
Codificación de Huffman
Integrantes:
Báez Velázquez Alberto
Benítez Barrios Carlos Alberto
Cruz De la cruz Carlos Andrés

Profesor:
José Eduardo Guzmán Rodríguez

Grupo: 7CM21
31/03/2020
Objetivo:
El alumno reconoce el algoritmo por el cual se lleva a cabo la Árbol
de código según Huffman codificación de Huffman.

CONSIDERACIONES GENERALES
Las practicas se entregan en una carpeta con el nombre de alguno de
los integrantes empezando por el apellido paterno, la carpeta debe
incluir en formato PDF o DOCX el reporte de la práctica, anexando
si es necesario el escaneo de los cálculos realizados en el cuaderno,
junto con el programa en MATLAB en la hora que corresponda al
laboratorio y en la fecha indicada, cualquier práctica recibida
después de la fecha no se tomará en cuenta para la calificación del
departamental. El día que se realiza la práctica se debe entregar un
programa funcional de manera individual (valor de 70%) y en la
próxima sesión se elige entre los integrantes el mejor programa y se
entrega ya terminado (valor 30%). Se tomará en cuenta para la
calificación del reporte: portada (O. I %), programa con GUI (20%),
desarrollo (.9%).

ANTECEDENTES
El algoritmo descrito por David Huffman asigna cada símbolo nodo
de un árbol de código binario. Estos nodos se ponderan por el
número de ocurrencias del símbolo correspondiente frecuencia o
costo.
La estructura del árbol resulta de combinar los nodos paso a paso
hasta que todos ellos estén incrustados en un árbol raíz. El algoritmo
siempre combina los dos nodos que proporcionan la frecuencia más
baja en un procedimiento ascendente. Los nuevos nodos interiores
obtienen la suma de las frecuencias de ambos nodos secundarios.
Árbol de código según Huffamn.

Las ramas del árbol representan los valores binarios 0 y l. La ruta


desde el árbol raíz hasta el nodo de hoja correspondiente define la
palabra de código concreta.
Ejemplo del código de Huffman.
El siguiente ejemplo se basa en una fuente de datos usando un
conjunto de cinco símbolos diferentes. Las frecuencias del símbolo
son:

Los dos símbolos menos frecuentes 'E' y están conectados primero,


seguidos por 'C' y Los nuevos nodos principales tienen la frecuencia
16 y 22 respectivamente y se unen en el siguiente paso. El nodo
resultante y el símbolo restante 'A' están subordinados al nodo raíz
que se Crea en un paso final.
Árbol de código según Huffman.
Los códigos de Huffman son árboles de código binario sin prefijo.
Los códigos generados por el algoritmo de Huffman alcanzan la
longitud ideal del código hasta el límite del bit. La desviación
máxima es menor que 1 bit.

El cálculo de la entropía da como resultado una longitud de código


promedio de 2.176 bits por símbolo en el supuesto de la distribución
mencionada. En contraste con esto, un código de Huffman alcanza
un promedio de 2.226 bits por símbolo. Por lo tanto, la codificación
de Huffman se acerca al óptimo en 97.74%.
Se puede lograr un resultado aún mejor solo con la codificación
aritmética, pero su uso está restringido por patentes.
Existen códigos que describen la construcción de árboles Huffman
de manera distinta, estos son "Código de Huffman Dinámico" y
"Código de Huffman Adaptativo".

DESARROLLO
1.- Encuentra la codificación de Huffman correspondiente a una
imagen compuesta por 8 intensidades de brillo con las siguientes
probabilidades: ½, 1/8, 1/8, 1/16,1/16, 1/16, 1/32 y 1/32.
2.- Aplica la codificación de Huffman a las siguientes imágenes:

3.- Calcula la eficiencia del código de Shannon - Fano de la practica


anterior y también calcula la eficiencia del código de Huffman.
¿Cuál de ellos es más eficiente?
*NOTA 1: Los puntos I y 3 se realizan en tu cuaderno.
4.- Al programa de MATLAB utilizado en las anteriores practicas
agrega la capacidad de que codifique un archivo de texto y de una
imagen (B/N, color, escala de grises) a través de la codificación de
Huffman.
*NOTA 2: Se tomará como 1 punto extra en la calificación de
examen si se al programa de Matlab agregas el código de Huffman
dinámico y adaptativo.
Comprobación en programa MATLAB
A) ARCHIVO DE TEXTO
function varargout = texto(varargin)
% UNTITLED MATLAB code for untitled.fig
% UNTITLED, by itself, creates a new UNTITLED or raises the existing
% singleton*.
%
% H = UNTITLED returns the handle to a new UNTITLED or the handle to
% the existing singleton*.
%
% UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in UNTITLED.M with the given input
arguments.
%
% UNTITLED('Property','Value',...) creates a new UNTITLED or raises
the
% existing singleton*. Starting from the left, property value pairs
are
% applied to the GUI before untitled_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property
application
% stop. All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 26-Mar-2020 23:45:48

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @texto_OpeningFcn, ...
'gui_OutputFcn', @texto_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 untitled is made visible.
function texto_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 untitled (see VARARGIN)

% Choose default command line output for untitled


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes untitled wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = texto_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;

%%%%%%%% TEXTO
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)
mensaje = get(hObject,'String');
handles.mensaje = mensaje;
guidata(hObject,handles);

%set(handles.uipanel1, 'Title', mensaje);


% 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

% BOTON PARA ESCRIBIR TEXTO Y CARGAR


% --- 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)
%mensaje = fread(fid,10000000,'uint8=>char')

%A = get(handles.edit1, 'string');

set(handles.uipanel1, 'Title', 'Decomponiendo');


B = dec2bin(handles.mensaje);
set(handles.listbox1,'String',B);

function bit_Callback(hObject, eventdata, handles)


% hObject handle to bit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cejas = get(handles.bit, 'value');

% Hints: get(hObject,'String') returns contents of bit as text


% str2double(get(hObject,'String')) returns contents of bit as a
double

% --- Executes during object creation, after setting all properties.


function bit_CreateFcn(hObject, eventdata, handles)
% hObject handle to bit (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 selection change in listbox1.


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

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1


contents as cell array
% contents{get(hObject,'Value')} returns selected item from
listbox1

% --- Executes during object creation, after setting all properties.


function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: listbox 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

% BOTON PARA CARGAR ARCHIVO DE TEXTO


% --- 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)

[archivo,ruta]=uigetfile({'*.txt;*UTF-8'}, 'Escoger')

dat_archivo = strcat(ruta, archivo);


%A = importdata(data_archivo,'t',1);

fid = fopen('pru.txt'); %cargamos el archivo

A = fread(fid,10000000,'uint8=>char')'; %
%disp('El archivo de texto se carga')
%disp('Su contenido del archivo .txt es')

%disp('presiones una tecla para continuar')


%pause;
fclose(fid);
handles.mensaje = A;
guidata(hObject,handles);
B = dec2bin(A);
C = bin2dec(B)';
%disp('El equivalente del archivo de texto es')
set(handles.listbox1,'String',B);
%set(handles.uipanel1,'String', A);

% --- Executes during object creation, after setting all properties.


function pushbutton2_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% --- 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)
H=0; %variable de entropia inicializada
S=0; %variable de fuente de información inicializada
simbolo=[];
veces = [];
ps = [];
is = [];
j = 1; %iterador para simbolos
k = 1;
l = 1;
m = 1;
%Este if lo ocupo para determinar la fuente de información
%Cuento cuales caracteres no repetidos hay en el mensaje
for i=32:255
caracter_sin_repetir = strfind(handles.mensaje, char(i));
if not(caracter_sin_repetir == 0)
S=S+1;
else
S=S+0;
end

end

for i=32:255 %todos los caracteres ascii escritos (recorre ascii


caracter por caracter)

dato=char(i); %convierte un tipo de datos en caracter


%length sirve para calcular longitud de una matriz o vector
%strfind
https://la.mathworks.com/help/matlab/ref/strfind.html#d117e91223
% encuentra en mensaje el patron dato veces se repite el caracter
total=length(strfind(handles.mensaje,dato));

p=total/S; %se obtiene la probabilidad del caraceter


p=#v.carecter/longitud de caracteres
p=total/length(handles.mensaje); %se obtiene la probabilidad del
caraceter p=#v.carecter/longitud de caracteres buena
in=log2(1/p);
if(total ~= 0)

simbolo(j) = dato; %para table vector


handles.simbolo(j) = simbolo(j);
guidata(hObject,handles);
veces(k) = total;
handles.veces(k)=veces(k);
guidata(hObject,handles);
handles.j=j;
guidata(hObject,handles);
ps(l) = p;
is(m) = in;

j=j+1;
k=k+1;
l=l+1;
m=m+1;

H=H+p*in;
end

end
simbolob = char(simbolo)
handles.simbolo =simbolo;
guidata(hObject,handles);
%datos = [cellstr(simbolob)' veces' ps' is];
% datos = [cellstr(simbolob)' num2cell(veces(:))' num2cell(ps(:))'
num2cell(is(:))']
datos = [cellstr(simbolob') num2cell(veces)' num2cell(ps)'
num2cell(is)'];
set(handles.uitable1,'data',datos)
set(handles.edit6,'String', H);
set(handles.edit7,'String',length(handles.mensaje));
%voy a hacer las variables globales
handles.simbolob= simbolob;
handles.veces=veces;
handles.ps=ps;
handles.is=is;
guidata(hObject,handles);

handles.H=H;
guidata(hObject,handles);

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a
double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 pushbutton10.


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

letra = char(handles.simbolo(1));
letra2 = char(handles.simbolo(2));
if(handles.j>2)
letra3 = char(handles.simbolo(3));
x = categorical({letra, letra2,letra3});
end

if(handles.j>3)
letra4 = char(handles.simbolo(4));
x = categorical({letra, letra2,letra3,letra4});
end

if(handles.j>4)
letra5 = char(handles.simbolo(5));
x = categorical({letra, letra2,letra3,letra4,letra5});
end

if(handles.j>5)
letra6 = char(handles.simbolo(6));
x = categorical({letra, letra2,letra3,letra4,letra5,letra6});
end

if(handles.j>6)
letra7 = char(handles.simbolo(7));
x = categorical({letra, letra2,letra3,letra4,letra5,letra6,letra7});
end

if (handles.j>7)
letra8 = char(handles.simbolo(8));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8});
end

if (handles.j>8)
letra9 = char(handles.simbolo(9));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8,letra9});
end

if (handles.j>9)
letra10 = char(handles.simbolo(10));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8,letra9,letra10});
end

if (handles.j>10)
letra11 = char(handles.simbolo(11));
x = categorical({letra,
letra2,letra3,letra4,letra5,letra6,letra7,letra8,letra9,letra10,letra11})
;
end

if(handles.j>1)
y = [handles.veces(1), handles.veces(2)];
end
if(handles.j>2)
y = [handles.veces(1), handles.veces(2), handles.veces(3)];
end
if(handles.j>3)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4)];
end
if(handles.j>4)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5)];
end
if(handles.j>5)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5), handles.veces(6)];
end
if(handles.j>6)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7)];
end
if(handles.j>7)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8)];
end
if(handles.j>8)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8),handles.veces(8)];
end
if(handles.j>9)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8),handles.veces(8),handles.veces(9)];
end
if(handles.j>10)
y = [handles.veces(1), handles.veces(2), handles.veces(3),
handles.veces(4),handles.veces(5),handles.veces(6),handles.veces(7),handl
es.veces(8),handles.veces(8),handles.veces(9),handles.veces(10)];
end
bar(x,y);

% --- Executes on button press in Long_promedio.


%Longitud promedio de la palabra codigo
function Long_promedio_Callback(hObject, eventdata, handles)
% La formla es li*pi
longitud = sum(handles.ps * length(dec2bin((((handles.simbolo))))));
set(handles.res_long_promedio, 'String', longitud);
handles.longitud = longitud;
guidata(hObject,handles);

function res_long_promedio_Callback(hObject, eventdata, handles)


% hObject handle to res_long_promedio (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 res_long_promedio as


text
% str2double(get(hObject,'String')) returns contents of
res_long_promedio as a double

% --- Executes during object creation, after setting all properties.


function res_long_promedio_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_long_promedio (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 Eficiencia de codigo


function Eficiencia_Callback(hObject, eventdata, handles)
%n = hr(S) / L
eficiencia = handles.H/handles.longitud;
handles.eficiencia = eficiencia;
guidata(hObject,handles);
set(handles.res_eficiencia, 'String', eficiencia);

function res_eficiencia_Callback(hObject, eventdata, handles)


% hObject handle to res_eficiencia (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 res_eficiencia as text


% str2double(get(hObject,'String')) returns contents of
res_eficiencia as a double

% --- Executes during object creation, after setting all properties.


function res_eficiencia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_eficiencia (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 redundancia.


function redundancia_Callback(hObject, eventdata, handles)
redundancia = 1 - handles.eficiencia;
set(handles.res_redundancia,'String',redundancia);

function res_redundancia_Callback(hObject, eventdata, handles)


% hObject handle to res_redundancia (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 res_redundancia as


text
% str2double(get(hObject,'String')) returns contents of
res_redundancia as a double

% --- Executes during object creation, after setting all properties.


function res_redundancia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_redundancia (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
B) ARCHIVO DE IMAGEN B/N

function varargout = archivo1(varargin)


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

% Last Modified by GUIDE v2.5 27-Mar-2020 01:21:37

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @archivo1_OpeningFcn, ...
'gui_OutputFcn', @archivo1_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 archivo1 is made visible.


function archivo1_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 archivo1 (see VARARGIN)

% Choose default command line output for archivo1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes archivo1 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = archivo1_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. "BOOOOOOOTON 1"
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)
[FileName, Path] = uigetfile({'*.jpg;.bmp'},'Abrir Imagen');
if isequal(FileName,0) %evalua si una matriz (A,B) son iguales para ver
si esta vacia y retornar la funcion
return
else %si la matriz no esta vacia entonces carga esa imagen
%imread carga la imagen FileName del directorio Path
%Strcat uno concatena varios string str = string, cat =concatena
imagen = imread(strcat(Path, FileName));
axes(handles.imagen);
imshow(imagen);
title 'Imagen RGB CARGADA'; xlabel 'eje x'; ylabel 'eje y';

%B imagen = imread('imagen.jpg'); %B
end
%handles es identificador de datos de la aplicación, almacena %id_global
handles.imagen=imagen; %B
guidata(hObject, handles)% A Y B salva los datos de la aplicación

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

% --- Executes on button press in pushbutton2. "BOOOOOOTON 2"


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)

binA = im2bw(handles.imagen);
handles.binA=binA;
guidata(hObject, handles)% salva los datos de la aplicación

imshow(binA)
title 'Imagen blanco y negro'; xlabel 'eje x'; ylabel 'eje y';
disp('A continuación mostraremos la matriz de valores binarios de B/N');
dimensiones = size(binA)
set(handles.size, 'String', strcat(num2str(dimensiones(1)),' x ',
num2str(dimensiones(2))) );

function size_Callback(hObject, eventdata, handles)


% hObject handle to size (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 size as text
% str2double(get(hObject,'String')) returns contents of size as a
double

% --- Executes during object creation, after setting all properties.


function size_CreateFcn(hObject, eventdata, handles)
% hObject handle to size (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 pixel_x_Callback(hObject, eventdata, handles)


% hObject handle to pixel_x (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 pixel_x as text


% str2double(get(hObject,'String')) returns contents of pixel_x as
a double
pixel_x = str2double (get (hObject, 'String' ))
handles.pixel_x = pixel_x;
guidata(hObject, handles);
pixel_x

% --- Executes during object creation, after setting all properties.


function pixel_x_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_x (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 pixel_y_Callback(hObject, eventdata, handles)


% hObject handle to pixel_y (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 pixel_y as text
% str2double(get(hObject,'String')) returns contents of pixel_y as
a double
pixel_y = str2double (get (hObject, 'String' ))
handles.pixel_y = pixel_y;
guidata(hObject, handles);
pixel_y

% --- Executes during object creation, after setting all properties.


function pixel_y_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_y (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 valor.


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

% --- Executes during object creation, after setting all properties.


function valor_CreateFcn(hObject, eventdata, handles)
% hObject handle to valor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% --- 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)
res = num2str(handles.binA(handles.pixel_x, handles.pixel_y))
res
set(handles.valor, 'String' , res);

% --- Executes on button press in pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
H=0; %variable de entropia inicializada
S=0; %variable de fuente de información inicializada
simbolo=[];
veces = [];
ps = [];
is = [];
j = 1; %iterador para simbolos
k = 1;
l = 1;
m = 1;

binCA = num2str(handles.binA); %binA es string


tam = size(binCA)
% S= unique(binCA)
S = 2;

P_x =0; %veces


P_y =0;

%calculo la probabilidad de 1 y 0
for x=1:9
for y = 1:11
if (handles.binA(x,y) == 1 )
P_x=P_x+1;
end
if (handles.binA(x,y) == 0 )
P_y=P_y+1;
end
end
end
prob1 = P_x/(P_x+P_y); %ps
prob2 = P_y/(P_x+P_y);

handles.prob1 = prob1;
handles.prob2 = prob2;
guidata(hObject,handles);

in1 = log2(1/prob1);
in2 = log2(1/prob2);
handles.in1 = in1;
handles.in2 = in2;
guidata(hObject,handles);

uno =1;
cero =0;
H=(in1+prob1)+(in2+prob2);
d= {1, P_x, prob1, in1 ; 0, P_y, prob2, in2 }
A= [1, P_x, prob1, in1 ];
B= [0, P_y, prob2, in2 ];
table = [A' B']
set(handles.uitable1,'data', d);
set(handles.edit5,'string',H);
handles.H=H;
guidata(hObject,handles);

handles.P_x=P_x;
guidata(hObject,handles);
handles.P_y=P_y;
guidata(hObject,handles);

function edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a
double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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)
% 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)
c = categorical({'Blanco','Negro'});
numa = handles.P_x;
numb = handles.P_y;
y = [ numa, numb];
axes(handles.histograma);
bar(c,y);

function res_long_Callback(hObject, eventdata, handles)


% hObject handle to res_long (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 res_long as text


% str2double(get(hObject,'String')) returns contents of res_long
as a double

% --- Executes during object creation, after setting all properties.


function res_long_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_long (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 lon_promedio.


function lon_promedio_Callback(hObject, eventdata, handles)
longitud = (1*handles.prob1+4*handles.prob2);

handles.longitud = longitud;
guidata(hObject,handles);
set(handles.res_long, 'String',longitud);

% --- Executes on button press in eficiencia.


function eficiencia_Callback(hObject, eventdata, handles)
eficiencia = (handles.H/handles.longitud)-1;
handles.eficiencia = eficiencia;
guidata(hObject,handles);
set(handles.res_eficiencia, 'String',eficiencia);

function res_eficiencia_Callback(hObject, eventdata, handles)


% hObject handle to res_eficiencia (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 res_eficiencia as text
% str2double(get(hObject,'String')) returns contents of
res_eficiencia as a double

% --- Executes during object creation, after setting all properties.


function res_eficiencia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_eficiencia (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 redundancia.


function redundancia_Callback(hObject, eventdata, handles)
redundancia = 1 - handles.eficiencia;
set(handles.res_redundancia, 'String',redundancia);

function res_redundancia_Callback(hObject, eventdata, handles)


% hObject handle to res_redundancia (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 res_redundancia as


text
% str2double(get(hObject,'String')) returns contents of
res_redundancia as a double

% --- Executes during object creation, after setting all properties.


function res_redundancia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_redundancia (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
C) ARCHIVO DE IMAGEN ESCALA A GRISES

function varargout = archivo1(varargin)


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

% Last Modified by GUIDE v2.5 27-Mar-2020 02:00:01


% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @archivo1_OpeningFcn, ...
'gui_OutputFcn', @archivo1_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 archivo1 is made visible.


function archivo1_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 archivo1 (see VARARGIN)

% Choose default command line output for archivo1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes archivo1 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = archivo1_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. "BOOOOOOOTON 1"


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)
[FileName, Path] = uigetfile({'*.jpg,*.bmp'},'Abrir Imagen');
if isequal(FileName,0) %evalua si una matriz (A,B) son iguales para ver
si esta vacia y retornar la funcion
return
else %si la matriz no esta vacia entonces carga esa imagen
%imread carga la imagen FileName del directorio Path
%Strcat uno concatena varios string str = string, cat =concatena
imagen = imread(strcat(Path, FileName));
axes(handles.imagen);
imshow(imagen);
title 'Imagen RGB CARGADA'; xlabel 'eje x'; ylabel 'eje y';

%B imagen = imread('imagen.jpg'); %B
end
%handles es identificador de datos de la aplicación, almacena %id_global
handles.imagen=imagen; %B
guidata(hObject, handles)% A Y B salva los datos de la aplicación

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

% --- Executes on button press in pushbutton2. "BOOOOOOTON 2"


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)
binA = rgb2gray(handles.imagen);%convertimos a escala de grises
handles.binA=binA;
guidata(hObject, handles)% salva los datos de la aplicación
imshow(binA)
title 'Imagen ESC GRISES '; xlabel 'eje x'; ylabel 'eje y';
disp('A continuación mostraremos la matriz de valores binarios de B/N');
dimensiones = size(binA)
set(handles.size, 'String', strcat(num2str(dimensiones(1)),' x ',
num2str(dimensiones(2))) );

function size_Callback(hObject, eventdata, handles)


% hObject handle to size (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 size as text


% str2double(get(hObject,'String')) returns contents of size as a
double

% --- Executes during object creation, after setting all properties.


function size_CreateFcn(hObject, eventdata, handles)
% hObject handle to size (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 pixel_x_Callback(hObject, eventdata, handles)


% hObject handle to pixel_x (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 pixel_x as text


% str2double(get(hObject,'String')) returns contents of pixel_x as
a double
pixel_x = str2num(get (hObject, 'String' ))
handles.pixel_x = pixel_x;
guidata(hObject, handles);
pixel_x

% --- Executes during object creation, after setting all properties.


function pixel_x_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_x (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 pixel_y_Callback(hObject, eventdata, handles)


% hObject handle to pixel_y (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 pixel_y as text


% str2double(get(hObject,'String')) returns contents of pixel_y as
a double
pixel_y = str2num (get (hObject, 'String' ))
handles.pixel_y = pixel_y;
guidata(hObject, handles);
pixel_y
% --- Executes during object creation, after setting all properties.
function pixel_y_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_y (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 valor.


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

% --- Executes during object creation, after setting all properties.


function valor_CreateFcn(hObject, eventdata, handles)
% hObject handle to valor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% --- 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)
res = num2str(handles.binA(handles.pixel_x, handles.pixel_y));
num_res = str2num(res);
res_bin = (dec2bin(num_res));
set(handles.valor, 'String' , (res_bin));

% --- Executes on selection change in listbox1.


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

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1


contents as cell array
% contents{get(hObject,'Value')} returns selected item from
listbox1
% --- Executes during object creation, after setting all properties.
function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: listbox 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 edit5_Callback(hObject, eventdata, handles)


% hObject handle to edit5 (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 edit5 as text


% str2double(get(hObject,'String')) returns contents of edit5 as a
double

% --- Executes during object creation, after setting all properties.


function edit5_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit5 (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 pushbutton4.


function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
entropia = entropy(handles.binA);
set(handles.edit5,'String',entropia);
handles.entropia= entropia;
guidata(hObject,handles);

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%OBTENCIÓN DE LAS DIMENSIONES PARA IMPRIMIRLAS EN PANTALLA
imagen_gris = handles.binA;
SZ = size(imagen_gris);
handles.SZ=SZ;
guidata(hObject,handles);

%USO LAS DIMENSIONES PARA MULTIPLICARLAS Y OBTENER NÚMERO DE MUESTRAS


muestras = SZ(1)*SZ(2);
handles.muestras = muestras;
guidata(hObject, handles);
set(handles.edit6,'String',muestras);

% Obtener el rango de los datos


valMin = min(min(imagen_gris(:,:)));
valMax = max(max(imagen_gris(:,:)));
handles.valMin = valMin;
guidata(hObject, handles);
handles.valMax = valMax;
guidata(hObject, handles);
Rango = valMax - valMin;
handles.Rango = Rango;

%calculos de frecuencia non-existent field 'pixy

%var_y = handles.pixel_y
blanco =0; gris = 0; negro =0;
for i = 1:SZ(1)
for y = 1:SZ(2)
if(imagen_gris(i,y) == 0)
negro=negro+1;
end
if(imagen_gris(i,y) == 127)
gris=gris+1;
end
if(imagen_gris(i,y) == 255)
blanco=blanco+1;
end

end
end
set(handles.edit7,'String',blanco);
set(handles.edit8,'String',gris);
set(handles.edit9,'String',negro);

%calculamos intervalos a utilizar


k = round(1+3.3*log(muestras));

%cantidad de datos potencialmente a incluir en cada inter. de clase


A= round(Rango/k)

%grafica de barras
c = categorical({'Negro','Gris','Blanco'});
%x = [255,127,0];
y = [negro, gris, blanco];
axes(handles.axes3);
bar(c,y);
handles.blanco = blanco;
handles.negro = negro;
handles.gris = gris;
guidata(hObject,handles);

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a
double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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 edit8_Callback(hObject, eventdata, handles)


% hObject handle to edit8 (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 edit8 as text


% str2double(get(hObject,'String')) returns contents of edit8 as a
double

% --- Executes during object creation, after setting all properties.


function edit8_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit8 (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 edit9_Callback(hObject, eventdata, handles)


% hObject handle to edit9 (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 edit9 as text


% str2double(get(hObject,'String')) returns contents of edit9 as a
double

% --- Executes during object creation, after setting all properties.


function edit9_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit9 (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 longitud.


%longitud promedio de coódigo
function longitud_Callback(hObject, eventdata, handles)
longitud = (4)*(handles.negro/handles.muestras)
+(2)*(handles.gris/handles.muestras)+(handles.blanco/handles.muestras);
set(handles.res_longitud,'String',longitud);
handles.longitud = longitud;
guidata(hObject,handles);

function res_longitud_Callback(hObject, eventdata, handles)


% hObject handle to res_longitud (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 res_longitud as text


% str2double(get(hObject,'String')) returns contents of
res_longitud as a double

% --- Executes during object creation, after setting all properties.


function res_longitud_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_longitud (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 eficiencia.


%EFICIENCIA
function eficiencia_Callback(hObject, eventdata, handles)
eficiencia = handles.entropia/ handles.longitud;
set(handles.res_eficiencia, 'String', eficiencia);
handles.eficiencia = eficiencia;
guidata(hObject, handles);

function res_eficiencia_Callback(hObject, eventdata, handles)


% hObject handle to res_eficiencia (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 res_eficiencia as text


% str2double(get(hObject,'String')) returns contents of
res_eficiencia as a double

% --- Executes during object creation, after setting all properties.


function res_eficiencia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_eficiencia (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 redundancia.


function redundancia_Callback(hObject, eventdata, handles)
redundancia = 1-handles.eficiencia;
set(handles.res_redundancia, 'String',redundancia);

function res_redundancia_Callback(hObject, eventdata, handles)


% hObject handle to res_redundancia (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 res_redundancia as


text
% str2double(get(hObject,'String')) returns contents of
res_redundancia as a double

% --- Executes during object creation, after setting all properties.


function res_redundancia_CreateFcn(hObject, eventdata, handles)
% hObject handle to res_redundancia (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

D) ARCHIVO DE IMAGEN A COLOR RGB

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

% Last Modified by GUIDE v2.5 09-Feb-2020 19:44:55

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @archivo1_OpeningFcn, ...
'gui_OutputFcn', @archivo1_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 archivo1 is made visible.


function archivo1_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 archivo1 (see VARARGIN)

% Choose default command line output for archivo1


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes archivo1 wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = archivo1_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. "BOOOOOOOTON 1"


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)
[FileName, Path] = uigetfile({'*.jpg;.bmp'},'Abrir Imagen');
if isequal(FileName,0) %evalua si una matriz (A,B) son iguales para ver
si esta vacia y retornar la funcion
return
else %si la matriz no esta vacia entonces carga esa imagen
%imread carga la imagen FileName del directorio Path
%Strcat uno concatena varios string str = string, cat =concatena
imagen = imread(strcat(Path, FileName));
imshow(imagen);
title 'Imagen RGB CARGADA'; xlabel 'eje x'; ylabel 'eje y';

%B imagen = imread('imagen.jpg'); %B
end
%handles es identificador de datos de la aplicación, almacena %id_global
handles.imagen=imagen; %B
guidata(hObject, handles)% A Y B salva los datos de la aplicación
dimensiones = size(imagen)
set(handles.size, 'String', strcat(num2str(dimensiones(1)),' x ',
num2str(dimensiones(2)), ' x',num2str(dimensiones(3))) );

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


% --- Executes on button press in pushbutton2. "BOOOOOOTON 2"
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)
dimensiones = size(binA)
set(handles.size, 'String', strcat(num2str(dimensiones(1)),' x ',
num2str(dimensiones(2))) );

function size_Callback(hObject, eventdata, handles)


% hObject handle to size (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 size as text


% str2double(get(hObject,'String')) returns contents of size as a
double

% --- Executes during object creation, after setting all properties.


function size_CreateFcn(hObject, eventdata, handles)
% hObject handle to size (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 pixel_x_Callback(hObject, eventdata, handles)


% hObject handle to pixel_x (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 pixel_x as text


% str2double(get(hObject,'String')) returns contents of pixel_x as
a double
pixel_x = str2double (get (hObject, 'String' ))
handles.pixel_x = pixel_x;
guidata(hObject, handles);
pixel_x

% --- Executes during object creation, after setting all properties.


function pixel_x_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_x (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 pixel_y_Callback(hObject, eventdata, handles)


% hObject handle to pixel_y (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 pixel_y as text


% str2double(get(hObject,'String')) returns contents of pixel_y as
a double
pixel_y = str2double (get (hObject, 'String' ))
handles.pixel_y = pixel_y;
guidata(hObject, handles);
pixel_y

% --- Executes during object creation, after setting all properties.


function pixel_y_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_y (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 valor.


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

% --- Executes during object creation, after setting all properties.


function valor_CreateFcn(hObject, eventdata, handles)
% hObject handle to valor (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called
% --- 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)
res = num2str(handles.imagen(handles.pixel_x, handles.pixel_y,
handles.pixel_z))
num_res = str2num(res)
res_bin = (dec2bin(num_res))
set(handles.valor, 'String' , (res_bin));

% --- Executes on selection change in listbox1.


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

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1


contents as cell array
% contents{get(hObject,'Value')} returns selected item from
listbox1

% --- Executes during object creation, after setting all properties.


function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: listbox 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 during object deletion, before destroying properties.


function pushbutton2_DeleteFcn(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)

function pixel_z_Callback(hObject, eventdata, handles)


% hObject handle to pixel_z (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 pixel_z as text
% str2double(get(hObject,'String')) returns contents of pixel_z as
a double
pixel_z = str2double (get (hObject, 'String' ))
handles.pixel_z = pixel_z;
guidata(hObject, handles);
pixel_z

% --- Executes during object creation, after setting all properties.


function pixel_z_CreateFcn(hObject, eventdata, handles)
% hObject handle to pixel_z (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 red.


function red_Callback(hObject, eventdata, handles)
% hObject handle to red (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 red


Red = handles.imagen;
guidata(hObject,handles);
Red(:,:,2) = 0; %RGB componente Rojo de la imagen original
Red(:,:,3) =0;
imshow (Red); title('capa roja')

% --- Executes on button press in green.


function green_Callback(hObject, eventdata, handles)
% hObject handle to green (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 green


Green = handles.imagen;
guidata(hObject,handles);
Green (:,:,1) =0;
Green (:,:,3) =0;
imshow (Green); title('Capa verde');

% --- Executes on button press in blue.


function blue_Callback(hObject, eventdata, handles)
% hObject handle to blue (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 blue
Blue = handles.imagen;
Blue(:,:,1) =0;
Blue(:,:,2) =0;

imshow(Blue); title('Capa azul');

% --- Executes on button press in rgb.


function rgb_Callback(hObject, eventdata, handles)
% hObject handle to rgb (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 rgb


imshow(handles.imagen);

% --- Executes on button press in pushbutton4.


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

Red = handles.imagen;
handles.Red = Red;
guidata(hObject,handles);
Red(:,:,2) = 0; %RGB componente Rojo de la imagen original
%la entropia en cualquier capa es la misma

entropiared = entropy(handles.Red(:,:,2))
handles.entropiared = entropiared;
guidata(hObject,handles);
set(handles.edit7,'String',entropiared*3);

% --- Executes on button press in pushbutton5.


function pushbutton5_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Green = handles.imagen;
handles.Green = Green;
guidata(hObject,handles);
Green (:,:,1) =0;
Green (:,:,3) =0;
entropiagreen = entropy(handles.Green(:,:,2))
handles.entropiagreen = entropiagreen;
guidata(hObject,handles);
entropiagreen

% --- Executes on button press in pushbutton6.


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

% --- Executes on button press in pushbutton7.


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

function text11_Callback(hObject, eventdata, handles)


% hObject handle to text11 (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 text11 as text


% str2double(get(hObject,'String')) returns contents of text11 as
a double

function edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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

Programa de archivo de texto.


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

% Last Modified by GUIDE v2.5 09-Feb-2020 05:44:02

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @texto_OpeningFcn, ...
'gui_OutputFcn', @texto_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 untitled is made visible.


function texto_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 untitled (see VARARGIN)

% Choose default command line output for untitled


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes untitled wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = texto_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;
%%%%%%%% TEXTO
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)
mensaje = get(hObject,'String');
handles.mensaje = mensaje;
guidata(hObject,handles);

%set(handles.uipanel1, 'Title', mensaje);


% 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

% BOTON
% --- 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)
%mensaje = fread(fid,10000000,'uint8=>char')

%A = get(handles.edit1, 'string');

set(handles.uipanel1, 'Title', 'Decomponiendo');


B = dec2bin(handles.mensaje);
set(handles.listbox1,'String',B);

function bit_Callback(hObject, eventdata, handles)


% hObject handle to bit (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
cejas = get(handles.bit, 'value');

% Hints: get(hObject,'String') returns contents of bit as text


% str2double(get(hObject,'String')) returns contents of bit as a
double

% --- Executes during object creation, after setting all properties.


function bit_CreateFcn(hObject, eventdata, handles)
% hObject handle to bit (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 selection change in listbox1.


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

% Hints: contents = cellstr(get(hObject,'String')) returns listbox1


contents as cell array
% contents{get(hObject,'Value')} returns selected item from
listbox1

% --- Executes during object creation, after setting all properties.


function listbox1_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% Hint: listbox 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 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)
[archivo,ruta]=uigetfile({'*.txt;*UTF-8'}, 'Escoger')

dat_archivo = strcat(ruta, archivo);


%A = importdata(data_archivo,'t',1);

fid = fopen('pru.txt'); %cargamos el archivo

A = fread(fid,10000000,'uint8=>char')'; %
%disp('El archivo de texto se carga')
%disp('Su contenido del archivo .txt es')

%disp('presiones una tecla para continuar')


%pause;
fclose(fid);
handles.mensaje = A;
guidata(hObject,handles);
B = dec2bin(A);
C = bin2dec(B)';
%disp('El equivalente del archivo de texto es')
set(handles.listbox1,'String',B);
%set(handles.uipanel1,'String', A);

% --- Executes during object creation, after setting all properties.


function pushbutton2_CreateFcn(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns
called

% --- 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)
H=0; %variable de entropia inicializada
S=0; %variable de fuente de información inicializada
simbolo=[];
veces = [];
ps = [];
is = [];
j = 1; %iterador para simbolos
k = 1;
l = 1;
m = 1;
%Este if lo ocupo para determinar la fuente de información
%Cuento cuales caracteres no repetidos hay en el mensaje
for i=32:255
caracter_sin_repetir = strfind(handles.mensaje, char(i));
if not(caracter_sin_repetir == 0)
S=S+1;
else
S=S+0;
end

end

for i=32:255 %todos los caracteres ascii escritos (recorre ascii


caracter por caracter)

dato=char(i); %convierte un tipo de datos en caracter


%length sirve para calcular longitud de una matriz o vector
%strfind
https://la.mathworks.com/help/matlab/ref/strfind.html#d117e91223
% encuentra en mensaje el patron dato veces se repite el caracter
total=length(strfind(handles.mensaje,dato));

p=total/S; %se obtiene la probabilidad del caraceter


p=#v.carecter/longitud de caracteres
p=total/length(handles.mensaje); %se obtiene la probabilidad del
caraceter p=#v.carecter/longitud de caracteres
in=log2(1/p);
if(total ~= 0)

simbolo(j) = dato; %para table vector


veces(k) = total;
ps(l) = p;
is(m) = in;

j=j+1;
k=k+1;
l=l+1;
m=m+1;

H=H+p*in;
end

end
simbolob = char(simbolo)
%datos = [cellstr(simbolob)' veces' ps' is];
% datos = [cellstr(simbolob)' num2cell(veces(:))' num2cell(ps(:))'
num2cell(is(:))']
datos = [cellstr(simbolob') num2cell(veces)' num2cell(ps)'
num2cell(is)'];
set(handles.uitable1,'data',datos)
set(handles.edit6,'String', H);
set(handles.edit7,'String',length(handles.mensaje));

function edit6_Callback(hObject, eventdata, handles)


% hObject handle to edit6 (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 edit6 as text


% str2double(get(hObject,'String')) returns contents of edit6 as a
double

% --- Executes during object creation, after setting all properties.


function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)


% hObject handle to edit7 (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 edit7 as text


% str2double(get(hObject,'String')) returns contents of edit7 as a
double

% --- Executes during object creation, after setting all properties.


function edit7_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit7 (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

También podría gustarte