Transformation.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import os
  2. from transformation_functions import svd_reconstruction, fast_ica_reconstruction, ipca_reconstruction
  3. # Transformation class to store transformation method of image and get usefull information
  4. class Transformation():
  5. def __init__(self, _transformation, _param):
  6. self.transformation = _transformation
  7. self.param = _param
  8. def getTransformedImage(self, img):
  9. if self.transformation == 'svd_reconstruction':
  10. begin, end = list(map(int, self.param.split(',')))
  11. data = svd_reconstruction(img, [begin, end])
  12. if self.transformation == 'ipca_reconstruction':
  13. n_components, batch_size = list(map(int, self.param.split(',')))
  14. data = ipca_reconstruction(img, n_components, batch_size)
  15. if self.transformation == 'fast_ica_reconstruction':
  16. n_components = self.param
  17. data = fast_ica_reconstruction(img, n_components)
  18. if self.transformation == 'static':
  19. # static content, we keep input as it is
  20. data = img
  21. return data
  22. def getTransformationPath(self):
  23. path = self.transformation
  24. if self.transformation == 'svd_reconstruction':
  25. begin, end = list(map(int, self.param.split(',')))
  26. path = os.path.join(path, str(begin) + '_' + str(end))
  27. if self.transformation == 'ipca_reconstruction':
  28. n_components, batch_size = list(map(int, self.param.split(',')))
  29. path = os.path.join(path, 'N' + str(n_components) + '_' + str(batch_size))
  30. if self.transformation == 'fast_ica_reconstruction':
  31. n_components = self.param
  32. path = os.path.join(path, 'N' + str(n_components))
  33. if self.transformation == 'static':
  34. # param contains the whole path of image
  35. path = self.param
  36. return path
  37. def getName(self):
  38. return self.transformation
  39. def getParam(self):
  40. return self.param
  41. def __str__( self ):
  42. return self.transformation + ' transformation with parameter : ' + self.param