How to use Svd

1 visualizzazione (ultimi 30 giorni)
Claudia Santos
Claudia Santos il 19 Gen 2016
Risposto: Abhipsa il 31 Gen 2025
If I want to SVD an image, I cant do this?
a= imread('C:\Users\Acer\Desktop\Inves\teddy.jpg');
s = svd(a)
[U,S,V] = svd(a)
[U,S,V] = svd(a,0)
[U,S,V] = svd(a,'econ')
  1 Commento
David Young
David Young il 19 Gen 2016
Is the problem that the code doesn't work because the image is not a matrix, because it has 3 colour planes?
Can you say why you want to take the SVD of the image? What use do you expect it to be? What problem are you trying to solve? Is there some mathematical background to what you are trying to do?

Accedi per commentare.

Risposte (1)

Abhipsa
Abhipsa il 31 Gen 2025
Hi, I understand that you are trying to apply “svd” to an image which is producing an error.
As SVD works on only 2D matrices, and your image might have more than 2 channels (such as RGB images that have 3 channels), this could be the reason for the issue you're encountering. To apply SVD to such images, you would need to handle each channel separately or convert the image to a single channel format, like grayscale, before performing SVD.
Here two options available for using svd” on a RGB image:
1. Convert the image to grayscale to apply SVD on a single matrix.
This can be done using “im2gray” function in MATLAB. Convert the grayscale image to double precision before applying "svd".
a = imread('image_path');
% Convert to grayscale
gray_a = im2gray(a);
% Convert to double for SVD computation
gray_a = double(gray_a);
% Apply Singular Value Decomposition (SVD)
[U, S, V] = svd(gray_a);
[U,S,V] = svd(gray_a,0);
[U,S,V] = svd(gray_a,'econ');
2. To perform SVD on an RGB image, apply SVD separately on each color channel (R, G, and B).
a = imread('image_path');
% Convert to double
R = double(a(:,:,1)); % Red channel
G = double(a(:,:,2)); % Green channel
B = double(a(:,:,3)); % Blue channel
% Apply SVD separately to each channel
[Ur, Sr, Vr] = svd(R);
[Ug, Sg, Vg] = svd(G);
[Ub, Sb, Vb] = svd(B);
You can use the below MATLAB documentations for more details.

Community Treasure Hunt

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

Start Hunting!

Translated by