Skip to content

Commit

Permalink
Added tooltips, made low-res step optional
Browse files Browse the repository at this point in the history
  • Loading branch information
JenkinsTR committed Jul 27, 2023
1 parent fcac065 commit 8a20d5a
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ImagePatcherUI/ImagePatcherUI.pyproject.user
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 11.0.0, 2023-07-27T12:40:06. -->
<!-- Written by QtCreator 11.0.0, 2023-07-27T12:58:03. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
Expand Down
16 changes: 14 additions & 2 deletions ImagePatcherUI/form.ui
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@
<height>32</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This output folder will contain your high resolution &amp;quot;Patches&amp;quot;, sometimes referred to as &amp;quot;Ground Truth&amp;quot; images to be used in Neural Network training.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="placeholderText">
<string>This is your output folder containing the full size patched images</string>
</property>
Expand All @@ -76,6 +79,9 @@
<height>32</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This is the output folder for low resolution &amp;quot;scaled&amp;quot; versions of the patches, useful in Neural Network training.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="placeholderText">
<string>This is your output folder containing the scaled Low-Res size patched images</string>
</property>
Expand Down Expand Up @@ -166,7 +172,7 @@
<rect>
<x>20</x>
<y>250</y>
<width>300</width>
<width>431</width>
<height>32</height>
</rect>
</property>
Expand All @@ -176,7 +182,7 @@
</font>
</property>
<property name="text">
<string>Output Low-Res Folder:</string>
<string>Output Low-Res Folder: (optional)</string>
</property>
<property name="textInteractionFlags">
<set>Qt::NoTextInteraction</set>
Expand Down Expand Up @@ -233,6 +239,9 @@
<height>32</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;How much to scale down the Patches.&lt;/p&gt;&lt;p&gt;E.G: if you chose 512 for the Patch Size, then choosing 4x here will produce 128px Low-Res versions&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="currentIndex">
<number>1</number>
</property>
Expand Down Expand Up @@ -266,6 +275,9 @@
<height>32</height>
</rect>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;This can be any pixel size that is smaller than your smallest Source images&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="statusTip">
<string/>
</property>
Expand Down
21 changes: 11 additions & 10 deletions ImagePatcherUI/imagepatcherui.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ def process_image(file, dest_path, dest_path_low_res, patch_size, resize_scale,
f"{os.path.splitext(os.path.basename(file))[0]}_{i}_{j}.png")
cropped.save(output_file)

try:
# Resize for low-resolution
new_size = patch_size // resize_scale
if new_size <= 0:
logging.warning(f"new_size is {new_size}, check resize_scale value.")
low_res = cropped.resize((new_size, new_size), Image.LANCZOS)
low_res.save(os.path.join(dest_path_low_res, f"{os.path.splitext(os.path.basename(file))[0]}_{i}_{j}.png"))
except Exception as e:
logging.error(f"Failed to process low-res image for file {file} with error {e}")
if dest_path_low_res: # Check if this string is not empty
try:
# Resize for low-resolution
new_size = patch_size // resize_scale
if new_size <= 0:
logging.warning(f"new_size is {new_size}, check resize_scale value.")
low_res = cropped.resize((new_size, new_size), Image.LANCZOS)
low_res.save(os.path.join(dest_path_low_res, f"{os.path.splitext(os.path.basename(file))[0]}_{i}_{j}.png"))
except Exception as e:
logging.error(f"Failed to process low-res image for file {file} with error {e}")

with counter_lock: # Lock the counter while updating it
processed_images_counter.value += 1
Expand Down Expand Up @@ -162,7 +163,7 @@ def startProcessing(self):
try:
source_path = self.ui.sourceLineEdit.text()
dest_path = self.ui.outputLineEdit.text()
dest_path_low_res = self.ui.lowResOutputLineEdit.text()
dest_path_low_res = self.ui.lowResOutputLineEdit.text().strip()
patch_size = int(self.ui.patchSizeText.toPlainText())
scale_text = self.ui.comboBoxScale.currentText()
resize_scale = int(scale_text.strip("x"))
Expand Down
16 changes: 14 additions & 2 deletions ImagePatcherUI/ui_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def setupUi(self, ImagePatcherUI):
self.labelOutputFolder.setTextInteractionFlags(Qt.NoTextInteraction)
self.labelOutputLowResFolder = QLabel(ImagePatcherUI)
self.labelOutputLowResFolder.setObjectName(u"labelOutputLowResFolder")
self.labelOutputLowResFolder.setGeometry(QRect(20, 250, 300, 32))
self.labelOutputLowResFolder.setGeometry(QRect(20, 250, 431, 32))
self.labelOutputLowResFolder.setFont(font)
self.labelOutputLowResFolder.setTextInteractionFlags(Qt.NoTextInteraction)
self.labelPatchSize = QLabel(ImagePatcherUI)
Expand Down Expand Up @@ -146,21 +146,33 @@ def retranslateUi(self, ImagePatcherUI):
self.sourceLineEdit.setToolTip(QCoreApplication.translate("ImagePatcherUI", u"<html><head/><body><p>Browse for a folder that contains your highest resolution images. Note: Images MUST be larger than your desired Patch Size</p></body></html>", None))
#endif // QT_CONFIG(tooltip)
self.sourceLineEdit.setPlaceholderText(QCoreApplication.translate("ImagePatcherUI", u"This is your input folder containing all the images you want to process", None))
#if QT_CONFIG(tooltip)
self.outputLineEdit.setToolTip(QCoreApplication.translate("ImagePatcherUI", u"<html><head/><body><p>This output folder will contain your high resolution &quot;Patches&quot;, sometimes referred to as &quot;Ground Truth&quot; images to be used in Neural Network training.</p></body></html>", None))
#endif // QT_CONFIG(tooltip)
self.outputLineEdit.setPlaceholderText(QCoreApplication.translate("ImagePatcherUI", u"This is your output folder containing the full size patched images", None))
#if QT_CONFIG(tooltip)
self.lowResOutputLineEdit.setToolTip(QCoreApplication.translate("ImagePatcherUI", u"<html><head/><body><p>This is the output folder for low resolution &quot;scaled&quot; versions of the patches, useful in Neural Network training.</p></body></html>", None))
#endif // QT_CONFIG(tooltip)
self.lowResOutputLineEdit.setPlaceholderText(QCoreApplication.translate("ImagePatcherUI", u"This is your output folder containing the scaled Low-Res size patched images", None))
self.browseSourceButton.setText(QCoreApplication.translate("ImagePatcherUI", u"Browse", None))
self.browseOutputButton.setText(QCoreApplication.translate("ImagePatcherUI", u"Browse", None))
self.browseLowResOutputButton.setText(QCoreApplication.translate("ImagePatcherUI", u"Browse", None))
self.labelSourceFolder.setText(QCoreApplication.translate("ImagePatcherUI", u"Source Folder:", None))
self.labelOutputFolder.setText(QCoreApplication.translate("ImagePatcherUI", u"Output Folder:", None))
self.labelOutputLowResFolder.setText(QCoreApplication.translate("ImagePatcherUI", u"Output Low-Res Folder:", None))
self.labelOutputLowResFolder.setText(QCoreApplication.translate("ImagePatcherUI", u"Output Low-Res Folder: (optional)", None))
self.labelPatchSize.setText(QCoreApplication.translate("ImagePatcherUI", u"Patch Size:", None))
self.labelLowResScale.setText(QCoreApplication.translate("ImagePatcherUI", u"Low-Res Scale:", None))
self.comboBoxScale.setItemText(0, QCoreApplication.translate("ImagePatcherUI", u"2x", None))
self.comboBoxScale.setItemText(1, QCoreApplication.translate("ImagePatcherUI", u"4x", None))
self.comboBoxScale.setItemText(2, QCoreApplication.translate("ImagePatcherUI", u"6x", None))
self.comboBoxScale.setItemText(3, QCoreApplication.translate("ImagePatcherUI", u"8x", None))

#if QT_CONFIG(tooltip)
self.comboBoxScale.setToolTip(QCoreApplication.translate("ImagePatcherUI", u"<html><head/><body><p>How much to scale down the Patches.</p><p>E.G: if you chose 512 for the Patch Size, then choosing 4x here will produce 128px Low-Res versions</p></body></html>", None))
#endif // QT_CONFIG(tooltip)
#if QT_CONFIG(tooltip)
self.patchSizeText.setToolTip(QCoreApplication.translate("ImagePatcherUI", u"<html><head/><body><p>This can be any pixel size that is smaller than your smallest Source images</p></body></html>", None))
#endif // QT_CONFIG(tooltip)
#if QT_CONFIG(statustip)
self.patchSizeText.setStatusTip("")
#endif // QT_CONFIG(statustip)
Expand Down

0 comments on commit 8a20d5a

Please sign in to comment.