Image Approximation (imshow) trouble -- I believe I'm doing Image Compression??

조회 수: 2 (최근 30일)
Jessica 2024년 2월 23일
댓글: Jessica 2024년 2월 26일
I have been asked to do the following (which I've done successfully):
Here is the beginning of what I entered, and I'm attaching a PDF for the rest.
I get confused when it gets to the second set of directions where I am to show an "image approximation". After all I've researched, again never have coded before, I cannot seem to enter anything correct because all I get is a white image. I used this help page to try to get me on the correct path: https://www.mathworks.com/help/matlab/math/image-compression-with-low-rank-svd.html but have had no luck. Here are the 2nd set of directions specifically that I'm struggling with. The math part of all the coding, I'm golden! It's the image part, and displaying that image where I'm getting the 1st image to display properly, but not the compressed/approximated images to come up as anything other than white.
Thank you!
댓글 수: 1이전 댓글 -1개 표시이전 댓글 -1개 숨기기
DGM 2024년 2월 24일
As to why the image is white, it's probably because your floating-point images are improperly scaled for their class because of the manner in which you handled them or cast them.

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

답변 (1개)

Karl 2024년 2월 23일
편집: Karl 2024년 2월 24일
The code below builds on code given by Torsten in relation to a related question: https://mathworks.com/matlabcentral/answers/2084643-how-to-do-a-rank-1-approximation.
% Read test image, which has data type uint8.
imshow(im1)
title(['original image']);
% Set rank of approximation.
k = 10;
% Convert to and from type double.
% The svd() function used in rank_k_approximation()
% requires data of type single or double.
im2 = uint8(rank_k_approximation(double(im1), k));
imshow(im2)
title(['rank-',num2str(k),' approximation']);
function Ak = rank_k_approximation(A, k)
%RANK_K_APPROXIMATION Calculate rank-k approximation of matrix A.
% The matrix A must be of type single or double
% (required by the function svd).
[U, S, V] = svd(A);
Ak = zeros(size(A));
for i=[1:k]
Ak = Ak + S(i,i)*U(:,i)*V(:,i).';
end
end
댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
Karl 2024년 2월 25일
편집: Karl 2024년 2월 25일
If you post the syntax errors that you're seeing, and the code that produced them, someone might be able to suggest changes for getting things to work with a MATLAB release from 2006.
In case it could be useful, MathWorks offers a free version of MATLAB Online:
Jessica 2024년 2월 26일
Thank you, my Professor helped me enough where I'm not going to fail anyways.

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

카테고리

Help CenterFile Exchange에서 Image Preview and Device Configuration에 대해 자세히 알아보기

R2006b

Community Treasure Hunt

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

Start Hunting!

Translated by