%SEGMENTACION DE CARAS BASADA EN COLOR DE PIEL
%MTI JAIRO AVENDAÑO MALVAEZ
%PROFESOR EN EL TECNOLOGICO DE ZACATEPC
%E-MAIL:jairomarvin@hotmail.com
%MATERIA: HERRAMIENTAS COMPUTACIONALES
%LIBRE DE USARSE Y MODIFICARSE, SOLO MENCIONA LA FUENTE.. :)
%cambiando pixeles RGB
clc;clear;
I=imread('images.jpg');
background = imopen(I,strel('octagon',15));
I = I - background;
[m,n,c]=size(I);
PSF = fspecial('gaussian',1,4);
I = imfilter(I,PSF,'symmetric','conv');
I=image(I);
arrayname = get(I, 'CData');
%detetecta piel y sustituye por negro
for x=1 : m
for y=1 : n
R=arrayname(x,y,1);
G=arrayname(x,y,2);
B=arrayname(x,y,3);
if (R<150&&G<150&&B<150)
arrayname(x,y,:)=0;
mascara(x,y,:)=0;
end
if (R>100&&R<232)&& (G>68&&G<182)&& (B>38&&B<155)
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
if (R==168&&G==108&&B==77)
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
if (R==230&&G==156&&B==123)
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
if (R==206&&G==192&&B==192)
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
if (R==215&&G==173&&B==151)
arrayname(x,y,:)=0;
mascara(x,y,:)=255;
end
if (R==255&&G==207&&B==162)
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);
prop=regionprops(L,'Area','Centroid', 'BoundingBox','Extent');
total=0;
for n=1:size(prop,1) %For 1 to Total number of coins
boundingBox = prop(n).BoundingBox;
x1 = boundingBox(1);
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
if ((xtotal-ytotal)<(4*ytotal))&&((ytotal-xtotal)<(3*xtotal))
plot(verticesX, verticesY, 'g-', 'LineWidth', 2);
total=total+1;
end
end
end
Comentarios