In: Computer Science
I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This code listed below. But this code is fail. I want to make the picture have a colour, but in my program the picture is still colorless. Can you fix my code?
clc
clear all
picture = im2double(imread('picture1.jpg'));
Red = picture(:,:,1);
premean = mean(Red(:));
premax = max(Red(:));
premin = min(Red(:));
x = size(Red,1);
y = size(Red,2);
Z = ones(x,y)*premean;
A = (Red - Z)*(1/premax - premin);
B = cov(A);
[veceig,eig,C] = pcacov(B);
NewRed = A*veceig(:,1:50);
ReturnRed = NewRed*veceig(:,1:50);
Return2Red = ((premax - premin)*ReturnRed)+ Z;
Green = picture(:,:,2);
premean_2 = mean(Green(:));
premax_2 = max(Green(:));
premin_2 = min(Green(:));
x2 = size(Green,1);
y2 = size(Green,2);
Z2 = ones(x2,y2)*premean_2;
A2 = (Green - Z2)*(1/premax_2 - premin_2);
D = cov(A2);
[veceig2,eig,E] = pcacov(D);
NewGreen = A2*veceig2(:,1:50);
ReturnGreen = NewGreen*veceig2(:,1:50);
Return2Green = ((premax_2 - Premin_2)*ReturnGreen)+ Z2;
Blue = picture(:,:,3);
premean_3 = mean(Blue(:));
premax_3 = max(Blue(:));
premin_3 = min(Blue(:));
x3 = size(Blue,1);
y3 = size(Blue,2);
Z3 = ones(x3,y3)*premean_3;
A3 = (Blue - Z3)*(1/premax_3 - premin_3);
F = cov(A3);
[veceig3,eig,G] = pcacov(F);
NewBlue = A3*veceig3(:,1:50);
ReturnBlue = NewBlue*veceig3(:,1:50);
Return2Blue = ((premax_3 - Premin_3)*Return2Blue)+ Z3;
figure,plot(cumsum(C)),cumsum(E),cumsum(G);
figure,imshow(A:A2:A2);
title('Original Image Normalization');
figure,imshow(ReturnRed:ReturnBlue:ReturnGreen);
title('Original Result of Decompression Normalization');
imshow(Red:Green:Blue);
picture = im2double(imread('picture1.jpg'));
Red = picture(:,:,1);
premean = mean(Red(:));
premax = max(Red(:));
premin = min(Red(:));
x = size(Red,1);
y = size(Red,2);
Z = ones(x,y)*premean;
A = (Red - Z)*(1/premax - premin);
B = cov(A);
[veceig,eig,C] = pcacov(B);
NewRed = A*veceig(:,1:60);
ReturnRed = NewRed*veceig(:,1:50);
Return2Red = ((premax - premin)*ReturnRed)+ Z;
Green = picture(:,:,2);
premean_2 = mean(Green(:));
premax_2 = max(Green(:));
premin_2 = min(Green(:));
x2 = size(Green,1);
y2 = size(Green,2);
Z2 = ones(x2,y2)*premean_2;
A2 = (Green - Z2)*(1/premax_2 - premin_2);
D = cov(A2);
[veceig2,eig,E] = pcacov(D);
NewGreen = A2*veceig2(:,2:60);
ReturnGreen = NewGreen*veceig2(:,2:50);
Return2Green = ((premax_2 - Premin_2)*ReturnGreen)+ Z2;
Blue = picture(:,:,3);
premean_3 = mean(Blue(:));
premax_3 = max(Blue(:));
premin_3 = min(Blue(:));
x3 = size(Blue,1);
y3 = size(Blue,2);
Z3 = ones(x3,y3)*premean_3;
A3 = (Blue - Z3)*(1/premax_3 - premin_3);
F = cov(A3);
[veceig3,eig,G] = pcacov(F);
NewBlue = A3*veceig3(:,3:60);
ReturnBlue = NewBlue*veceig3(:,3:50);
Return2Blue = ((premax_3 - Premin_3)*Return2Blue)+ Z3;
figure,plot(cumsum(C)),cumsum(E),cumsum(G);
figure,imshow(A:A2:A3);
title('Original Image Normalization');
figure,imshow(ReturnRed:ReturnBlue:ReturnGreen);
title('Original Result of Decompression Normalization');
imshow(Red:Green:Blue);