<jupyter_start><jupyter_text><jupyter_code>from PIL import ImageColor
from PIL import Image, ImageFilter
import binascii
import cv2 
from math import log
from math import e
from scipy import stats
from numpy import asarray
from math import floor
import numpy as np 
from google.colab.patches import cv2_imshow  
import matplotlib.pyplot as plt 
%matplotlib inline
image = cv2.imread('star.jpg') 
image = cv2.resize(image, (430, 430))
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
 cv2_imshow(gray)
row,col = gray.shape
height = int(row/10)
width = int(col/10)
entropy = np.zeros([height, width])
stdev = np.zeros([height, width])
#entropy,stdev = entropyanalisis(height,width,gray,10)

for i in range(height):
  for j in range(width):
    lst=[]
    for k in range(i*10,i*10+10):
      for l in range(j*10,j*10+10):
        lst.append(gray[k,l])
    stdev[i,j]= log((np.std(np.array(lst))),2)
    unique, frequency = np.unique(np.array(lst), return_counts = True)
    prob=frequency/100
    entropy[i,j]=stats.entropy(prob,base=2)


"""def entropyanalisis(heigth,width,grayimage,submatsize):
  entropy = np.zeros([height, width])
  stdev = np.zeros([height, width])
  for i in range(height):
    for j in range(width):
      lst=[]
      for k in range(i*submatsize,i*submatsize+submatsize):
        for l in range(j*submatsize,j*submatsize+submatsize):
          lst.append(gray[k,l])
      stdev[i,j]= log((np.std(np.array(lst))),2)
      unique, frequency = np.unique(np.array(lst), return_counts = True)
      totalcount = submatsize*submatsize
      prob=frequency/totalcount
      entropy[i,j]=stats.entropy(prob,base=2)
      return entropy,stdev"""
c=plt.imshow(entropy, cmap='hot',vmin = np.min(entropy), vmax = np.max(entropy) , interpolation='nearest')
plt.colorbar(c)
plt.title('  entropy  ', fontweight ="bold")
plt.show()
c=plt.imshow(stdev, cmap='hot',vmin = np.min(stdev), vmax = np.max(stdev) , interpolation='nearest')
plt.colorbar(c)
plt.title('  stdev  ', fontweight ="bold")
plt.show()
"""for i in range(h):
  for j in range(w):
    for k in range(i*4,i*4+4):
      for l in range(j*4,j*4+4):
        print(i,j,k,l)"""
image = cv2.imread('lena.png') 
#image = cv2.resize(image, (430, 430))
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
gray.shape
cv2_imshow(gray)
row,col = gray.shape
height = int(row/5)
width = int(col/5)
entropy = np.zeros([height, width])
stdev = np.zeros([height, width])
for i in range(height):
  for j in range(width):
    lst=[]
    for k in range(i*5,i*5+5):
      for l in range(j*5,j*5+5):
        lst.append(gray[k,l])
    stdev[i,j]= log((np.std(np.array(lst))),2)
    unique, frequency = np.unique(np.array(lst), return_counts = True)
    prob=frequency/25
    entropy[i,j]=stats.entropy(prob,base=2)
entropy.shape
c=plt.imshow(entropy, cmap='hot',vmin = np.min(entropy), vmax = np.max(entropy) , interpolation='nearest')
plt.colorbar(c)
plt.title('  entropy  ', fontweight ="bold")
plt.show()
c=plt.imshow(stdev, cmap='hot',vmin = np.min(stdev), vmax = np.max(stdev) , interpolation='nearest')
plt.colorbar(c)
plt.title('  stdev  ', fontweight ="bold")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1667725540025413, 'fraction_numerical': 0.021918678526048285, 'mean_word_length': 4.603202846975089, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '549520', 'license': 'MIT', 'n_tokens_mistral': 1290, 'n_tokens_neox': 1255, 'n_words': 253, 'path': 'entropyanalysis.ipynb', 'repo_name': 'mridulbiswas402/entropy-based-stegnography', 'size': '3148'}