sandeep03edu

Image Hiding QR decomposition

Apr 18th, 2023 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. from PIL import Image
  2. from numpy import asarray
  3. import numpy as np
  4.  
  5. import os
  6. os.system("cls")
  7.  
  8. def image2Matrix(img):
  9.     sample = Image.open(img)
  10.  
  11.     # Resing image to fix size
  12.     sample = sample.resize((400,400))
  13.  
  14.     # Converting image to numpy array
  15.     npData = asarray(sample)
  16.     return npData
  17.  
  18. alpha = 10
  19.  
  20. ####################### Embedding starts ###################
  21.  
  22. # Input cover image scan
  23. numpyDataCover = image2Matrix("Sample.png")
  24.  
  25. # QR decomposition for cover image
  26. Qc, Rc = np.linalg.qr(numpyDataCover)
  27.  
  28. # Input secret image scan
  29. numpyDataSecret = image2Matrix("Sample3.png")
  30.  
  31. # QR decomposition for image 2
  32. Qs, Rs = np.linalg.qr(numpyDataSecret)
  33.  
  34. # Embedding both matrix
  35. Rn = Rc + alpha*Rs
  36.  
  37. # Producing Stego image
  38. Si = np.matmul(Qc, Rn)
  39.  
  40.  
  41. ####################### Extraction starts ###################
  42.  
  43. # Matrix QR decomposition
  44. Qsi, Rsi = np.linalg.qr(Si)
  45.  
  46. # Extracting the embedded matrix
  47. Rnew = (Rsi-Rc)/alpha
  48.  
  49. # Output secret image
  50. secretImage = np.matmul(Qs, Rnew)
  51.  
  52. # Secret image from array
  53. pilImage = Image.fromarray((secretImage).astype(np.uint8))
  54. pilImage.show()
Advertisement
Add Comment
Please, Sign In to add comment