Está en la página 1de 34

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 3
Histogramas en imágenes
Integrantes:
Báez Velázquez Alberto
Benitez Barrios Carlos Alberto
Cruz De la cruz Carlos Andrés

Profesor:
José Eduardo Guzmán Rodríguez

Grupo:
7CM21
Objetivo.
El alumno identifica como obtener el histograma de una imagen, realizando un
programa en MATLAB, Este deberá mostrar una interfaz gráfica de usuario en
(GUI), en la cual se muestre la gráfica del histograma de una imagen.

Consideracion Generales.
Esta práctica se entrega en equipo con la investigación realizada impresa, con los
nombres de los integrantes del equipo, empezando por el apellido paterno. En
classroom se debe subir un archivo que contenga si es necesario el escaneo de
los cálculos realizados en el cuaderno, junto con una copia del programa realizado
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 tomara en cuenta para la
calificación del departamental. Es necesario que cada integrante suba la práctica a
classroom

Antecedentes.
El histograma es una herramienta muy útil, que se encuentra frecuentemente
disponible en programas de edición de imágenes o se ofrece como ayuda en la
pantalla de algunas cámaras digitales. El histograma resulta muy útil para
determinar si el contraste o la exposición de una imagen digital son los adecuados.
Vamos a usar la pequeña imagen que representa la siguiente figura para
comprender qué es un histograma.

Se trata de una imagen en escala de grises muy simple, de 8x8 pixeles de tamaño
(se han señalado los límites entre pixeles para facilitar su identificación). Sólo son
posibles 4 niveles de gris, porque se van a usul 2 bits pala codifica' el bi illo de
cada pixel. De la forma habitual, los niveles de gris se numeran del 0 al 3,
correspondiendo un brillo mayor a los valores más altos. La tabla siguiente resume
esto:

Histograma:

El histograma resulta una herramienta de gran interés también en tareas de


análisis automático de imágenes, como las que se llevan a cabo en el área
análisis de imágenes por computadora. Para una aplicación de inspección
automática, se trata de determinar los pixeles de la imagen que corresponden a la
llave inglesa (perico), que se sabe depositada sobre un fondo de color más claro,
bastante uniforme.
Los números que aparecen el eje horizontal representan los niveles de gris que
pueden aparecer en la imagen: a la izquierda está el valor más oscuro (negro) y
en el extremo derecho el más claro (blanco). El resto de los niveles se distribuyen
uniformemente. Se ha puesto una escala con los tonos de gris correspondientes
para facilitar la comprensión. En un histograma real habitualmente no encontrará
numerado el eje vertical, ni la escala de tonos para el eje horizontal. La altura de
cada barra representa el número de pixeles de la imagen que presentan ese nivel
de gris concreto. Se puede deducir entonces que la imagen tiene 15 pixeles
completamente negros (con nivel 0), 11 de tono gris oscuro (nivel l) y 38 pixeles
completamente blancos (nivel 3). No hay ningún píxel en la imagen con un nivel de
gris 2.
¿Cuánto deberán sumar las alturas de todas las barras?
Efectivamente, 64, que es el número total de pixeles que tiene la imagen. Como
ve, con sólo mirar el histograma podemos deducir algunas cosas interesantes
sobre la imagen, lo que demuestra su utilidad:
 La mayor parte de los pixeles son blancos, así que probablemente se
aprecie un fondo blanco uniforme.
 Hay un número significativo de pixeles totalmente blancos y negros, por lo
que presentará un aspecto bien contrastado.
Para imágenes en color es posible realizar un análisis más detallado,
considerando que están formadas por la composición de tres canales de color
RGB (componentes roja, verde y azul). Es posible obtener el histograma de
canales de color, que cabe entenderlo como la superposición de 3 histogramas
distintos, los que corresponden a cada uno de los canales que forman la Imagen.

Desarrollo.
1. De acuerdo con la siguiente imagen y
tomando en cuenta que cada cuadro
representa un pixel, obtén a grafica del
histograma que corresponde a la
imagen. Los niveles de gris son los
mismos que los del ejemplo anterior.

//resuelto a través de programa


//resuelto a cálculos a mano.
2. Al mismo programa de MATLAB que realizaste en las practicas
anteriores añade la capacidad de que muestre la gráfica del
histograma de una imagen a blanco y negro, a escala de grises, a
color y de un archivo de texto.

Imagen B/N:

Programa:
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-Mar-2020 22:43:45

% 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);
in1 = log2(1/prob1);
in2 = log2(1/prob2);
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.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);

Imagen escala de grises:


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

% Last Modified by GUIDE v2.5 09-Mar-2020 22:17:12

% Begin initialization code - DO NOT EDIT


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


function practica3_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 practica3 (see VARARGIN)

% Choose default command line output for practica3


handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

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


% uiwait(handles.figure1);

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

% --- SECCIÓN DEL CODIGO DONDE CARGO MI IMAGEN (MAPADEBITS DESDE


FICHERO)
% --- 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)
[FileName, Path] = uigetfile({'*.png;.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.axes1);
imshow(imagen);
title 'Imagen RGB CARGADA'; xlabel 'eje x'; ylabel 'eje y';
imagen_gris = rgb2gray(imagen);

%OBTENCIÓN DE LAS DIMENSIONES PARA IMPRIMIRLAS EN PANTALLA


SZ = size(imagen_gris);
handles.SZ=SZ;
guidata(hObject,handles);
set(handles.edit1,'String',SZ(1));
set(handles.edit2,'String',SZ(2));

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


muestras = SZ(1)*SZ(2);
handles.muestras = muestras;
guidata(hObject, handles);
set(handles.edit3,'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
blanco =0; gris = 0; negro =0;
for i = 1:9
for y = 1:11
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.edit4,'String',blanco);
set(handles.edit5,'String',gris);
set(handles.edit6,'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.axes2);
bar(c,y);

end
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a
double

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


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

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit2_Callback(hObject, eventdata, handles)


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

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


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

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


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

% Hint: edit controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function edit3_Callback(hObject, eventdata, handles)


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


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

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


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

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

function edit4_Callback(hObject, eventdata, handles)


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


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

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


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

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

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