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
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ I made it to help with tagging my training images when creating embeddings or dr
![Alt text](https://github.com/spaciousmind/image-tag-editor/blob/main/image-tag-editor-UI-screenshot.JPG?raw=true "UI screenshot")

how to use:
just chuck it in the folder where your images are and run it, it'll load all .png and .jpg images in the folder, you can scroll through them with page up or page down keys. If there's a corresponding .txt file with the same name it will open it up and display it in the text editor next to the picture. if there isn't it will create one for you as it loads the image. saves the text files as you scroll through them.
just chuck it in the folder where your images are (or give dataset directory via command line option -i) and run it, it'll load all .png and .jpg images in the folder, you can scroll through them with page up or page down keys. If there's a corresponding .txt file with the same name it will open it up and display it in the text editor next to the picture. if there isn't it will create one for you as it loads the image. saves the text files as you scroll through them.

WARNING:
it will automatically save over the current text file when you hit page up or page down, or when you click on save and exit button, so be careful not to delete anything.
Expand All @@ -15,3 +15,19 @@ It's probably buggy so might wanna back up your files first in another directory

I've just hardcoded the display resolution to 512x768, cause that's what I was working with and I couldn't be bothered figuring out how to make it dynamic based on the images. If you can tell me how please do and I'll update it.
Only been tested in windows 10, with python 3.11


## command line usage

```
$ python3 image tag editor.py --help
usage: image tag editor.py [-h] [-i IMAGES] [-e EXTENSIONS [EXTENSIONS ...]] [-v]

options:
-h, --help show this help message and exit
-i IMAGES, --images IMAGES
input directory with images dataset
-e EXTENSIONS [EXTENSIONS ...], --extensions EXTENSIONS [EXTENSIONS ...]
add file extensions to load (default: JPG jpg png)
-v, --verbose increase verbosity
```
55 changes: 45 additions & 10 deletions image tag editor.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,50 @@
import tkinter as tk
import os

text = ""

# Open an image using the PIL library
image_dir = Path.cwd()
import argparse
import logging as log

image_files = [f for f in os.listdir(image_dir) if f.endswith('.png') or f.endswith('.jpg')]
text = ""
image_extensions = {"jpg", "png", "JPG"}

# get cmdline options
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--images',
help="input directory with images dataset",
default=Path.cwd())
parser.add_argument('-e', '--extensions',
help="add file extensions to load (default: %s)" % (" ".join(image_extensions)),
default=image_extensions,
nargs='+')
parser.add_argument('-v', '--verbose',
action='count',
help="increase verbosity",
default=0)
args = parser.parse_args()

# init logging for verbosity
# Level value verbose
# CRITICAL 50
# ERROR 40
# WARNING 30 0
# INFO 20 1 -v
# DEBUG 10 2 -vv
# NOTSET 0
log_level = log.WARNING - 10 * args.verbose
log.basicConfig(format="%(levelname)s: %(message)s", level=log_level)

image_dir = args.images
image_extensions = image_extensions.union(set(args.extensions))

log.debug("Very Verbose output. level=%d" % (log_level))
log.debug ("Will load files ending by %s" % (", ".join(image_extensions)))

image_files = [f for f in os.listdir(image_dir) if f.endswith(tuple(image_extensions))]
image_names = [file[:-4] for file in image_files]
text_file_paths = [os.path.join(image_dir, image_file[:-4] + '.txt') for image_file in image_files]

log.info ("Found %d images in %s" % (len (image_files), image_dir) )

images = []
for image_file in image_files:
image_path = os.path.join(image_dir, image_file)
Expand Down Expand Up @@ -58,7 +93,7 @@ def update_text_file(text, file_path):



# Function to update the image displayed in the
# Function to update the image displayed in the
def update_image():
global current_image
if current_image:
Expand All @@ -72,7 +107,7 @@ def update_image():
else:
text = ""
create_text_file("", current_text_file)
print("created " + image_names[current_image_index] + ".txt")
log.info ("created " + image_names[current_image_index] + ".txt")


img = img.resize((512, 768), Image.LANCZOS)
Expand Down Expand Up @@ -106,13 +141,13 @@ def on_key_press(event):


def load_text_file(file):
with open(file, "r") as f:
with open(file, "r") as f:
content = f.read()
entry.insert(INSERT, content)

def save_text_file(file):
text = str(entry.get(1.0, END))
with open(file, "w") as f:
with open(file, "w") as f:
f.write(text)

def clearFile():
Expand Down Expand Up @@ -166,4 +201,4 @@ def saveAndExitButton():
entry.grid(row=0,column=1,sticky="nsew", padx=15, pady=(15, 60))

update_image()
canvas.mainloop()
canvas.mainloop()