Post on 09-Apr-2018
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 1/17
DIGITAL IMAGE PROCESSING
PROJECT: 3
BY
NC Shakeela Naz
MSCS-17
DATED
5TH JAN, 2011
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 2/17
1. Problem definition :-
A program that reads a binary image in .PPM format after prompting the user for the file name of thatimage (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:-
See Appendix B for MATLAB implementation.
Reuse of outside code: None.
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 3/17
3. Example image and results of running the program on it :-
Above: Input Image TestImage1.ppm
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 4/17
Above: After Color Segmentation
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 5/17
Above: After converting to binary and applying morphological operations (opening by disk of size 1,
then filing holes and then opening again by disk of size 3)
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 6/17
Above: After labeling
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 7/17
Above: After discarding areas smaller than 200 pixels
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 8/17
Above: After discarding arms (by discarding areas with Eccentricity greater than 0.96)
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 9/17
Above: Color Segmented image after Morphological Processing and Connected region analysis
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 10/17
Above: Snapshot of output file OutPutTestImage1.ppm
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 11/17
Above: zoomed in snap-shot of OutPut file OutPutTestImage1.ppm
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 12/17
RESULTS:-
• Adjacent (overlapping) faces merged by program because of being part of same connected
region.
• Program successfully eliminated arm and elongated hand; but not curled hands (like fist). This
happened because arm and stretched / elongated hand and fingers had high Eccentricity, whilethe Eccentricity of fist/curled hands was closer to the Eccentricity of faces.
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 13/17
APPENDIX AREFRENCES:-
• MATLAB Central website : http://www.mathworks.com
• MATLAB Help.
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 14/17
APPENDIX BMATLAB CODE:-
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%--------------------------------------------%%%%%%%%%
%%%%%~*~*~*~ NC Shakeela Naz --- MSCS-17 ~*~*~*~%%%%%%%%%%~*~*~*~ Digital Image Processing ~*~*~*~%%%%%
%%%%%~*~*~*~ Project 3 ~*~*~*~%%%%%%%%%%~*~*~*~ 5th January, 2011 ~*~*~*~%%%%%
%%%%%%%%%--------------------------------------------%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% Reading/Loading the PPM File %%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Load the Color Image(selected by user) in 'inImg' Variable(matrix).%
clc; % clear command window
clear; % clear work space
Imgread=0;while(Imgread==0)
[F,P]=uigetfile('*ppm;','Choose Image');
if F==0
return;else
PF=[ P , F ];
ext=PF(findstr(PF,'.')+1:end);
tryinRGB=imread(PF,'ppm');
Imgread=1;
catch lasterr
s1=lasterr;
if(s1=='Attempt to reference field of non-structure array.')
%if format mismatch; lasterr=Attempt to reference field of non-structure array.
Imgread=0
h=errordlg('File format mis-match','ERROR!')
uiwait(h);
uiresume;end
endend
end
figure,imshow(inRGB);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%%%%%%%%%%%%%%%%%%%%% Convert to HSV %%%%%%%%%%%%%%%%%
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 15/17
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
%
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;
endend
end
figure,imshow(inRGB);
%convert color segmented img 2 grayscale......light greyshades correspond 2
%faces....others are to b discarded
graySeg=rgb2gray(inRGB);figure,imshow(graySeg);
BinSeg=graySeg;
BinSeg(BinSeg<80)=0;
BinSeg(BinSeg>=80)=1;
%binary morphology on BinSeg
%%
BinSeg=logical(BinSeg);figure,imshow(BinSeg);
se=strel('disk',1);
BinSeg=imopen(BinSeg,se);
figure,imshow(BinSeg);
BinSeg=imfill(BinSeg,'holes');
figure,imshow(BinSeg);
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 16/17
se=strel('disk',3);
BinSeg=imopen(BinSeg,se);
figure,imshow(BinSeg);
%%% Connected Region Analysis
BinSeg=bwlabel(BinSeg);
figure,imagesc(BinSeg);
%discard regions with areas less than 201
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);
%discard regions with high Eccentricity
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.96BinSeg2(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:EndCif 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
8/7/2019 Project No 3 [Shakeela Naz] [MSCS 17]
http://slidepdf.com/reader/full/project-no-3-shakeela-naz-mscs-17 17/17
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');