Documentos de Académico
Documentos de Profesional
Documentos de Cultura
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:
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.
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
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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)
%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
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)
%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)
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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)
%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);
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
Programa RGB
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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;
%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))) );
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);
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- 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)
%%%%%%%% 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);
% 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');
[archivo,ruta]=uigetfile({'*.txt;*UTF-8'}, 'Escoger')
A = fread(fid,10000000,'uint8=>char')'; %
%disp('El archivo de texto se carga')
%disp('Su contenido del archivo .txt es')
end
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));