data_type.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. from ipfml import image_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 = image_processing.get_LAB_L_SVD_s(Image.open(block_file_path))
  13. if data_type == 'mscn_revisited':
  14. img_mscn_revisited = image_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 = image_processing.calculate_mscn_coefficients(img_gray, 7)
  25. img_mscn_norm = image_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 = image_processing.rgb_to_LAB_L_low_bits(block, 63)
  30. # extract from temp image
  31. data = metrics.get_SVD_s(low_bits_6)
  32. if data_type == 'low_bits_5':
  33. low_bits_5 = image_processing.rgb_to_LAB_L_low_bits(block, 31)
  34. # extract from temp image
  35. data = metrics.get_SVD_s(low_bits_5)
  36. if data_type == 'low_bits_4':
  37. low_bits_4 = image_processing.rgb_to_LAB_L_low_bits(block)
  38. # extract from temp image
  39. data = metrics.get_SVD_s(low_bits_4)
  40. if data_type == 'low_bits_3':
  41. low_bits_3 = image_processing.rgb_to_LAB_L_low_bits(block, 7)
  42. # extract from temp image
  43. data = metrics.get_SVD_s(low_bits_3)
  44. if data_type == 'low_bits_2':
  45. low_bits_2 = image_processing.rgb_to_LAB_L_low_bits(block, 3)
  46. # extract from temp image
  47. data = metrics.get_SVD_s(low_bits_2)
  48. if data_type == 'low_bits_4_shifted_2':
  49. data = metrics.get_SVD_s(image_processing.rgb_to_LAB_L_bits(block, (3, 6)))
  50. return data