Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- from numpy import asarray
- import numpy as np
- import os
- os.system("cls")
- def image2Matrix(img):
- sample = Image.open(img)
- # Resing image to fix size
- sample = sample.resize((400,400))
- # Converting image to numpy array
- npData = asarray(sample)
- return npData
- alpha = 10
- ####################### Embedding starts ###################
- # Input cover image scan
- numpyDataCover = image2Matrix("Sample.png")
- # QR decomposition for cover image
- Qc, Rc = np.linalg.qr(numpyDataCover)
- # Input secret image scan
- numpyDataSecret = image2Matrix("Sample3.png")
- # QR decomposition for image 2
- Qs, Rs = np.linalg.qr(numpyDataSecret)
- # Embedding both matrix
- Rn = Rc + alpha*Rs
- # Producing Stego image
- Si = np.matmul(Qc, Rn)
- ####################### Extraction starts ###################
- # Matrix QR decomposition
- Qsi, Rsi = np.linalg.qr(Si)
- # Extracting the embedded matrix
- Rnew = (Rsi-Rc)/alpha
- # Output secret image
- secretImage = np.matmul(Qs, Rnew)
- # Secret image from array
- pilImage = Image.fromarray((secretImage).astype(np.uint8))
- pilImage.show()
Advertisement
Add Comment
Please, Sign In to add comment