| import streamlit as st
|
| from PIL import Image
|
| import numpy as np
|
|
|
| def steganography_detection():
|
| def lsb_analysis(image):
|
| """
|
| Analyzes the Least Significant Bits (LSB) of the image pixels
|
| and checks for irregularities that might indicate hidden data.
|
| """
|
| img = Image.open(image)
|
| img = img.convert('RGB')
|
| pixels = np.array(img)
|
|
|
| if len(pixels.shape) != 3 or pixels.shape[2] != 3:
|
| raise ValueError("Unsupported image format. Please use RGB images.")
|
|
|
| height, width, _ = pixels.shape
|
|
|
| lsb_count = [0, 0]
|
| lsb_distribution = []
|
|
|
|
|
| for y in range(height):
|
| for x in range(width):
|
| pixel = pixels[y, x]
|
| for channel in range(3):
|
| lsb = pixel[channel] & 1
|
| lsb_count[lsb] += 1
|
| lsb_distribution.append(lsb)
|
|
|
| total_lsb = sum(lsb_count)
|
| if total_lsb == 0:
|
| return None, None
|
|
|
|
|
| lsb_percentage = [count / total_lsb * 100 for count in lsb_count]
|
| return lsb_percentage, lsb_distribution
|
|
|
| st.title("Steganography Detection Tool")
|
| st.subheader("Analyze images for hidden messages based on LSB irregularities")
|
|
|
| uploaded_image = st.file_uploader("Upload an image to analyze", type=["png", "jpg", "jpeg"])
|
| analyze_button = st.button("Analyze Image")
|
|
|
| if analyze_button:
|
| if uploaded_image:
|
| try:
|
| st.image(uploaded_image, caption="Uploaded Image", use_column_width=True)
|
| lsb_percentage, lsb_distribution = lsb_analysis(uploaded_image)
|
|
|
| if lsb_percentage is None:
|
| st.error("Unable to analyze the image.")
|
| else:
|
| st.write("### LSB Distribution Analysis")
|
| st.write(f"**Percentage of LSBs:**\n- 0s: {lsb_percentage[0]:.2f}%\n- 1s: {lsb_percentage[1]:.2f}%")
|
|
|
|
|
| st.write("### Visualization of LSB Distribution")
|
| st.bar_chart({
|
| "LSB Values": ["0s", "1s"],
|
| "Percentage": lsb_percentage
|
| })
|
|
|
|
|
| threshold = 50
|
| if abs(lsb_percentage[0] - lsb_percentage[1]) > 5:
|
| st.warning("The image shows irregular LSB distribution, suggesting possible steganographic modification.")
|
| else:
|
| st.success("The LSB distribution appears normal, with no clear indication of hidden data.")
|
|
|
| except Exception as e:
|
| st.error(f"An error occurred while analyzing the image: {e}")
|
| else:
|
| st.error("Please upload an image for analysis.")
|
|
|