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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/.gitignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Default ignored files
/shelf/
/workspace.xml
.ipynb_checkpoints
.DS_Store
2 changes: 1 addition & 1 deletion .idea/GUI.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions .idea/ImageAnnotationProject.iml

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/profiles_settings.xml

This file was deleted.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# SEE-Segment TKinter gui framework

This framework is the start of a Graphical User Interface to help segment images to establish ground truth. To use this tool run the following from python (requires TKinter):

'''python combined.py'''


Binary file renamed .DS_Store → ScrollAndZoom/.DS_Store
Binary file not shown.
122 changes: 122 additions & 0 deletions combined.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import tkinter as tk
from tkinter import filedialog
from PIL import Image, ImageTk


class FileOpening_and_Paint():
def __init__(self, root = None):
self.root = root
#title of GUI window
self.root.title("BRUSH AND ERASE TOOL")
#size of GUI window
self.root.geometry("800x600")
#initial size of brush
self.brush_size = 10
#initial color of brush
self.brush_color = "black"
#initial size of eraser tool
self.eraser_size = 10
self.image = 0

self.create_widgets()
self.setup_bindings()

def create_widgets(self):
#creates a canvas widget with white background
self.canvas = tk.Canvas(self.root, bg="white")
#packs canvas widget into main window
self.canvas.pack(fill=tk.BOTH, expand=True)

self.button = tk.Button(self.root, text="Choose file to upload", command=self.browse_file)
self.button.pack(side="top")
#creates button widget
self.brush_button = tk.Button(self.root, text="Brush", command=self.set_brush_tool)
#packs button widget into main window
self.brush_button.pack(side="top")
#creates eraser button
self.eraser_button = tk.Button(self.root, text="Eraser", command=self.set_eraser_tool)
#packs eraser button into main window
self.eraser_button.pack(side="top")
#creates a Label widget with appropriate text and packs it into main window
brush_size_label = tk.Label(self.root, text="Brush Size:")
#label appears on the left side
brush_size_label.pack(side="top")
#creates horizontal scale widget with values ranging from 1 to 50
self.brush_size_scale = tk.Scale(self.root, from_=1, to=50, orient=tk.HORIZONTAL, command=self.set_brush_size)
#sets brush size to whatever the value in the scale is
self.brush_size_scale.set(self.brush_size)
self.brush_size_scale.pack(side="top")


def browse_file(self):
filetypes = (("JPEG files", "*.jpg"), ("PNG files", "*.png"), ("All files", "*.*"))
filepath = filedialog.askopenfilename(title="Select an image file", filetypes=filetypes)
if filepath:
global image
image = Image.open(filepath)
image = image.convert("RGBA")
self.image = ImageTk.PhotoImage(image)
self.canvas.create_image(0, 0, anchor="nw", image=self.image)

#sets up the event bindings for the canvas widget to enable drawing on the canvas with the brush tool
def setup_bindings(self):
#binds the left mouse button motion event to the draw_brush method when the mouse is moved while the left mouse button is held down
self.canvas.bind("<B1-Motion>", self.draw_brush)
#binds the left mouse button release event to the reset method when the left mouse button is released
self.canvas.bind("<ButtonRelease-1>", self.reset)

#sets the current tool to the brush tool
def set_brush_tool(self):
#sets the instance variable current_tool to the string "brush", indicating that the brush tool is currently selected
self.current_tool = "brush"
#changes the cursor for the canvas widget to a pencil icon
self.canvas.config(cursor="pencil")

#sets the current tool to the eraser tool
def set_eraser_tool(self):
#sets the instance variable current_tool to the string "eraser", indicating that the eraser tool is currently selected
self.current_tool = "eraser"
#changes the cursor for the canvas widget to a tcross icon
self.canvas.config(cursor="tcross")

#updates brush size with whatever the value in the scale is
def set_brush_size(self, size):
self.brush_size = int(size)

#implements the drawing functionality for the brush and eraser tools, depending on the current tool selected by the user
def draw_brush(self, event):
#checks if the current tool selected is the brush tool
if self.current_tool == "brush":
#gets the x and y coordinates of the mouse pointer from the event object
x, y = event.x, event.y
#calculates the top-left corner of the oval to be drawn based on the current mouse position and the size of the brush
x1, y1 = (x - self.brush_size), (y - self.brush_size)
#calculates the bottom-right corner of the oval to be drawn based on the current mouse position and the size of the brush
x2, y2 = (x + self.brush_size), (y + self.brush_size)
#creates an oval shape on the canvas with the calculated coordinates, fill color and outline color specified
self.canvas.create_oval(x1, y1, x2, y2, fill=self.brush_color, outline=self.brush_color)
#checks if the current tool selected is the eraser tool
elif self.current_tool == "eraser":
#gets the x and y coordinates of the mouse pointer from the event object
x, y = event.x, event.y
#calculates the top-left corner of the rectangle to be drawn based on the current mouse position and the size of the eraser
x1, y1 = (x - self.eraser_size), (y - self.eraser_size)
#calculates the bottom-right corner of the rectangle to be drawn based on the current mouse position and the size of the eraser
x2, y2 = (x + self.eraser_size), (y + self.eraser_size)
#creates a white rectangle shape on the canvas with the calculated coordinates, hence erasing anything drawn
self.canvas.create_rectangle(x1, y1, x2, y2, fill="white", outline="white")
self.canvas.create_image(0, 0, anchor="nw", image=self.image)

#called when the user releases the left mouse button after drawing on the canvas
def reset(self, event):
#ensures that there is a new brush stroke from the current mouse position
self.previous_point = None


#represents the main window frame of a Tkinter GUI application
root = tk.Tk()
#defines the behavior of the GUI application
paint = FileOpening_and_Paint(root)
# waits for user input and responds to it by calling the appropriate event handler functions
root.mainloop()

22 changes: 14 additions & 8 deletions File opening/file_opening.py → file_opening/file_opening.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,35 @@
class FileOpening(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.button = tk.Button(self, text="Choose file to upload", command=self.browse_file)
self.select_button = tk.Button(self, text="Choose file to upload", command=self.browse_file)
self.save_button = tk.Button(self, text="Save Image", command=self.save_image)
self.label_image = tk.Label(self)
self.master = master
self.pack()
self.create_widget()

def create_widget(self):
self.button.pack(side="top")
self.select_button.pack(side="top")
self.save_button.pack(side="top")
self.label_image.pack(side="top")

def browse_file(self):
filetypes = (("JPEG files", "*.jpg"), ("PNG files", "*.png"), ("All files", "*.*"))
filepath = filedialog.askopenfilename(title="Select an image file", filetypes=filetypes)
if filepath:
image = Image.open(filepath)
photo = ImageTk.PhotoImage(image)
self.label_image.configure(image=photo)
self.label_image.image = photo
self.image = Image.open(filepath)
self.photo = ImageTk.PhotoImage(self.image)
self.label_image.configure(image=self.photo)
self.label_image.image = self.photo

def save_image(self):
if hasattr(self, 'label_image'):
save_path = filedialog.asksaveasfilename(defaultextension='.jpg')
if save_path:
self.image.save(save_path)


root = tk.Tk()
root.geometry("{0}x{1}+0+0".format(root.winfo_screenwidth(), root.winfo_screenheight()))
win = FileOpening(master=root)
win.mainloop()


Binary file added updated_brush_erase/.DS_Store
Binary file not shown.
Loading