b
unknown
matlab
2 years ago
1.2 kB
2
Indexable
Never
image = imread('img_blackwhite_e2.jpg'); %image = rgb2gray(image); A=im2double(image); [U,S,V] = svd(A); singular_values = diag(S); singular_values_quantity = length(singular_values); sum_total_singular_values_squares = sum(singular_values.^2); preserved_quantities = [25 50 75]; for n = 1 : length(preserved_quantities) preserved_quantity = preserved_quantities(n); singular_values_length = round(singular_values_quantity*(preserved_quantity/100)); [U_2,S_2,V_2] = svds(A,singular_values_length); singular_values = diag(S_2); sum_singular_values_squares = sum(singular_values.^2); fprintf('Percentagem de qualidade de dados preservada com %d%% dos valores singulares: %0.8f%% \r\n',preserved_quantity, 100*(sum_singular_values_squares/sum_total_singular_values_squares)); A_2 = U_2*S_2*V_2'; image_2 = uint8(A_2); if(n == 1) image_25 = image_2; elseif (n==2) image_50 = image_2; else image_75 = image_2; end end subplot(2,2,1), imshow(image) title('Imagem original') subplot(2,2,2), imshow(image_25) title('25%') subplot(2,2,3), imshow(image_50) title('50%') subplot(2,2,4), imshow(image_75) title('75%')