0% found this document useful (0 votes)
8 views1 page

Activity 9 Python

This Python code takes three images as input, resizes one to match the dimensions of another, and encrypts the pixels of the first image by combining the most significant bits of the pixel values from all three images.

Uploaded by

Nicko De Guzman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Activity 9 Python

This Python code takes three images as input, resizes one to match the dimensions of another, and encrypts the pixels of the first image by combining the most significant bits of the pixel values from all three images.

Uploaded by

Nicko De Guzman
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

import cv2

import numpy as np
import random

# Encryption function
def encrypt(img1_path, img2_path, img3_path):
# Load images
img1 = cv2.imread(img1_path)
img2 = cv2.imread(img2_path)
img3 = cv2.imread(img3_path)

# Resize img2 to match the dimensions of img1


img2 = cv2.resize(img2, (img1.shape[1], img1.shape[0]))

for i in range(img2.shape[0]):
for j in range(img2.shape[1]):
for l in range(3): # 3 channels R, G, B
# v1, v2, and v3 are 8-bit pixel values of img1, img2, and img3
respectively
v1 = format(img1[i][j][l], '08b')
v2 = format(img2[i][j][l], '08b')
v3 = format(img3[i][j][l], '08b')

# Taking 4 Most Significant Bits of each image


v_combined = v1[:4] + v2[:2] + v3[:2]
img1[i][j][l] = int(v_combined, 2)

# Save the resulting image


cv2.imwrite('pic3in1.png', img1)

# Example usage
encrypt('pic1.jpg', 'pic2.jpg', 'pic3.jpg')

You might also like