How to use Svd
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
David Young
2016-1-19
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?
回答(1 个)
Abhipsa
2025-1-31
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.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!