Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Objective : Improve MATLAB programming skills Description : This optional projec

ID: 2250021 • Letter: O

Question

Objective: Improve MATLAB programming skills
Description: This optional project is to make a passport photo from the pictures taken by your mobile phone or camera. The requirements are stated on the government’s website:

Digital Image Head Size Template

-The top of the head, including the hair, to the bottom of the chin must be between 50% and 69% of the image's total height. The eye height (measured from the bottom of the image to the level of the eyes) should be between 56% and 69% of the image's height.
- Image pixel dimensions must be in a square aspect ratio (meaning the height must be equal to the width). Minimum acceptable dimensions are 600 pixels (width) x 600 pixels (height). Maximum acceptable dimensions are 1200 pixels (width) x 1200 pixels (height).

Your program should take the following input parameters:
1. im – the input image
2. headsize -- the top of the head, including the hair, to the bottom of the chin in a percentage of the image’s total height. (50% to 69%)
3. eyeheight – the distance from the bottom of the image to the level of the eyes in a percentage of the image’s total height. (56% to 69%)
4. dim – photo size in pixels. (600 to 1200)

The prototype of your matlab function:

photo = YourName_PassportPhoto(im, headsize, eyeheight, dim)

Implementation
Step 1: Find the coordinates of the eyes. Rotate the image to level the head position
Step 2: Find the coordinates of the chin and the top of the head.
Step 3: Crop the image into the required head size ratio and eye height ratio. The head should be centered. Prompt an error message if the input image does not have enough pixels for cropping. No need to change the background of the input picture.
Step 4: Resample the cropped image into required dimensions

600 px 600 px 50-69% 56-69%

Explanation / Answer

function I = ArrangePhoto(InputI,I,Nrol,Ncol)
% Arrange the photos into a big printable photo

[Hs,Ws,z]=size(InputI);
[H,W,z]=size(I);

if ((Hs*Nrol == H)||(Ws*Ncol==W))
InputI = imresize(InputI,[Hs-1,Ws-1]);
[Hs,Ws,z]=size(InputI);
end

Srol=ceil((H-Hs*Nrol)/(Nrol+1));
Scol=ceil((W-Ws*Ncol)/(Ncol+1));
if Srol<2
I = ones((Hs+Srol)*Nrol+Srol,size(I,2),3);
end

if Scol<2
I = ones(size(I,1),(Ws+Scol)*Ncol+Scol,3);
end

for j=1:Nrol
for k=1:Ncol
I((Hs+Srol)*(j-1)+Srol+1:(Hs+Srol)*(j-1)+Hs+Srol,(Ws+Scol)*(k-1)+Scol+1:(Ws+Scol)*(k-1)+Ws+Scol,:)=InputI;
end
end