Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions ImageProcessingScripts/Circular Image Cropper/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# ✔ CIRCULAR IMAGE CROPPER
- ### An Circular Image Cropper is an image processing application created in python with tkinter gui and OpenCv library.
- ### In this application user can select an image, and will be able to crop the image circularly.
- ### Also user will be able to see the preview of the original image as well as the cropped image.
- ### User can also reset the cropped image to original format using RESET button.
- ### Also after cropping user will be able to save the cropped image to any where on the local system.

****

# REQUIREMENTS :
- ### python 3=
- ### tkinter module
- ### filedialog from tkinter
- ### messagebox
- ### from PIL import Image, ImageTk, ImageDraw
- ### numpy
- ### cv2

****

# HOW TO Use it :
- ### User just need to download the file, and run the circular_image_cropper.py, on local system.
- ### After running a GUI window appears, where user can see button like START and EXIT.
- ### After user clicks on the START button a main application window will appear, where user needs to select an image file using SELECT button from the local system.
- ### After selecting the image, two images will appear on screen one on left side, which is original and one on write in which Circular Cropped format will be shown.
- ### Now user can start cropping of selected image using CIRCULAR CROP button.
- ### After segmenting user can also save the cropped image to any location in local system using SAVE button.
- ### User can also reset the cropped image to original format using RESET button.s
- ### Also there is exit button, clicking on which we get a exit dialog box asking the permission to exit.

# Purpose :
- ### This scripts helps user to easily crop any image in circular format and even save it anywhere in local system.

# Compilation Steps :
- ### Install tkinter, PIL, numpy, cv2
- ### After that download the code file, and run circular_image_cropper.py on local system.
- ### Then the script will start running and user can explore it by selecting any image and cropping it circularly.

****

# SCREENSHOTS :
****

<p align="center">
<img width = 1000 src="Images/1.jpg" /><br>
<img width = 1000 src="Images/2.jpg" /><br>
<img width = 1000 src="Images/3.jpg" /><br>
<img width = 1000 src="Images/4.jpg" /><br>
<img width = 1000 src="Images/5.jpg" /><br>
<img width = 1000 src="Images/6.jpg" /><br>
<img width = 1000 src="Images/7.jpg" /><br>
<img width = 1000 src="Images/8.jpg" /><br>
<img width = 1000 src="Images/9.jpg" /><br>
<img width = 1000 src="Images/10.jpg" /><br>
<img width = 1000 src="Images/11.jpg" /><br>
<img width = 1000 src="Images/12.jpg" /><br>
</p>

****

# Name :
- ### Akash Ramanand Rajak
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@

# Circular Image Cropper

# imported necessary library
import tkinter
from tkinter import *
import tkinter as tk
import tkinter.messagebox as mbox
from tkinter import filedialog
from PIL import Image, ImageTk, ImageDraw
import numpy as np
import cv2


# Main Window
frame = Tk()
frame.title('Circular Image Cropper')
frame.geometry('1300x750')
# frame.configure(bg = "white")


# image on the main window
path = "Images/front.jpg"
# Creates a Tkinter-compatible photo image, which can be used everywhere Tkinter expects an image object.
img1 = ImageTk.PhotoImage(Image.open(path))
# The Label widget is a standard Tkinter widget used to display a text or image on the screen.
panel = tk.Label(frame, image = img1)
panel.place(x = 270, y = 150)

# starting label
start1 = Label(frame, text='CIRCULAR IMAGE CROPPER', font=("Arial", 55,"underline"),fg="magenta")
start1.place(x=120,y=10)

def start_fun():
frame.destroy()

# creating an exit button
prevB = Button(frame, text='START', command=start_fun, font=("Arial", 25), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
prevB.place(x = 200, y = 620)

# defined exit_win function, to show a exit dialog box when tried to exit
def exit_win():
if mbox.askokcancel("Exit", "Do you want to exit?"):
frame.destroy()

# creating an exit button
prevB = Button(frame, text='EXIT', command=exit_win, font=("Arial", 25), bg = "red", fg = "blue", borderwidth=3, relief="raised")
prevB.place(x = 970, y = 620)

# this is done to show the exit dialog box when tried to exit from the main window, using the top-roght close button of titlebar
frame.protocol("WM_DELETE_WINDOW", exit_win)
frame.mainloop()

#created main window
window = Tk()
window.geometry("1300x750")
window.title("Circular Image Cropper")

# defined variable
global count, emig
# global bright, con
# global frp, tname # list of paths
frp = []
tname = []
con = 1
bright = 0
panelB = None
panelA = None

# function defined to get the path of the image selected
def getpath(path):
a = path.split(r'/')
# print(a)
fname = a[-1]
l = len(fname)
location = path[:-l]
return location

# function defined to get the folder name from which image is selected
def getfoldername(path):
a = path.split(r'/')
# print(a)
name = a[-1]
return name

# function defined to get the file name of image is selected
def getfilename(path):
a = path.split(r'/')
fname = a[-1]
a = fname.split('.')
a = a[0]
return a

# function defined to open the image file
def openfilename():
filename = filedialog.askopenfilename(title='"pen')
return filename

# function defined to open the selected image
def open_img():
global x, panelA, panelB
global count, eimg, location, filename
count = 0
x = openfilename()
img = Image.open(x)
eimg = img
img = ImageTk.PhotoImage(img)
temp = x
location = getpath(temp)
filename = getfilename(temp)
# print(x)
if panelA is None or panelB is None:
panelA = Label(image=img)
panelA.image = img
panelA.pack(side="left", padx=50, pady=12)
panelB = Label(image=img)
panelB.image = img
panelB.pack(side="right", padx=50, pady=12)
else:
panelA.configure(image=img)
panelB.configure(image=img)
panelA.image = img
panelB.image = img

# function defined for cropping image in circle
def crop_fun():
global x
# Open the input image as numpy array, convert to RGB
img = Image.open(x).convert("RGB")
npImage = np.array(img)
h, w = img.size

# Create same size alpha layer with circle
alpha = Image.new('L', img.size, 0)
draw = ImageDraw.Draw(alpha)
draw.pieslice([0, 0, h, w], 0, 360, fill=255)

# Convert alpha Image to numpy array
npAlpha = np.array(alpha)

# Add alpha layer to RGB
npImage = np.dstack((npImage, npAlpha))

# Save with alpha
Image.fromarray(npImage).save('Cropped_Image.png')

imge = Image.open('Cropped_Image.png')
imge = ImageTk.PhotoImage(imge)
panelB.configure(image=imge)
panelB.image = imge
mbox.showinfo("Cropping Status", "Image Cropped in Circle successfully.")

# function defined to reset the edited image to original one
def reset():
global x
# print(x)
image = cv2.imread(x)[:, :, ::-1]
global count, eimg
count = 6
global o6
o6 = image
image = Image.fromarray(o6)
eimg = image
image = ImageTk.PhotoImage(image)
panelB.configure(image=image)
panelB.image = image
mbox.showinfo("Success", "Image reset to original format!")

# function defined to same the edited image
def save_img():
global location, filename, eimg
print(filename)
# eimg.save(location + filename + r"_edit.png")
filename = filedialog.asksaveasfile(mode='w', defaultextension=".jpg")
if not filename:
return
eimg.save(filename)
mbox.showinfo("Success", "Cropped Image Saved Successfully!")



# top label
start1 = tk.Label(text = "CIRCULAR IMAGE\nCROPPER", font=("Arial", 50, "underline"), fg="magenta") # same way bg
start1.place(x = 350, y = 10)

# original image label
start1 = tk.Label(text = "Original\nImage", font=("Arial", 40), fg="magenta") # same way bg
start1.place(x = 100, y = 300)

# edited image label
start1 = tk.Label(text = "Circular Cropped\nImage", font=("Arial", 40), fg="magenta") # same way bg
start1.place(x = 800, y = 300)

# save button created
saveb = Button(window, text="SAVE",command=save_img,font=("Arial", 25), bg = "orange", fg = "blue", borderwidth=3, relief="raised")
saveb.place(x =80 , y =20 )

# choose button created
chooseb = Button(window, text="SELECT",command=open_img,font=("Arial", 25), bg = "light green", fg = "blue", borderwidth=3, relief="raised")
chooseb.place(x =170 , y =650 )

# crop button created
enb = Button(window, text="CIRCULAR CROP",command=crop_fun,font=("Arial", 25), bg = "orange", fg = "blue", borderwidth=3, relief="raised")
enb.place(x =530 , y =650 )

# reset button created
resetb = Button(window, text="RESET",command=reset,font=("Arial", 25), bg = "yellow", fg = "blue", borderwidth=3, relief="raised")
resetb.place(x =1000 , y =650 )

# function created for exiting
def exit_win():
if mbox.askokcancel("Exit", "Do you want to exit?"):
window.destroy()

# exit button created
exitb = Button(window, text="EXIT",command=exit_win,font=("Arial", 25), bg = "red", fg = "blue", borderwidth=3, relief="raised")
exitb.place(x =1100 , y =20 )


window.protocol("WM_DELETE_WINDOW", exit_win)
window.mainloop()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
libraries used : tkinter
from tkinter import filedialog
import tkinter.messagebox
from PIL import ImageTk, Image, ImageDraw
os
cv2
numpy