Я делаю домашнее задание для класса, и мне нужно найти количество нецелочисленных значений в каждой реконструкции изображения (код ниже).
A=imread('bu_gray.jpg');
% read image into an unsigned integer array
A=single(A)./225;
%convert to decimal and set max value to 1
imshow(A,[])
%display image, [] scales to the min and max value
S = svd(A);
logsingVals = log10(S);
plot(logsingVals)
% Compute SVD of this tiger
[U, S, V] = svd(A);
% Plot the magnitude of the singular values (log scale)
sigmas = diag(S);
figure; plot(log10(sigmas)); title('Singular Values (Log10 Scale)');
figure; plot(cumsum(sigmas) / sum(sigmas)); title('Cumulative Percent of Total Sigmas');
% Show full-rank tiger
figure; subplot(4, 2, 1), imshow(A), title('Full-Rank bu_gray');
% Compute low-rank approximations of the tiger, and show them
ranks = [20, 10, 5, 1];
for i = 1:length(ranks)
% Keep largest singular values, and nullify others.
approx_sigmas = sigmas; approx_sigmas(ranks(i):end) = 0;
% Form the singular value matrix, padded as necessary
ns = length(sigmas);
approx_S = S; approx_S(1:ns, 1:ns) = diag(approx_sigmas);
% Compute low-rank approximation by multiplying out component matrices.
approx_bugray = U * approx_S * V';
% Plot approximation
subplot(4, 2, i + 1), imshow(approx_bugray), title(sprintf('Rank %d BU_Gray', ranks(i)));
%Compute number decimal values that must be stored to produce image
end
Дополнительный вопрос: как я могу найти количество сингулярных значений n, необходимых для представления изображения, которое имеет аналогичный/близкий вид к оригиналу?