matlab - How do I calculate a truncated-sum approximation? -
.
i'm take image, convert set of 3 matrices using imread()
, calculate truncated-sum approximation each matrix using n=1,2,3,4,8,16,32,64,128
terms. have matrices, i'm not sure last part , reading bit vague. mean truncated-sum approximation?
update based on given answer:
i tried following:
a = double(imread("image.jpg"))/255; [u1, s1, v1] = svd(a(:,:,1)); [u2, s2, v2] = svd(a(:,:,2)); [u3, s3, v3] = svd(a(:,:,3)); n = 128; trunc_image = (u1(1:763,1:n)*s1(1:n,1:n)*v1(1:n,1:691))*255; imwrite(trunc_image, "truncimg.jpg", "jpg");
...but resulting image looks this:
when perform svd
on image i
:
[u,s,v] = svd(i,'econ'); %//you matrices u, s, v
s
diagonal
matrix, decreasing singular values along diagonals.
approximation truncating...
means can reconstruct i'
zeroing out singular values in s
:
i_recon = u(1:256,1:n)*s(1:n,1:n)*v(1:256,1:n).'; %//reconstruct keeping first n singular values in s.
what happens here i_recon
image reconstructed n
significant singular values. purpose of doing can remove less significant
contributions image i
, , represent i
less data.
this example of reconstructed images varying n
:
Comments
Post a Comment