Sei sulla pagina 1di 2

%SEGMENTACION DE CARAS BASADA EN COLOR DE PIEL

%MTI JAIRO AVENDAO MALVAEZ


%PROFESOR EN EL TECNOLOGICO DE ZACATEPC
%E-MAIL:jairomarvin@hotmail.com
%MATERIA: HERRAMIENTAS COMPUTACIONALES
%LIBRE DE USARSE Y MODIFICARSE, SOLO MENCIONA LA FUENTE.. :)
%limpiando pantalla y variables
clc;clear;
I=imread('images.jpg');
%limpiando pantalla y variables
imshow(I);
pause(3)
[m,n,c]=size(I);%calculando tamao de imagen en m y n
I=image(I);
arrayname = get(I, 'CData');
%barrido de toda la imagen pixel por pixel
for x=1 : m
for y=1 : n
%recupera valores rgb para cada pixel de imagen
R=arrayname(x,y,1);
G=arrayname(x,y,2);
B=arrayname(x,y,3);
%detetecta piel y sustituye por negro
if (R>254&&R<255)&& (G>254&&G<255)&& (B>254&&B<255)%rangos rgb de piel
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
%sustituye por negro colores obscuros
if (R<65&&G<65&&B<65)
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
end
end
set(I, 'CData', arrayname);
imshow(mascara)
pause(2)

I = bwareaopen(mascara, 200);
imshow(I);hold on
pause(2)
[L Ne]=bwlabel(double(I),8);%etiqueta objetos
%recupera propiedades de objetos etiquetados
prop=regionprops(L,'Area','Centroid', 'BoundingBox','Extent');
total=0;
for n=1:size(prop,1) %Dibuja marco verde alrededor de caras
boundingBox = prop(n).BoundingBox;
x1 = boundingBox(1);%recupera limites por cada objeto
y1 = boundingBox(2);
x2 = x1 + boundingBox(3) - 1;
y2 = y1 + boundingBox(4) - 1;
verticesX = [x1 x2 x2 x1 x1];
verticesY = [y1 y1 y2 y2 y1];
xtotal=abs(x1-x2);

ytotal=abs(y1-y2);
cent=prop(n).Centroid;
X=cent(1);Y=cent(2);
if prop(n).Extent>.4 %llenado del bounding box
%discrimina rectangulos muy grandes
if ((xtotal-ytotal)<(4*ytotal))&&((ytotal-xtotal)<(3*xtotal))
plot(verticesX, verticesY, 'g-', 'LineWidth', 2);
total=total+1; % cuenta el total de caras
end
end
end

Potrebbero piacerti anche