Keep processing output resolution when restoring ignored regions
Browse files
app.py
CHANGED
|
@@ -168,11 +168,18 @@ def detect_parts(input_path, part):
|
|
| 168 |
def restore_parts(input_path, output_path, boxes):
|
| 169 |
with Image.open(input_path) as original, Image.open(output_path) as cleaned:
|
| 170 |
result = cleaned.copy()
|
| 171 |
-
|
| 172 |
-
|
| 173 |
original = original.convert(result.mode)
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
result.save(output_path)
|
| 177 |
|
| 178 |
|
|
@@ -207,9 +214,7 @@ def remove_watermark(file_obj, strength, steps, model, ignore_eyes=True, ignore_
|
|
| 207 |
else:
|
| 208 |
model_id = WatermarkRemover.CTRLREGEN_MODEL_ID if model == "CtrlRegen" else None
|
| 209 |
run_watermark(input_path, work_path, strength, int(steps), model_id)
|
| 210 |
-
with Image.open(
|
| 211 |
-
if image.size != original.size:
|
| 212 |
-
image = image.resize(original.size, Image.Resampling.LANCZOS)
|
| 213 |
image.save(output_path)
|
| 214 |
boxes = [box for found in regions.values() for box in found]
|
| 215 |
if boxes:
|
|
|
|
| 168 |
def restore_parts(input_path, output_path, boxes):
|
| 169 |
with Image.open(input_path) as original, Image.open(output_path) as cleaned:
|
| 170 |
result = cleaned.copy()
|
| 171 |
+
width, height = result.size
|
| 172 |
+
sx, sy = width / original.width, height / original.height
|
| 173 |
original = original.convert(result.mode)
|
| 174 |
+
if original.size != result.size:
|
| 175 |
+
original = original.resize(result.size, Image.Resampling.LANCZOS)
|
| 176 |
+
for x1, y1, x2, y2 in boxes:
|
| 177 |
+
box = (
|
| 178 |
+
max(0, math.floor(x1 * sx)), max(0, math.floor(y1 * sy)),
|
| 179 |
+
min(width, math.ceil(x2 * sx)), min(height, math.ceil(y2 * sy)),
|
| 180 |
+
)
|
| 181 |
+
if box[2] > box[0] and box[3] > box[1]:
|
| 182 |
+
result.paste(original.crop(box), box)
|
| 183 |
result.save(output_path)
|
| 184 |
|
| 185 |
|
|
|
|
| 214 |
else:
|
| 215 |
model_id = WatermarkRemover.CTRLREGEN_MODEL_ID if model == "CtrlRegen" else None
|
| 216 |
run_watermark(input_path, work_path, strength, int(steps), model_id)
|
| 217 |
+
with Image.open(work_path) as image:
|
|
|
|
|
|
|
| 218 |
image.save(output_path)
|
| 219 |
boxes = [box for found in regions.values() for box in found]
|
| 220 |
if boxes:
|