diff --git a/scripts/tagger.py b/scripts/tagger.py index bc6657d..d10ff11 100644 --- a/scripts/tagger.py +++ b/scripts/tagger.py @@ -3,7 +3,6 @@ from modules import script_callbacks from tagger.api import on_app_started from tagger.ui import on_ui_tabs -from tagger.settings import on_ui_settings # if you do not initialize the Image object @@ -16,5 +15,4 @@ script_callbacks.on_app_started(on_app_started) -script_callbacks.on_ui_tabs(on_ui_tabs) -script_callbacks.on_ui_settings(on_ui_settings) +script_callbacks.on_ui_tabs(on_ui_tabs) \ No newline at end of file diff --git a/tagger/Generator/TFDataReader.py b/scripts/tagger/Generator/TFDataReader.py similarity index 100% rename from tagger/Generator/TFDataReader.py rename to scripts/tagger/Generator/TFDataReader.py diff --git a/scripts/tagger/__init__.py b/scripts/tagger/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tagger/api.py b/scripts/tagger/api.py similarity index 100% rename from tagger/api.py rename to scripts/tagger/api.py diff --git a/tagger/api_models.py b/scripts/tagger/api_models.py similarity index 100% rename from tagger/api_models.py rename to scripts/tagger/api_models.py diff --git a/tagger/dbimutils.py b/scripts/tagger/dbimutils.py similarity index 96% rename from tagger/dbimutils.py rename to scripts/tagger/dbimutils.py index 332b25b..e014967 100644 --- a/tagger/dbimutils.py +++ b/scripts/tagger/dbimutils.py @@ -1,54 +1,54 @@ -# DanBooru IMage Utility functions - -import cv2 -import numpy as np -from PIL import Image - - -def smart_imread(img, flag=cv2.IMREAD_UNCHANGED): - if img.endswith(".gif"): - img = Image.open(img) - img = img.convert("RGB") - img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) - else: - img = cv2.imread(img, flag) - return img - - -def smart_24bit(img): - if img.dtype is np.dtype(np.uint16): - img = (img / 257).astype(np.uint8) - - if len(img.shape) == 2: - img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) - elif img.shape[2] == 4: - trans_mask = img[:, :, 3] == 0 - img[trans_mask] = [255, 255, 255, 255] - img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR) - return img - - -def make_square(img, target_size): - old_size = img.shape[:2] - desired_size = max(old_size) - desired_size = max(desired_size, target_size) - - delta_w = desired_size - old_size[1] - delta_h = desired_size - old_size[0] - top, bottom = delta_h // 2, delta_h - (delta_h // 2) - left, right = delta_w // 2, delta_w - (delta_w // 2) - - color = [255, 255, 255] - new_im = cv2.copyMakeBorder( - img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color - ) - return new_im - - -def smart_resize(img, size): - # Assumes the image has already gone through make_square - if img.shape[0] > size: - img = cv2.resize(img, (size, size), interpolation=cv2.INTER_AREA) - elif img.shape[0] < size: - img = cv2.resize(img, (size, size), interpolation=cv2.INTER_CUBIC) - return img +# DanBooru IMage Utility functions + +import cv2 +import numpy as np +from PIL import Image + + +def smart_imread(img, flag=cv2.IMREAD_UNCHANGED): + if img.endswith(".gif"): + img = Image.open(img) + img = img.convert("RGB") + img = cv2.cvtColor(np.array(img), cv2.COLOR_RGB2BGR) + else: + img = cv2.imread(img, flag) + return img + + +def smart_24bit(img): + if img.dtype is np.dtype(np.uint16): + img = (img / 257).astype(np.uint8) + + if len(img.shape) == 2: + img = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR) + elif img.shape[2] == 4: + trans_mask = img[:, :, 3] == 0 + img[trans_mask] = [255, 255, 255, 255] + img = cv2.cvtColor(img, cv2.COLOR_BGRA2BGR) + return img + + +def make_square(img, target_size): + old_size = img.shape[:2] + desired_size = max(old_size) + desired_size = max(desired_size, target_size) + + delta_w = desired_size - old_size[1] + delta_h = desired_size - old_size[0] + top, bottom = delta_h // 2, delta_h - (delta_h // 2) + left, right = delta_w // 2, delta_w - (delta_w // 2) + + color = [255, 255, 255] + new_im = cv2.copyMakeBorder( + img, top, bottom, left, right, cv2.BORDER_CONSTANT, value=color + ) + return new_im + + +def smart_resize(img, size): + # Assumes the image has already gone through make_square + if img.shape[0] > size: + img = cv2.resize(img, (size, size), interpolation=cv2.INTER_AREA) + elif img.shape[0] < size: + img = cv2.resize(img, (size, size), interpolation=cv2.INTER_CUBIC) + return img diff --git a/tagger/format.py b/scripts/tagger/format.py similarity index 100% rename from tagger/format.py rename to scripts/tagger/format.py diff --git a/tagger/interrogator.py b/scripts/tagger/interrogator.py similarity index 100% rename from tagger/interrogator.py rename to scripts/tagger/interrogator.py diff --git a/tagger/preset.py b/scripts/tagger/preset.py similarity index 100% rename from tagger/preset.py rename to scripts/tagger/preset.py diff --git a/tagger/settings.py b/scripts/tagger/settings.py similarity index 100% rename from tagger/settings.py rename to scripts/tagger/settings.py diff --git a/tagger/ui.py b/scripts/tagger/ui.py similarity index 100% rename from tagger/ui.py rename to scripts/tagger/ui.py diff --git a/tagger/uiset.py b/scripts/tagger/uiset.py similarity index 100% rename from tagger/uiset.py rename to scripts/tagger/uiset.py diff --git a/tagger/utils.py b/scripts/tagger/utils.py similarity index 100% rename from tagger/utils.py rename to scripts/tagger/utils.py