ToOne.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # import
  2. # ------------------------------------------------------------------------------------------
  3. from . import Processing
  4. from .. import image
  5. import copy
  6. import numpy as np
  7. # ------------------------------------------------------------------------------------------
  8. # MIAM project 2020
  9. # ------------------------------------------------------------------------------------------
  10. # author: remi.cozot@univ-littoral.fr
  11. # ------------------------------------------------------------------------------------------
  12. class ToOne(Processing.Processing):
  13. """description of class"""
  14. def __init__(self):
  15. pass
  16. def compute(self, img, **kwargs):
  17. """
  18. compute method:
  19. @params:
  20. self - Required: (MIAM.processing.LaplaceFilter)
  21. img: - Required: image on which Laplace is computed (MIAM.image.IMAGE)
  22. kwargs - Optionnal: optionnal parameter (dict)
  23. 'method'= 'scalingMax' | scalingMinMax | 'crop'
  24. if scalingMax img.colorData = img.colorData/max(img.colorData)
  25. if scalingMinMax img.colorData = (img.colorData - min(img.colorData))/(max(img.colorData) - min(img.colorData))
  26. if crop img.colorData[img.colorData>1]=1 and img.colorData[img.colorData<0]=0
  27. """
  28. res = copy.deepcopy(img)
  29. if not kwargs: kwargs = {'method': 'scalingMax'} # default value
  30. # taking into account optional parameters
  31. if kwargs['method'] == 'scalingMax':
  32. minIMG = np.min(res.colorData)
  33. res.colorData = res.colorData/maxIMG
  34. elif kwargs['method'] == 'scalingMinMax':
  35. minIMG = np.min(res.colorData)
  36. maxIMG = np.max(res.colorData)
  37. res.colorData = (res.colorData-minIMG)/(maxIMG-minIMG)
  38. elif kwargs['method'] == 'crop':
  39. res.colorData[res.colorData>1] = 1
  40. res.colorData[res.colorData<0] = 0
  41. else:
  42. print("WARNING[miam.processing.ToOne: unknown 'method'=",kwargs['method'],"]")
  43. return res