SVD decomposition on color image?

3 ビュー (過去 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