<commit_before>from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from PIL import Image, ImageTk, ImageFilter, ImageOps
import numpy as np

image = Image.new('RGB', (800,1280), (255, 255, 255)) #global image
backup = Image.new('RGB', (800,1280), (255, 255, 255)) #backup
histogram = {}

class MyFrame(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("ImageShop")
        self.master.rowconfigure(5, weight=1)
        self.master.columnconfigure(5, weight=1)
        self.master.minsize(width = 600, height = 500)
        self.grid()

        self.buttonLoad = Button(self, text="Open", # load img button
        command = self.load_img, width=10)
        self.buttonLoad.grid()

    def load_img(self):
        global image
        global backup
        imgname = askopenfilename(filetypes=(("JPG files", "*.jpg"),
        ("PNG files", "*.png"),
        ("BMP files", "*.bmp")))
        if imgname:
            try:
                print(imgname)
                image = Image.open(imgname)

                backup = image # to have the original image button

                tkimage = ImageTk.PhotoImage(image)
                Label(image = tkimage).grid(row = 0, column = 8,padx = 10, pady= 10)

                self.buttonHF = Button(self,text="flipH",
                command = self.H_flip,width=10)
                self.buttonHF.grid(row = 1, column = 0, padx = 10, pady = 1) # horizontal flip button

                self.buttonVF = Button(self,text="flipV",
                command = self.V_flip,width=10)
                self.buttonVF.grid(row = 2, column = 0, padx = 10, pady = 1) # vertical flip button

                self.buttonGS = Button(self,text="GrayScale",
                command = self.GSFilter,width=10)
                self.buttonGS.grid(row = 3, column = 0, padx = 10, pady = 1) # GS filter

                self.LblQT = Label(self, text = "QT number:") # label qt
                self.LblQT.grid(row = 4, column = 0, padx = 1, pady =1)

                self.EQT = Entry(self, bd =3, width = 10) # Image quantization
                self.EQT.bind("<Return>",lambda numqt: self.QTFilter(numqt = self.EQT.get()))
                self.EQT.grid(row = 4, column = 1)

                self.buttonQT = Button(self, text="Ok",
                command = lambda: self.QTFilter(numqt = self.EQT.get()), width=10)
                self.buttonQT.grid(row = 4, column = 2, ) # Image qt button


                self.LblSV = Label(self, text = "Save as:") # label qt
                self.LblSV.grid(row = 5, column = 0)

                self.ESV = Entry(self, bd =3, width = 10) # Image quantization
                self.ESV.bind("<Return>",lambda name: self.save_img(name = self.ESV.get()))
                self.ESV.grid(row = 5, column = 1)

                self.buttonSV = Button(self, text="Save", # Image save button
                command = lambda: self.save_img(name = self.ESV.get()),width=10)
                self.buttonSV.grid(row = 5, column = 2)

                self.buttonOI = Button(self, text="Original", # Retrive original image button
                command = self.originalIMG, width = 10)
                self.buttonOI.grid(row = 6, column = 0,  padx = 10, pady = 1)

                self.buttonNEG = Button(self, text = "Negative", # Negative calc button
                command = self.negative, width = 10)
                self.buttonNEG.grid(row = 7, column = 0, padx = 10, pady = 1)

                self.buttonHIST = Button(self, text = "Histogram", # Histogram calc button
                command = self.histogram, width =10)
                self.buttonHIST.grid(row = 8, column =0, padx = 10, pady =1)

                self.lblBV = Label(self, text="Bright value:")  # label brightness
                self.lblBV.grid(row=9, column=0, padx=1, pady=1)

                self.EBV = Entry(self, bd=3, width=10)
                self.EBV.bind("<Return>", lambda: self.brightness_adjust(bright=self.EBV.get()))
                self.EBV.grid(row=9, column=1)

                self.buttonBV = Button(self, text="Ok",
                                       command=lambda: self.brightness_adjust(bright=self.EBV.get()), width=10)
                self.buttonBV.grid(row=9, column=2, )  # Image brightness button

                self.lblCA = Label(self, text="Contrast:")  # label contrast
                self.lblCA.grid(row=10, column=0, padx=1, pady=1)

                self.ECA = Entry(self, bd=3, width=10)
                self.ECA.bind("<Return>", lambda: self.contrast_adjust(contrast_value=self.ECA.get()))
                self.ECA.grid(row=10, column=1)

                self.buttonCA = Button(self, text="Ok",
                                       command=lambda: self.contrast_adjust(contrast_value=self.ECA.get()), width=10)
                self.buttonCA.grid(row=10,  column=2, )  # contrast button

                # ************************** Buttons and Labels for Zooming out **********************************

                self.buttonZO = Button(self, text="Z_out",
                                       command=lambda: self.zoom_out(sx=self.EZOsx.get(), sy=self.EZOsy.get()),
                                       width=10)
                self.buttonZO.grid(row=11, column=0)

                self.lblCA = Label(self, text="Values:")  # label zout
                self.lblCA.grid(row=11, column=1, padx=1, pady=1)

                self.EZOsx = Entry(self, bd=3, width = 3)
                self.EZOsx.grid(row = 11, column = 2)

                self.EZOsy = Entry(self, bd=3, width = 3)
                self.EZOsy.grid(row=11, column = 3)

<commit_msg>histogram working<commit_after>from tkinter import *
from tkinter.filedialog import askopenfilename
from tkinter.messagebox import showerror
from PIL import Image, ImageTk, ImageFilter, ImageOps
import numpy as np

image = Image.new('RGB', (800,1280), (255, 255, 255)) #global image
backup = Image.new('RGB', (800,1280), (255, 255, 255)) #backup
histogram = {}

class MyFrame(Frame):
    def __init__(self):
        Frame.__init__(self)
        self.master.title("ImageShop")
        self.master.rowconfigure(5, weight=1)
        self.master.columnconfigure(5, weight=1)
        self.master.minsize(width = 600, height = 500)
        self.grid()

        self.buttonLoad = Button(self, text="Open", # load img button
        command = self.load_img, width=10)
        self.buttonLoad.grid()

    def load_img(self):
        global image
        global backup
        imgname = askopenfilename(filetypes=(("JPG files", "*.jpg"),
        ("PNG files", "*.png"),
        ("BMP files", "*.bmp")))
        if imgname:
            try:
                print(imgname)
                image = Image.open(imgname)

                backup = image # to have the original image button

                tkimage = ImageTk.PhotoImage(image)
                Label(image = tkimage).grid(row = 0, column = 8,padx = 10, pady= 10)

                self.buttonHF = Button(self,text="flipH",
                command = self.H_flip,width=10)
                self.buttonHF.grid(row = 1, column = 0, padx = 10, pady = 1) # horizontal flip button

                self.buttonVF = Button(self,text="flipV",
                command = self.V_flip,width=10)
                self.buttonVF.grid(row = 2, column = 0, padx = 10, pady = 1) # vertical flip button

                self.buttonGS = Button(self,text="GrayScale",
                command = self.GSFilter,width=10)
                self.buttonGS.grid(row = 3, column = 0, padx = 10, pady = 1) # GS filter

                self.LblQT = Label(self, text = "QT number:") # label qt
                self.LblQT.grid(row = 4, column = 0, padx = 1, pady =1)

                self.EQT = Entry(self, bd =3, width = 5) # Image quantization
                self.EQT.bind("<Return>",lambda numqt: self.QTFilter(numqt = self.EQT.get()))
                self.EQT.grid(row = 4, column = 1)

                self.buttonQT = Button(self, text="Ok",
                command = lambda: self.QTFilter(numqt = self.EQT.get()), width=6)
                self.buttonQT.grid(row = 4, column = 2, ) # Image qt button


                self.LblSV = Label(self, text = "Save as:") # label qt
                self.LblSV.grid(row = 5, column = 0)

                self.ESV = Entry(self, bd =3, width = 5) # Image quantization
                self.ESV.bind("<Return>",lambda name: self.save_img(name = self.ESV.get()))
                self.ESV.grid(row = 5, column = 1)

                self.buttonSV = Button(self, text="Save", # Image save button
                command = lambda: self.save_img(name = self.ESV.get()),width=6)
                self.buttonSV.grid(row = 5, column = 2)

                self.buttonOI = Button(self, text="Original", # Retrive original image button
                command = self.originalIMG, width = 10)
                self.buttonOI.grid(row = 6, column = 0,  padx = 10, pady = 1)

                self.buttonNEG = Button(self, text = "Negative", # Negative calc button
                command = self.negative, width = 10)
                self.buttonNEG.grid(row = 7, column = 0, padx = 10, pady = 1)

                self.buttonHIST = Button(self, text = "Histogram", # Histogram calc button
                command = self.histogram, width =10)
                self.buttonHIST.grid(row = 8, column =0, padx = 10, pady =1)

                self.lblBV = Label(self, text="Bright value:")  # label brightness
                self.lblBV.grid(row=9, column=0, padx=1, pady=1)

                self.EBV = Entry(self, bd=3, width=5)
                self.EBV.bind("<Return>", lambda: self.brightness_adjust(bright=self.EBV.get()))
                self.EBV.grid(row=9, column=1)

                self.buttonBV = Button(self, text="Ok",
                                       command=lambda: self.brightness_adjust(bright=self.EBV.get()), width=6)
                self.buttonBV.grid(row=9, column=2, )  # Image brightness button

                self.lblCA = Label(self, text="Contrast:")  # label contrast
                self.lblCA.grid(row=10, column=0, padx=1, pady=1)

                self.ECA = Entry(self, bd=3, width=5)
                self.ECA.bind("<Return>", lambda: self.contrast_adjust(contrast_value=self.ECA.get()))
                self.ECA.grid(row=10, column=1)

                self.buttonCA = Button(self, text="Ok",
                                       command=lambda: self.contrast_adjust(contrast_value=self.ECA.get()), width=6)
                self.buttonCA.grid(row=10,  column=2, )  # contrast button

                # ************************** Buttons and Labels for Zooming out **********************************

                self.buttonZO = Button(self, text="Z_out",
                                       command=lambda: self.zoom_out(sx=self.EZOsx.get(), sy=self.EZOsy.get()),
                                       width=10)
                self.buttonZO.grid(row=11, column=0)

                self.lblCA = Label(self, text="Values:")  # label zout
                self.lblCA.grid(row=11, column=1, padx=1, pady=1)

                self.EZOsx = Entry(self, bd=3, width = 5)
                self.EZOsx.grid(row = 11, column = 2)

                self.EZOsy = Entry(self, bd=3, width = 5)
                self.EZOsy.grid(row=11, column = 3)


{'fraction_non_alphanumeric': 0.1391472188103176, 'fraction_numerical': 0.028250570275486928, 'mean_word_length': 1.8872847011144884, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4705664', 'n_tokens_mistral': 3891, 'n_tokens_neox': 3411, 'n_words': 781}