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
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
Abhipsa 2025년 1월 31일

0 개 추천

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.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

질문:

2016년 1월 19일

답변:

2025년 1월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by