%Curso:PDI
%Alumno:
%Fecha: 06.06.2015
%Laboratorio 2 -1era sesión
%Previos: Imágenes de varios tipos.
%imagen a color comprimida
I=imread('rostro.jpg');
imshow(I)
%Imagen a color comprimida.
imwrite(I,'rostro.bmp');
J=imread('rostro.bmp');
figure,imshow(J)
%Imagen a escala de grises.
%G=fLum(J) %TAREA 1
%G=fAve(J)
%G=fLigh(J)
G=rgb2gray(J);
imwrite(G,'rostroG.bmp')
imshow(G);
%Imagen binaria.
%B=fOtsu(G) TAREA 2
B=im2bw(G);
imwrite(B,'rostroB.bmp')
figure, imshow(B);
%Histograma de una imagen.
%a. H. Imagen binaria.
% TAREA 3: Funcion histograma de Imagen Binaria
% mHB(B) .... mi Histograma de Imagen Binaria, B es la imagen binaria
% Previo: Verificar si B es binaria
% Resultados: Mostrar ambas imagenes
% Verificar que se ha recorrido toda la imagen
H=[0 0]
for f=1:480
for c=1:640
if B(f,c)==1 H(2)=H(2)+1;
else H(1)=H(1)+1;
end
end
end
figure,stem(H);
%b. H. Imagen en escala de grises.
% I=imresize(J, [80 60])
% TAREA 4: Funcion histograma de Imagen Binaria
% mHG(G) .... mi Histograma de Imagen escala de grises, G es la imagen gris
% Previo: Verificar si G es escala de grises
% Resultados: Mostrar ambas imagenes
% Verificar que se ha recorrido toda la imagen
[x,y]=size(G)
figure, imshow(I)
F=zeros(1, 256)
for i=1:x
for j=1:y
v=G(i,j)
F(v+1)=F(v+1)+1;
end
end
figure, stem(F);
% Verificacion que se ha recorrido toda la imagen
s=0;
for z=1:256
s=s+F(z)
end
% x*y
% ans =
% 307200
%c. H. Imagen a color.
% TAREA 5: Funcion histograma de Imagen a color
% mHC(C) .... mi Histograma de Imagen a color, C es la imagen a color
% Previo: Verificar si C es a color
% Resultados: Mostrar ambas imagenes.
% Verificar que se ha recorrido toda la imagen.
% Funciones de histograma en Matlab
help imhist
% imhist Display histogram of image data.
% imhist(I) displays a histogram for the intensity image I whose number of
% bins are specified by the image type. If I is a grayscale image, imhist
% uses 256 bins as a default value. If I is a binary image, imhist uses
% only 2 bins.
%
% imhist(I,N) displays a histogram with N bins for the intensity image I
% above a grayscale colorbar of length N. If I is a binary image then N
% can only be 2.
% TAREA 6. Funciones propias y funciones de matlab
figure, imhist(G); % Comparar con su propias funciones
figure, imhist(J); % Comparar con su propias funciones
figure, imhist(B); % Comparar con su propias funciones
% K=imhist();
% ECUALIZACION DE UNA IMAGEN
I=[52 55 61 66 70 61 64 73; ...
63 59 55 90 109 85 69 72; ...
62 59 68 113 144 104 66 73; ...
63 58 71 122 154 106 70 69; ...
67 61 68 104 126 88 68 70; ...
79 65 60 70 77 68 58 75; ...
85 71 64 59 55 61 65 83; ...
87 79 69 68 65 76 78 94]
% Analizar que tipo de imagen es. (TAREA 7)
[x,y]=size(I)
f=zeros(1, 255) % matriz de frecuencias
for i=1:x
for j=1:y
v=I(i,j)
f(v+1)=f(v+1)+1;
end
end
figure, stem(f);
figure, imhist(uint8(I),255);
cdf=zeros(1,255)
for m=1:255
for n=1: m
cdf(m)=cdf(m)+f(n)
end
end
cdfmin=min(cdf)
P=zeros(8,8)
for i=1:x
for j=1:y
v=I(i,j)
v1=round((cdf(v+1)-cdfmin)/(x*y-cdfmin)*255)
P(i,j)=v1
end
end
I2=imresize(I,[640 640]);
P2=imresize(P,[640 640]);
imwrite(uint8(I),'r1.bmp');
imwrite(uint8(P),'r2.bmp');
figure, imshow(uint8(I2));
figure, imshow(uint8(P2));
%=======================================================
% Funciones de ecualizacion en Matlab
% J = HISTEQ(I,HGRAM)
% HGRAM = [0,1] for images of class
% double or single, [0,255] for images of class uint8, [0,65535] for images
% of class uint16, and [-32768, 32767] for images of class int16.
% J = HISTEQ(I,N) N discrete levels
% [J,T] = HISTEQ(I) returns the gray scale transformation that maps gray
% levels in the intensity image I to gray levels in J.
H=histeq(ig)
%=======================================================
I = imread('tire.tif');
J = histeq(I);
figure, imshow(I), figure, imshow(J)
%=======================================================
% Funciones de histograma en Matlab
%=============================================================
% BRILLO Y CONTRASTE DE UNA IMAGEN
% Manipulacion del brillo de una imagen escala de grise
ic=imread('rostro.bmp');
figure, imshow(ic);
ig=rgb2gray(ic);
figure, imshow(ig);
ig1=ig+50;
figure, imshow(ig1);
ig2=ig+50;
figure, imshow(ig2);
ig3=ig*0.5;
figure, imshow(ig3);
ig4=ig*1.5;
figure, imshow(ig4);
%=======================================================
% Funciones de brillo en Matlab
% IMADJUST Adjust image intensity values or colormap.
% J = IMADJUST(I)
% J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT])
% J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT],GAMMA)
G=imread('frutasg.bmp')
J1 =imadjust(G,[0 1], [0.2 1],1);
figure, imshow(J1);
% TAREA 8:
% Manipular el brillo de una imagen de color
% TAREA 9:
% Manipulacion del contraste de una imagen escala de grises
%=======================================================
% Funciones de contraste en Matlab
J2 = imadjust(G, [0.3 1], [0 1],1 );
figure, imshow(J2);
I = imread('flor2.bmp');
J = imadjust(I);
figure, imshow(I), figure, imshow(J)
K = imadjust(I,[0.3 0.7],[]);
figure, imshow(K)
RGB1 = imread('frutasg.bmp');
RGB2 = imadjust(RGB1,[.2 .3 0; .6 .7 1],[]);
figure, imshow(RGB1), figure, imshow(RGB2)
% TAREA 10:
% Manipular el contraste de una imagen de color
% CORRECCIONGAMMA DE UNA IMAGEN
% corrección gamma
g=gamma
nvalue = 255*(ovalue/255)^(1/g);
% TAREA 11.
% Hallar la coreccion gamma para una imagen escala de grises para valores de
% gamma= 0.1, 0.4, 0.7, 1.0 3.0 y 5.0
% Mostrar las imagenes en ventanas diferentes.
% Describir el efecto del gamma.
% TAREA 12.
% Hallar la coreccion gamma para una imagen a color para valores de
% gamma= 0.1, 0.4, 0.7, 1.0 3.0 y 5.0
% Describir el efecto del gamma.

L2 s1

  • 1.
    %Curso:PDI %Alumno: %Fecha: 06.06.2015 %Laboratorio 2-1era sesión %Previos: Imágenes de varios tipos. %imagen a color comprimida I=imread('rostro.jpg'); imshow(I) %Imagen a color comprimida. imwrite(I,'rostro.bmp'); J=imread('rostro.bmp'); figure,imshow(J) %Imagen a escala de grises. %G=fLum(J) %TAREA 1 %G=fAve(J) %G=fLigh(J) G=rgb2gray(J); imwrite(G,'rostroG.bmp') imshow(G); %Imagen binaria. %B=fOtsu(G) TAREA 2 B=im2bw(G); imwrite(B,'rostroB.bmp') figure, imshow(B); %Histograma de una imagen. %a. H. Imagen binaria. % TAREA 3: Funcion histograma de Imagen Binaria % mHB(B) .... mi Histograma de Imagen Binaria, B es la imagen binaria % Previo: Verificar si B es binaria % Resultados: Mostrar ambas imagenes % Verificar que se ha recorrido toda la imagen H=[0 0] for f=1:480 for c=1:640 if B(f,c)==1 H(2)=H(2)+1; else H(1)=H(1)+1; end end end figure,stem(H); %b. H. Imagen en escala de grises. % I=imresize(J, [80 60]) % TAREA 4: Funcion histograma de Imagen Binaria
  • 2.
    % mHG(G) ....mi Histograma de Imagen escala de grises, G es la imagen gris % Previo: Verificar si G es escala de grises % Resultados: Mostrar ambas imagenes % Verificar que se ha recorrido toda la imagen [x,y]=size(G) figure, imshow(I) F=zeros(1, 256) for i=1:x for j=1:y v=G(i,j) F(v+1)=F(v+1)+1; end end figure, stem(F); % Verificacion que se ha recorrido toda la imagen s=0; for z=1:256 s=s+F(z) end % x*y % ans = % 307200 %c. H. Imagen a color. % TAREA 5: Funcion histograma de Imagen a color % mHC(C) .... mi Histograma de Imagen a color, C es la imagen a color % Previo: Verificar si C es a color % Resultados: Mostrar ambas imagenes. % Verificar que se ha recorrido toda la imagen. % Funciones de histograma en Matlab help imhist % imhist Display histogram of image data. % imhist(I) displays a histogram for the intensity image I whose number of % bins are specified by the image type. If I is a grayscale image, imhist % uses 256 bins as a default value. If I is a binary image, imhist uses % only 2 bins. % % imhist(I,N) displays a histogram with N bins for the intensity image I % above a grayscale colorbar of length N. If I is a binary image then N % can only be 2. % TAREA 6. Funciones propias y funciones de matlab figure, imhist(G); % Comparar con su propias funciones figure, imhist(J); % Comparar con su propias funciones figure, imhist(B); % Comparar con su propias funciones % K=imhist(); % ECUALIZACION DE UNA IMAGEN
  • 3.
    I=[52 55 6166 70 61 64 73; ... 63 59 55 90 109 85 69 72; ... 62 59 68 113 144 104 66 73; ... 63 58 71 122 154 106 70 69; ... 67 61 68 104 126 88 68 70; ... 79 65 60 70 77 68 58 75; ... 85 71 64 59 55 61 65 83; ... 87 79 69 68 65 76 78 94] % Analizar que tipo de imagen es. (TAREA 7) [x,y]=size(I) f=zeros(1, 255) % matriz de frecuencias for i=1:x for j=1:y v=I(i,j) f(v+1)=f(v+1)+1; end end figure, stem(f); figure, imhist(uint8(I),255); cdf=zeros(1,255) for m=1:255 for n=1: m cdf(m)=cdf(m)+f(n) end end cdfmin=min(cdf) P=zeros(8,8) for i=1:x for j=1:y v=I(i,j) v1=round((cdf(v+1)-cdfmin)/(x*y-cdfmin)*255) P(i,j)=v1 end end I2=imresize(I,[640 640]); P2=imresize(P,[640 640]); imwrite(uint8(I),'r1.bmp'); imwrite(uint8(P),'r2.bmp'); figure, imshow(uint8(I2)); figure, imshow(uint8(P2)); %======================================================= % Funciones de ecualizacion en Matlab % J = HISTEQ(I,HGRAM) % HGRAM = [0,1] for images of class % double or single, [0,255] for images of class uint8, [0,65535] for images % of class uint16, and [-32768, 32767] for images of class int16. % J = HISTEQ(I,N) N discrete levels % [J,T] = HISTEQ(I) returns the gray scale transformation that maps gray % levels in the intensity image I to gray levels in J. H=histeq(ig)
  • 4.
    %======================================================= I = imread('tire.tif'); J= histeq(I); figure, imshow(I), figure, imshow(J) %======================================================= % Funciones de histograma en Matlab %============================================================= % BRILLO Y CONTRASTE DE UNA IMAGEN % Manipulacion del brillo de una imagen escala de grise ic=imread('rostro.bmp'); figure, imshow(ic); ig=rgb2gray(ic); figure, imshow(ig); ig1=ig+50; figure, imshow(ig1); ig2=ig+50; figure, imshow(ig2); ig3=ig*0.5; figure, imshow(ig3); ig4=ig*1.5; figure, imshow(ig4); %======================================================= % Funciones de brillo en Matlab % IMADJUST Adjust image intensity values or colormap. % J = IMADJUST(I) % J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT]) % J = IMADJUST(I,[LOW_IN; HIGH_IN],[LOW_OUT; HIGH_OUT],GAMMA) G=imread('frutasg.bmp') J1 =imadjust(G,[0 1], [0.2 1],1); figure, imshow(J1); % TAREA 8: % Manipular el brillo de una imagen de color % TAREA 9: % Manipulacion del contraste de una imagen escala de grises %======================================================= % Funciones de contraste en Matlab J2 = imadjust(G, [0.3 1], [0 1],1 ); figure, imshow(J2); I = imread('flor2.bmp'); J = imadjust(I); figure, imshow(I), figure, imshow(J) K = imadjust(I,[0.3 0.7],[]); figure, imshow(K)
  • 5.
    RGB1 = imread('frutasg.bmp'); RGB2= imadjust(RGB1,[.2 .3 0; .6 .7 1],[]); figure, imshow(RGB1), figure, imshow(RGB2) % TAREA 10: % Manipular el contraste de una imagen de color % CORRECCIONGAMMA DE UNA IMAGEN % corrección gamma g=gamma nvalue = 255*(ovalue/255)^(1/g); % TAREA 11. % Hallar la coreccion gamma para una imagen escala de grises para valores de % gamma= 0.1, 0.4, 0.7, 1.0 3.0 y 5.0 % Mostrar las imagenes en ventanas diferentes. % Describir el efecto del gamma. % TAREA 12. % Hallar la coreccion gamma para una imagen a color para valores de % gamma= 0.1, 0.4, 0.7, 1.0 3.0 y 5.0 % Describir el efecto del gamma.