data_type.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from ipfml import processing, metrics
  2. from PIL import Image
  3. from skimage import color
  4. import numpy as np
  5. def get_svd_data(data_type, block):
  6. """
  7. Method which returns the data type expected
  8. """
  9. if data_type == 'lab':
  10. block_file_path = '/tmp/lab_img.png'
  11. block.save(block_file_path)
  12. data = processing.get_LAB_L_SVD_s(Image.open(block_file_path))
  13. if data_type == 'mscn_revisited':
  14. img_mscn_revisited = processing.rgb_to_mscn(block)
  15. # save tmp as img
  16. img_output = Image.fromarray(img_mscn_revisited.astype('uint8'), 'L')
  17. mscn_revisited_file_path = '/tmp/mscn_revisited_img.png'
  18. img_output.save(mscn_revisited_file_path)
  19. img_block = Image.open(mscn_revisited_file_path)
  20. # extract from temp image
  21. data = metrics.get_SVD_s(img_block)
  22. if data_type == 'mscn':
  23. img_gray = np.array(color.rgb2gray(np.asarray(block))*255, 'uint8')
  24. img_mscn = processing.calculate_mscn_coefficients(img_gray, 7)
  25. img_mscn_norm = processing.normalize_2D_arr(img_mscn)
  26. img_mscn_gray = np.array(img_mscn_norm*255, 'uint8')
  27. data = metrics.get_SVD_s(img_mscn_gray)
  28. if data_type == 'low_bits_6':
  29. low_bits_6 = processing.rgb_to_LAB_L_low_bits(block, 6)
  30. data = metrics.get_SVD_s(low_bits_6)
  31. if data_type == 'low_bits_5':
  32. low_bits_5 = processing.rgb_to_LAB_L_low_bits(block, 5)
  33. data = metrics.get_SVD_s(low_bits_5)
  34. if data_type == 'low_bits_4':
  35. low_bits_4 = processing.rgb_to_LAB_L_low_bits(block, 4)
  36. data = metrics.get_SVD_s(low_bits_4)
  37. if data_type == 'low_bits_3':
  38. low_bits_3 = processing.rgb_to_LAB_L_low_bits(block, 3)
  39. data = metrics.get_SVD_s(low_bits_3)
  40. if data_type == 'low_bits_2':
  41. low_bits_2 = processing.rgb_to_LAB_L_low_bits(block, 2)
  42. data = metrics.get_SVD_s(low_bits_2)
  43. if data_type == 'low_bits_4_shifted_2':
  44. data = metrics.get_SVD_s(processing.rgb_to_LAB_L_bits(block, (3, 6)))
  45. return data