SVD decomposition on color image?

조회 수: 6 (최근 30일)
Jeremy Dessert
Jeremy Dessert 2021년 2월 16일
댓글: Jeremy Dessert 2021년 2월 16일
I am trying to preform SVD Decomposition on a color image. I have attached my code. The main goal is to preform SVD on a color image, and apply various rank approximations. The issue is when i change the rank to k=55, I get a greyscale image and not color. How could I fix this to get a color image when I change the rank?
% Read jpg file
A = imread('woodchuck.jpg');
% Convert to A to double
A = im2double(A);
% Color Channels
R = A(:, :, 1);
G = A(:, :, 2);
B = A(:, :, 3);
% Perform svd
[UR,SR,VR] = svd(R);
[UG,SG,VG] = svd(G);
[UB,SB,VB] = svd(B);
DR = UR*SR*VR';
DG = UG*SG*VG';
DB = UB*SB*VB';
%Create new matrix
% Plot rank 5 approximation, rank 10 approximation, rank 50, and true image
figure('Position',[50 50 800 800])
subplot(2,2,1)
M=zeros(480,640,3);
M(:,:,1) = DR;
M(:,:,2) = DG;
M(:,:,3) = DB;
imshow(M); title ('Original Image')
subplot(2,2,2)
k = 55;
Mk = UR(:,1:k)*SR(1:k, 1:k)* VR(:,1:k)';
Mk = UG(:,1:k)*SG(1:k, 1:k)* VG(:,1:k)';
Mk = UB(:,1:k)*SB(1:k, 1:k)* VB(:,1:k)';
imshow(Mk); title('Rank 55')
  댓글 수: 2
Christine Tobler
Christine Tobler 2021년 2월 16일
The lines
Mk = UR(:,1:k)*SR(1:k, 1:k)* VR(:,1:k)';
Mk = UG(:,1:k)*SG(1:k, 1:k)* VG(:,1:k)';
Mk = UB(:,1:k)*SB(1:k, 1:k)* VB(:,1:k)';
each overwrite Mk with the next channel, so you're only seeing a grayscale image with the last channel (blue). Use Mk(:, :, 1) = ..., Mk(:, :, 2) = ..., Mk(:, :, 3) = ... instead.
Jeremy Dessert
Jeremy Dessert 2021년 2월 16일
Thanks for the suggestion that worked!

댓글을 달려면 로그인하십시오.

답변 (0개)

제품


릴리스

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by