Question

In: Computer Science

I want to make picture compress program in matlab use eigenmatrix in RGB with PCA. This...

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);

Solutions

Expert Solution

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);


Related Solutions

I want to create an image compression program with matlab use PCA. I have the code...
I want to create an image compression program with matlab use PCA. I have the code listed below. But this code is fail, the image is colorless, but still gray. Can you help me to 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 =...
PLEASE USE THE ECLIPSE. I want to make a program that shows whether the correct number...
PLEASE USE THE ECLIPSE. I want to make a program that shows whether the correct number is correct or incorrect. Example: how much is 1+1? option 1: 2 option 2: 3 option 3: 4 option 4: 5 option 5: 6 The answer is 1. because the answer is 2 and the option number is 1. Write a Java application that simulates a test. The test contains at least five questions about first three lectures of this course. Each question should...
For a catapult project I must make a MATLAB code that should make use of the...
For a catapult project I must make a MATLAB code that should make use of the projectile motion equations so for a given input range R (horizontal distance from the catapult to the target), the code outputs the necessary velocity and firing angle of the catapult. What is the code for this? I am lost.
For a catapult project I must make a MATLAB code that should make use of the...
For a catapult project I must make a MATLAB code that should make use of the projectile motion equations so for a given input range R (horizontal distance from the catapult to the target), the code outputs the necessary velocity and firing angle of the catapult. I must be able to input ranges: 7ft, 8ft and 9ft and the output of the code should give me the possible velocities and theta of the catapult.
Use SVD method to compress and decompress images in the MATLAB. Compression function. The input is...
Use SVD method to compress and decompress images in the MATLAB. Compression function. The input is an image file and k. The output is a text file containing the reduced U, V , and the reduced diagonals of ?. Decompression function. The input is the output of the compression code. The output is an image (you can use imshow for this purpose).
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red,...
CODE WITH ARDUINO: With an RGB Led, Use the iterative loop (for loop) to make red, blue, and green. Use ‘analogWrite’ command inside the 'for loop.' Use the value ranges from 0-255 for this command. So, to activate any of the pins, the value should be 255. To turn off 0. pattern: First for loop Red light – delay – Second for loop for blue light – delay - Third for loop for green light - delay. (The resulting lights...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want...
Hi, I'm currently writing a Matlab program to simulate the Apollo 11 trajectory. Now I want to plot a 3D animated orbit which is a 60 by 58 nautical miles orbit. Can you provide a code or some idea of how to plot an orbit like this in 3D?
sir I want to make discrete time Fourier series on GUI MATLAB can any one tell...
sir I want to make discrete time Fourier series on GUI MATLAB can any one tell me step by step procedure or coding for Discrete time Fourier series on GUI? pleaseeeee
I am working on an IOT BASED HOME AUTOMATION PROJECT...I want to make use of a...
I am working on an IOT BASED HOME AUTOMATION PROJECT...I want to make use of a camera in this system to be able to capture movements or happenings in the house... Can this be accomplished by using NODEMCU,ARDUINO,RASPBERRY PIE.. if yes...I need detailed ways on how to do it using each of them.
I want the code for the 2D Ising model using Matlab
I want the code for the 2D Ising model using Matlab
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT