Transformation.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. return data
  19. def getTransformationPath(self):
  20. path = self.transformation
  21. if self.transformation == 'svd_reconstruction':
  22. begin, end = list(map(int, self.param.split(',')))
  23. path = os.path.join(path, str(begin) + '_' + str(end))
  24. if self.transformation == 'ipca_reconstruction':
  25. n_components, batch_size = list(map(int, self.param.split(',')))
  26. path = os.path.join(path, 'N' + str(n_components) + '_' + str(batch_size))
  27. if self.transformation == 'fast_ica_reconstruction':
  28. n_components = self.param
  29. path = os.path.join(path, 'N' + str(n_components))
  30. return path
  31. def getName(self):
  32. return self.transformation
  33. def getParam(self):
  34. return self.param
  35. def __str__( self ):
  36. return self.transformation + ' transformation with parameter : ' + self.param