Image Investigation

Last modified: 2023-08-19

Computer Vision Machine Learning

We can investigate images to get secret data or sensitive information hidden in the images.

Basic Information

import numpy as np
from PIL import Image

img = Image.open("example.png")

# Filename
print(img.filename)

# Image information
print(img.info)

# Image format (PNG, JPG, etc.)
print(img.format)

# Color mode (RPG, CMYK, etc.)
print(img.mode)

# Image size
print(img.size)

# Bytes
print(img.tobytes())

# Pixels
print(np.array(img.getdata()))

Hidden Information

We may be able to find hidden data in the image by slightly changing.

import numpy as np
from PIL import Image

img = Image.open("example.png")

# Resize and get bytes
img1 = img.resize((128, 128))
print(img1.tobytes())

# XORing
bytes = img.tobytes()
key = 2 # specify the XOR key
xored = []
for byte in bytes:
	xored.append(byte ^ key)
xored_np = np.array(xored)
print(xored_np)