data_type_module.py 2.2 KB

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