preprocessing_functions.py 585 B

1234567891011121314151617181920212223
  1. from numpy.linalg import svd
  2. from PIL import Image
  3. from scipy import misc
  4. import time
  5. import numpy as np
  6. from ipfml import metrics
  7. def svd_reconstruction(img, interval):
  8. begin, end = interval
  9. lab_img = metrics.get_LAB_L(img)
  10. lab_img = np.array(lab_img, 'uint8')
  11. U, s, V = svd(lab_img, full_matrices=True)
  12. # reconstruction using specific interval
  13. smat = np.zeros((end-begin, end-begin), dtype=complex)
  14. smat[:, :] = np.diag(s[begin:end])
  15. output_img = np.dot(U[:, begin:end], np.dot(smat, V[begin:end, :]))
  16. return output_img