import numpy as np
import cv2

def alargamento_constrate(image, limiar):
    height, width = image.shape
    for h in range(0,height):
        for w in range(0,width):
            if image[h, w] < limiar:
                image[h,w] = 0
            else:
                image[h,w] = 1

def log_transformation(image, constant = 1):
    height, width = image.shape
    for h in range(0,height):
        for w in range(0,width):
            image[h,w] = constant * np.log10(image[h,w] + 1)

def powerrating_transformation(image, gama, constant = 1):
    height, width = image.shape
    for h in range(0,height):
        for w in range(0,width):
            image[h,w] = constant * (image[h,w] ** gama)

def bits_plane(image, plane):
    height, width = image.shape
    new_image = np.zeros((height, width))
    n = 8
    for h in range(0,height):
        for w in range(0,width):
            bin_number = '{0:08b}'.format(image[h,w])
            new_image[h,w] = int(bin_number[:n - plane],2)


if __name__ == '__main__':
    img = cv2.imread('ar_chaves.jpg', 0)
    cv2.imshow('image', img)
    #alargamento_constrate(img, 100)
    #log_transformation(img, 1)
    powerrating_transformation(img, 1.0)

@@ -22,16 +22,654 @@
 port cv2
+%0Afrom tkinter import *%0Afrom PIL import Image, ImageTk%0Afrom tkinter import filedialog%0A%0Adef select_image():%0A    global panelA, panelB%0A%0A    path = filedialog.askopenfilename()%0A%0A    if len(path) %3E 0:%0A        image = cv2.imread(path, 0)%0A        #gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)%0A%0A        image = Image.fromarray(image)%0A        image = ImageTk.PhotoImage(image)%0A%0A    if panelA is None and panelB is None:%0A        panelA = Label(image=image)%0A        panelA.image = image%0A        panelA.pack(side='left', padx=10, pady=10)%0A    else:%0A        panelA.configure(image=image)%0A        panelA.image = image%0A%0A# Global Variables%0Aimage = None
 %0A%0Adef al
@@ -940,23 +940,16 @@
 rmation(
-image, 
 constant
@@ -1432,18 +1432,8 @@
 h))%0A
-    n = 8%0A
     
@@ -1561,24 +1561,10 @@
     
-new_image%5Bh,w%5D =
+if
  int
@@ -1579,10 +1579,9 @@
 ber%5B
-:n
+7
  - p
@@ -1589,217 +1589,341 @@
 ane%5D
-,2)%0A%0A%0Aif __name__ == '__main__':%0A    img = cv2.imread('ar_chaves.jpg', 0)%0A    cv2.imshow('image', img)%0A    #alargamento_constrate(img, 100)%0A    #log_transformation(img, 1
+) == 1:%0A                image%5Bh,w%5D = 255%0A            else:%0A                image%5Bh,w%5D = 0%0A%0A%0Aif __name__ == '__main__':%0A    root = Tk()%0A    panelA = None%0A    panelB = None%0A    btn = Button(root, text='Select a image', command=select_image)%0A    btn.pack(side='bottom', fill='both', expand='yes', padx='10', pady='10'
 )%0A
+%0A
     
-powerrating_transformation(img, 1.0
+root.mainloop(
 )%0A

Add bits plane function