Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
PROJECT: 3
BY
NC Shakeela Naz
MSCS-17
DATED
5TH JAN, 2011
1. Problem definition:-
A program that reads a binary image in .PPM format after prompting the user for the file name of that
image (There should be no other input.). The program will identify regions in the input image that are
potentially a human face.
2. Summary of algorithm:-
Top-Down development approach is used for the required program.
Block diagram below shows the working of the program:-
• MATLAB Help.
APPENDIX B
MATLAB CODE:-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%--------------------------------------------%%%%%%%%%
%%%%%~*~*~*~ NC Shakeela Naz --- MSCS-17 ~*~*~*~%%%%%
%%%%%~*~*~*~ Digital Image Processing ~*~*~*~%%%%%
%%%%%~*~*~*~ Project 3 ~*~*~*~%%%%%
%%%%%~*~*~*~ 5th January, 2011 ~*~*~*~%%%%%
%%%%%%%%%--------------------------------------------%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Reading/Loading the PPM File %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure,imshow(inRGB);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%% Convert to HSV %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
InImg=inRGB;
hsvImg=rgb2hsv(inRGB);
[EndR EndC Channel]=size(hsvImg);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%% FACE EXTRACTION %%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
%
for i=1:EndR
for j= 1:EndC %%% only H and channel is needed
if ~(((0.01<=hsvImg(i,j,1) && hsvImg(i,j,1)<=0.06) || (0.96<=hsvImg(i,j,1) && hsvImg(i,j,1)<=1.0)))
inRGB(i,j,1)=0;
inRGB(i,j,2)=0;
inRGB(i,j,3)=0;
end
end
end
figure,imshow(inRGB);
graySeg=rgb2gray(inRGB);
figure,imshow(graySeg);
BinSeg=graySeg;
BinSeg(BinSeg<80)=0;
BinSeg(BinSeg>=80)=1;
%%
BinSeg=logical(BinSeg);
figure,imshow(BinSeg);
se=strel('disk',1);
BinSeg=imopen(BinSeg,se);
figure,imshow(BinSeg);
BinSeg=imfill(BinSeg,'holes');
figure,imshow(BinSeg);
se=strel('disk',3);
BinSeg=imopen(BinSeg,se);
figure,imshow(BinSeg);
BinSeg=bwlabel(BinSeg);
figure,imagesc(BinSeg);
STATS = regionprops(BinSeg,'Area');
[c r]=size(STATS);
for i=1:c
if STATS(i).Area<=200 % if area of label c is less than or equal to 200
BinSeg(BinSeg==i)=0;
end
end
BinSeg2=bwlabel(BinSeg);
figure,imagesc(BinSeg2);
STATS2 = regionprops(BinSeg2,'Eccentricity');
[c2 r2]=size(STATS2);
for i=1:c2
if STATS2(i).Eccentricity>0.96 % if Eccentricity of label c is greater than 0.96
BinSeg2(BinSeg2==i)=0;
end
end
[BinSeg3 n]=bwlabel(BinSeg2);
figure,imagesc(BinSeg3);
%Color Segmented image after Morphological Processing and Connected region analysis
for i=1:EndR
for j= 1:EndC
if BinSeg3(i,j)==0
inRGB(i,j,1)=0;
inRGB(i,j,2)=0;
inRGB(i,j,3)=0;
end
end
end
figure,imshow(inRGB);
%Bounding boxes
STATS3 = regionprops(BinSeg3,'BoundingBox');
for j=1:n
x1=uint8(STATS3(j).BoundingBox(1,1));
y1=uint8(STATS3(j).BoundingBox(1,2));
x2=uint8(x1 + STATS3(j).BoundingBox(1,3));
y2=uint8(y1 + STATS3(j).BoundingBox(1,4));
InImg(y1,x1:x2,1:3)=255;
InImg(y2,x1:x2,1:3)=255;
InImg(y1:y2,x1,1:3)=255;
InImg(y1:y2,x2,1:3)=255;
x1=0;
x2=0;
y1=0;
y2=0;
end
% writing output file in work directory, in Output+Filename. ppm format, with bounding boxes on potential
face regions
figure,imshow(InImg);
d='OutPut';
fileOut=[d,F];
imwrite(InImg,fileOut,'ppm');