class Steganography(object): def __init__(self, pathToImage, messageToEncrypt, encryptionMethod, pathToNewImage): self.image = Img(pathToImage) self.message = messageToEncrypt self.encryptionMethod = encryptionMethod self.newPath = pathToNewImage self.key = '' def encrypt(self): self.image.toArray() if (self.encryptionMethod == 'lsb'): l = LSB(self.image.RGB, self.message) l.encrypt() self.key = l.key self.image.RGB = l.image self.image.fromArrayToImage(self.newPath) if (self.encryptionMethod == 'kohonen'): self.image.divide(8,8) k = Kohonen(self.image.divided, self.message) k.setContrastPoints() # k.som(3, 1, 1, 5) k.som3(3, 1, 3, 10) k.encrypt() self.key = k.key self.image.divided = k.image self.image.joinBlocks() self.image.toImage(self.newPath) print('Capacity ' , k.getCapacity()) def decrypt(self): message = '' if (self.encryptionMethod == 'lsb'): image = Img(self.newPath) image.toArray() l = LSB(image.RGB, '') l.decrypt(image.RGB, self.key) message = l.decryptedMessage if (self.encryptionMethod == 'kohonen'): image = Img(self.newPath) image.toArray() k = Kohonen(image, '') image.divide(8,8) k.decrypt(image.divided, self.key) message = k.decryptedMessage return message
def decrypt(self): message = '' if (self.encryptionMethod == 'lsb'): image = Img(self.newPath) image.toArray() l = LSB(image.RGB, '') l.decrypt(image.RGB, self.key) message = l.decryptedMessage if (self.encryptionMethod == 'kohonen'): image = Img(self.newPath) image.toArray() k = Kohonen(image, '') image.divide(8,8) k.decrypt(image.divided, self.key) message = k.decryptedMessage return message
def setContrastPoints(self): # steps 1 - 3 image = self.image contrastPoints = numpy.zeros(len(image)) horizontalContrastPoints = numpy.zeros(len(image)) verticalContrastPoints = numpy.zeros(len(image)) diagonalContrastPoints = numpy.zeros(len(image)) for index in range(len(image)): image0 = Img(path='', array=image[index]) image0.toArray() decomposed = imageDWT(image0, '', level=1) verticalContrast = getContrast(decomposed.get('LL'), decomposed.get('LH')) horizontalContrast = getContrast(decomposed.get('LL'), decomposed.get('HL')) diagonalContrast = getContrast(decomposed.get('LL'), decomposed.get('HH')) globalContrast = getGlobalContrast(verticalContrast, horizontalContrast, diagonalContrast) C = 0 sumVertical = 0 sumHorizontal = 0 sumDiagonal = 0 for i in globalContrast: C += i for j in range(len(verticalContrast)): sumDiagonal += diagonalContrast[j] sumVertical += verticalContrast[j] sumHorizontal += horizontalContrast[j] contrastPoints[index] = C if C < 150 else 0 horizontalContrastPoints[index] = sumHorizontal / len(horizontalContrast) if sumHorizontal < 30 else 0 verticalContrastPoints[index] = sumVertical / len(verticalContrast) if sumVertical < 30 else 0 diagonalContrastPoints[index] = sumDiagonal / len(diagonalContrast) if sumDiagonal < 30 else 0 self.horizontalContrast = horizontalContrastPoints self.verticalContrast = verticalContrastPoints self.diagonalContrast = diagonalContrastPoints self.contrastPoints = contrastPoints
def __init__(self, pathToOrigImage, pathToNewImage): original = Img(pathToOrigImage) stego = Img(pathToNewImage) original.toArray() stego.toArray() self.original = original.RGB self.stego = stego.RGB h,w,_ = self.original.shape self.numPixels = h * w self.MSE() self.corr() self.SSIM() self.Fusion()
def clasterisationPlots(): for image in tqdm(testImages): image = Img(image) image.toArray() image.divide(8, 8) k = Kohonen(image.divided, '') k.setContrastPoints() k.som3(3, 1, 3, 50) k.plot3d(k.horizontalContrast, k.diagonalContrast, k.verticalContrast) k.plot3d(k.horizontalContrast, k.diagonalContrast, k.verticalContrast, k.blocksMapping, k.neuronsMap)
def testImagesDWT(): print('Images DWT calculation') for image in tqdm(testImages): i = Img(image) i.toArray() imageDWT(i, 'imageDWT/' + testImages.get(image) + '.tiff')
def __init__(self, pathToImage, messageToEncrypt, encryptionMethod, pathToNewImage): self.image = Img(pathToImage) self.message = messageToEncrypt self.encryptionMethod = encryptionMethod self.newPath = pathToNewImage self.key = ''