Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Solve the question using a simple MATLAB code and answer each and every sub - questions mentioned in attached image. Write a brief executive summary,

Solve the question using a simple MATLAB code and answer each and every sub-questions mentioned in attached image. Write a brief executive summary, answer to the all underlined questions and the significant images, add brief comments and write a clear explanation of why we wrote that step and what output we get.
Thank You.
Note: below is the MATLAB code that I got from previous expert but its not satisfactory. In which I got below mentioned error please rectify it.
>> project1
Arrays have incompatible sizes for this operation.
Error in project1(line 88)
norm_diff(i)= norm(coefficients - mean(data(:,(i-1)*3+1:i*3),2))/ norm(coefficients);
Write more explanations and what outputs we got.
% Project 1
% Step 1: Read, convert to black and white, resize images
om1= imresize(double(rgb2gray(imread('Myobama1.jpg'))),[12080]);
om2= imresize(double(rgb2gray(imread('Myobama2.jpg'))),[12080]);
om3= imresize(double(rgb2gray(imread('Myobama3.jpg'))),[12080]);
c1= imresize(double(rgb2gray(imread('Clooney1.jpg'))),[12080]);
c2= imresize(double(rgb2gray(imread('Clooney2.jpg'))),[12080]);
c3= imresize(double(rgb2gray(imread('Clooney3.jpg'))),[12080]);
t1= imresize(double(rgb2gray(imread('Thatcher1.jpg'))),[12080]);
t2= imresize(double(rgb2gray(imread('Thatcher2.jpg'))),[12080]);
t3= imresize(double(rgb2gray(imread('Thatcher3.jpg'))),[12080]);
% Step 2: Reshape images to vectors
om1_vec = reshape(om1,[],1);
om2_vec = reshape(om2,[],1);
om3_vec = reshape(om3,[],1);
c1_vec = reshape(c1,[],1);
c2_vec = reshape(c2,[],1);
c3_vec = reshape(c3,[],1);
t1_vec = reshape(t1,[],1);
t2_vec = reshape(t2,[],1);
t3_vec = reshape(t3,[],1);
% Step 3: Calculate average image and average vector
om_ave =(om1+ om2+ om3)/3;
c_ave =(c1+ c2+ c3)/3;
t_ave =(t1+ t2+ t3)/3;
om_ave_vec = reshape(om_ave, [],1);
c_ave_vec = reshape(c_ave, [],1);
t_ave_vec = reshape(t_ave, [],1);
% Step 4: Plot training images
figure;
subplot(3,3,1); pcolor(flipud(om1)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,2); pcolor(flipud(om2)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,3); pcolor(flipud(om3)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,4); pcolor(flipud(c1)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,5); pcolor(flipud(c2)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,6); pcolor(flipud(c3)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,7); pcolor(flipud(t1)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,8); pcolor(flipud(t2)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
subplot(3,3,9); pcolor(flipud(t3)); shading interp; colormap(gray); set(gca, 'Xtick', [], 'Ytick', []);
% Step 5: Plot average images
figure;
subplot(1,3,1); colormap(gray);
pcolor(flipud(om_ave)); shading interp;
subplot(1,3,2); colormap(gray);
pcolor(flipud(c_ave)); shading interp;
subplot(1,3,3); colormap(gray);
pcolor(flipud(t_ave)); shading interp;
% Step 6: Create data matrix
data =[c1_vec c2_vec c3_vec t1_vec t2_vec t3_vec om1_vec om2_vec om3_vec];
data_dim = size(data);
data_rank = rank(data);
singular_values = svd(data);
% Step 7: Evaluate covariance matrix
cov_mat = cov(data');
% Step 8: Calculate first 9 eigenvalues and eigenvectors
[eigenvectors, eigenvalues]= eigs(cov_mat, 9);
% Step 9: Transform test image into column vector
test_img = imresize(double(rgb2gray(imread('obama4.jpg'))),[12080]);
test_img_vec = reshape(test_img, [],1);
% Step 10: Evaluate coefficients of expansion
coefficients = eigenvectors' * test_img_vec;
reconstructed_img_vec = eigenvectors * coefficients;
% Step 11: Plot coefficients
figure;
bar(coefficients);
% Step 12: Plot remaining 8 coefficients
figure;
bar(coefficients(2:end));
% Step 13: Plot coefficients of test image
figure;
bar(coefficients);
% Step 14: Calculate normalized difference
norm_diff = zeros(3,1);
for i =1:3
norm_diff(i)= norm(coefficients - mean(data(:,(i-1)*3+1:i*3),2))/ norm(coefficients);
end
% Step 15: Plot test image and reconstruction
figure;
subplot(1,2,1); imshow(uint8(test_img));
title('Original Test Image');
subplot(1,2,2); imshow(uint8(reshape(reconstructed_img_vec, 120,80)));
title('Reconstructed Test Image');
% Step 16: Calculate normalized error
normalized_error = zeros(3,1);
for i =1:3
normalized_error(i)= norm(coefficients - mean(data(:,(i-1)*3+1:i*3),2))/ norm(mean(data(:,(i-1)*3+1:i*3),2))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2014 Nancy France September 15 19 2014 Proceedings Part I Lnai 8724

Authors: Toon Calders ,Floriana Esposito ,Eyke Hullermeier ,Rosa Meo

2014th Edition

3662448475, 978-3662448472

More Books

Students also viewed these Databases questions

Question

Presentation Aids Practicing Your Speech?

Answered: 1 week ago