Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcb9be2bdc | ||
|
|
9304be69a8 | ||
|
|
c636d73223 | ||
|
|
6db92cdd28 | ||
|
|
3c6cbd3a41 | ||
|
|
aaf3ae6ae6 | ||
|
|
d62d263725 | ||
|
|
ffd4e66654 | ||
|
|
7f97d84a88 | ||
|
|
acfe587691 | ||
|
|
f87d710d14 | ||
|
|
85da4a4d0e | ||
|
|
4832789b48 |
@@ -2,6 +2,47 @@
|
||||
|
||||
All notable changes to ComfyUI-AusBoss are documented here.
|
||||
|
||||
## 2.26.6 - 2026-11-20
|
||||
|
||||
- **Image Toolbox's help page says what happens with too many pieces.**
|
||||
Asking for more pieces than the picture is wide in pixels gives one piece
|
||||
per pixel column, so fewer pieces than asked for. The page now says so.
|
||||
|
||||
## 2.26.5 - 2026-11-20
|
||||
|
||||
- **New node: Image Toolbox.** Small picture jobs in one node: pick the job
|
||||
from a list. Its first job, split sheet at gaps, cuts a row of pictures
|
||||
such as a character sheet's four views into separate pictures. Each cut
|
||||
goes to the gap between two pictures instead of an equal share of the
|
||||
width, so no piece gets part of its neighbour's sleeve. The pieces come out
|
||||
as one batch of the same size, padded with the sheet's backdrop colour.
|
||||
- **Box edits on big photos start much sooner.** Crop For Inpaint,
|
||||
Image Crop + Rotate + Pad and Stitch Inpaint grew and softened their
|
||||
masks across the whole picture, even when the box was small or there was
|
||||
nothing to do. On a 17 MP photo that took about 5 seconds before the
|
||||
model started. The work now covers only the area around the mask:
|
||||
Crop For Inpaint went from 3.1 s to 0.14 s, and Image Crop + Rotate + Pad
|
||||
with nothing to do from 2.2 s to 0.5 s. The results are the same pixels.
|
||||
|
||||
- **Stitch Inpaint can paste past the box.** Edit models that redraw the
|
||||
whole crop, such as MiniMax H3 Image, often draw a new boot, a plate rim
|
||||
or a collar a little past the box, and the paste cut it off at the box's
|
||||
edge. Turn on the new **Follow changes** switch: the paste then grows to
|
||||
every change that touches the box, and fades out before the edge of the
|
||||
crop. It first undoes the small zoom or shift such a model can draw, so
|
||||
the wall or table around the edit lines up again. When the model redrew
|
||||
nearly everything around the box, the paste stays the box. It is off by
|
||||
default, so saved workflows paste exactly as before.
|
||||
|
||||
- **LoRA Loader's + LoRA list opens with its folders folded.** A big LoRA
|
||||
folder now opens as a short list of top folders. **Open all** and
|
||||
**Fold all** beside the search box open or fold every folder at once,
|
||||
and **Alt**- or **Shift**-click on a folder's arrow does the same for
|
||||
that folder and every folder inside it. **Left** on a highlighted file
|
||||
folds the folder it is in and moves up to it. To keep the old way, where
|
||||
the list opens as you left it, set **Settings → 🆎 AusBoss → LoRA Loader
|
||||
→ Picker folders** to **Remember my folds**.
|
||||
|
||||
## 2.26.4 - 2026-11-18
|
||||
|
||||
- **A video upload stops at 4 GB.** Dropping a video on Load Video had no
|
||||
|
||||
@@ -136,6 +136,10 @@ Rounds a picture's size to a multiple you choose, by resizing, cropping or paddi
|
||||
|
||||
Reads a picture's `width`, `height`, `longest_edge`, `shortest_edge` and batch `count` as whole numbers. Wire them into a resize, a latent, a frame count or Math Expression, so the rest of the graph follows the source's size. After a run the node shows each number beside its output.
|
||||
|
||||
### Image Toolbox
|
||||
|
||||
Small picture jobs in one node, picked from a list. **split sheet at gaps** cuts a row of pictures, such as a character sheet's views, into separate pictures, cutting at the gaps between them so no piece gets part of its neighbour.
|
||||
|
||||
### Color Match
|
||||
|
||||
Matches a picture's colors to a reference, with LAB, RGB, MKL or histogram transfer. Strength sets how much, and an optional mask (with invert) limits where. With `reference_mode` set to first frame, every frame of a batch matches the batch's first frame. That can cut down color drift in a clip, but it does not steady motion.
|
||||
|
||||
@@ -31,6 +31,7 @@ NODE_MODULES = [
|
||||
"node_image_folder",
|
||||
"node_image_resize",
|
||||
"node_image_size",
|
||||
"node_image_toolbox",
|
||||
"node_inpaint_crop_stitch",
|
||||
"node_krea2_encode",
|
||||
"node_krea2_model_patch",
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="105" height="20" role="img" aria-label="release: v2.26.4">
|
||||
<title>release: v2.26.4</title>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="105" height="20" role="img" aria-label="release: v2.26.6">
|
||||
<title>release: v2.26.6</title>
|
||||
<path fill="#555" d="M0 0h48v20H0z"/>
|
||||
<path fill="#00b4aa" d="M48 0h57v20H48z"/>
|
||||
<g fill="#fff" text-anchor="middle" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" font-size="11">
|
||||
<text x="24" y="14">release</text>
|
||||
<text x="76.5" y="14">v2.26.4</text>
|
||||
<text x="76.5" y="14">v2.26.6</text>
|
||||
</g>
|
||||
</svg>
|
||||
|
||||
|
Before Width: | Height: | Size: 425 B After Width: | Height: | Size: 425 B |
@@ -0,0 +1,44 @@
|
||||
# Image Toolbox
|
||||
|
||||
Small picture jobs in one node. Pick the job from the **Job** list (`job`);
|
||||
the rows under it change to what that job needs.
|
||||
|
||||
## Jobs
|
||||
|
||||
### split sheet at gaps
|
||||
|
||||
Cuts a row of pictures that sit side by side, such as the four views of a
|
||||
character sheet, into separate pictures.
|
||||
|
||||
- **Pieces** (`pieces`): how many pictures are on the sheet. 4 for a
|
||||
four-view character sheet.
|
||||
|
||||
Each cut goes to the gap between two pictures, not to an equal share of the
|
||||
width. An image model rarely puts each view exactly on its quarter of a
|
||||
sheet, so cutting into equal parts can leave part of a neighbour's sleeve in
|
||||
one piece and cut another's off. Here every piece holds one picture.
|
||||
|
||||
The pieces come out as one batch, from left to right, all the same size.
|
||||
Narrower pieces are padded with the sheet's backdrop colour. The first and
|
||||
last pieces keep the sheet's own left and right edges at their outer edge,
|
||||
so a person drawn up to the edge of the sheet does not look cut off by a
|
||||
band of padding. Wire the batch into Save Image to save each piece as its
|
||||
own file.
|
||||
|
||||
A batch of sheets is cut sheet by sheet: the first sheet's pieces, then the
|
||||
next sheet's.
|
||||
|
||||
## Technical details
|
||||
|
||||
- The backdrop colour is the median colour of the picture's border.
|
||||
- A pixel counts as part of a picture when any channel differs from the
|
||||
backdrop by more than 0.1 (on a 0-1 scale).
|
||||
- Each cut looks for the column with the fewest such pixels, up to 40% of
|
||||
one piece's width either side of the equal-share line, and takes the
|
||||
middle of the longest run of those columns.
|
||||
- When two pictures overlap on the sheet, no column is clean. The cut then
|
||||
goes where the least of them is lost, and a small part of one can remain
|
||||
in the other's piece.
|
||||
- Pieces set to 1 returns the picture unchanged.
|
||||
- Pieces higher than the picture's width in pixels gives one piece per
|
||||
pixel column, so fewer pieces than asked for.
|
||||
@@ -176,8 +176,15 @@ last one you ticked and the one you click. Ticks stay while you search, so you c
|
||||
gather files from several searches; **Clear** unticks them all. Files that
|
||||
are already in the stack say **in stack** and have no box. With the
|
||||
keyboard, **Ctrl+Enter** ticks the highlighted file and **Shift+Enter**
|
||||
ticks the run up to it. Use the arrow beside a folder to collapse or expand it without
|
||||
adding anything. Folded folders are remembered in this browser. Search
|
||||
ticks the run up to it. The list opens with every folder folded. Use the
|
||||
arrow beside a folder to open or fold it without adding anything.
|
||||
**Open all** beside the search box opens every folder at once (it then
|
||||
reads **Fold all**), and **Alt**- or **Shift**-click on a folder's arrow
|
||||
opens or folds that folder and every folder inside it. With the keyboard,
|
||||
**Right** opens the highlighted folder and **Left** folds it; **Left** on a
|
||||
file folds the folder it is in and moves up to it. To have the list open
|
||||
the way you left it instead, set **Settings → 🆎 AusBoss → LoRA Loader →
|
||||
Picker folders** to **Remember my folds**. Search
|
||||
reveals matching files; clearing it brings back your folded view. You can
|
||||
also fold folders while searching.
|
||||
|
||||
|
||||
@@ -7,6 +7,43 @@ from **Crop For Inpaint 🆎**, **Load Image + Pad 🆎** or any
|
||||
result, it is resized to fit first, then joined to your picture the way
|
||||
**Seam** says.
|
||||
|
||||
## Follow changes
|
||||
|
||||
Turn on **Follow changes** when the model draws past your box and the paste
|
||||
cuts it off: a boot that ends at the box's edge, half a plate rim, a collar
|
||||
sliced flat. Edit models that redraw the whole crop they are given, such as
|
||||
MiniMax H3 Image, do this often.
|
||||
|
||||
With it on, the paste is no longer just the box. It takes the box plus every
|
||||
change the model made that touches the box, and fades out before the edge
|
||||
of the crop that went to the model. Before that, it undoes the small zoom or
|
||||
shift such a model can draw, so the wall, tiles or table around the edit line
|
||||
up with your picture again.
|
||||
|
||||
When the model changed nearly everything around the box, there is no single
|
||||
new thing to follow, and the paste stays the box. The console says what was
|
||||
done on each run. Follow changes works on a Crop For Inpaint stitcher with
|
||||
the classic seam; an outpaint has no picture under its new area to compare
|
||||
against, so it pastes as before.
|
||||
|
||||
### Technical details
|
||||
|
||||
- The model's crop is lined up with the picture's own crop by the zoom and
|
||||
shift Realign to Source measures (up to 20% zoom). An unreliable
|
||||
measurement leaves the crop as it came back.
|
||||
- A pixel counts as changed when the lined-up crop differs from your
|
||||
picture by more than 0.10 (on 0 to 1, averaged over red, green and blue,
|
||||
after a 4 px blur). Changes are joined to the box when they come within
|
||||
8 px of it, then closed by 6 px, filled, widened by 10 px and softened by
|
||||
10 px.
|
||||
- The paste fades to nothing over 24 px before each crop edge that lies
|
||||
inside your picture, and runs to the picture's own edge where the crop
|
||||
reaches it.
|
||||
- When the changes outside the box cover more than half of the crop outside
|
||||
the box, the paste stays the box.
|
||||
- The work runs at most 768 px on the long side and takes under a second
|
||||
on a 4 MP crop.
|
||||
|
||||
## Paste onto: crop or original
|
||||
|
||||
**Paste onto** picks what you get back. It lives in the gear menu, next to
|
||||
|
||||
+76
-11
@@ -9,6 +9,7 @@ import {
|
||||
loadSettings,
|
||||
openSettingsMenu,
|
||||
} from "../shared/settings_menu.mjs";
|
||||
import { compactAction } from "../shared/panel_controls.mjs";
|
||||
import { makeScrubInput } from "../shared/scrub_input.mjs";
|
||||
import { isAppShortcut, keepKeyInField } from "../shared/canvas_passthrough.mjs";
|
||||
import { resetUnknownValues } from "../shared/widget_card_math.mjs";
|
||||
@@ -47,6 +48,8 @@ import {
|
||||
collectUpstreamLoaders,
|
||||
collectDownstreamLoaders,
|
||||
absorbChainIssue,
|
||||
anyFolderOpen,
|
||||
parentFolder,
|
||||
mergeImportedRows,
|
||||
moveGroup,
|
||||
moveHighlight,
|
||||
@@ -65,6 +68,7 @@ import {
|
||||
scrubValue,
|
||||
serializeRows,
|
||||
setGroupEnabled,
|
||||
setFolderFolds,
|
||||
setGroupOff,
|
||||
setStrength,
|
||||
shortLoraName,
|
||||
@@ -394,6 +398,10 @@ function installStyles() {
|
||||
.ausboss-lora-pop { position: fixed; z-index: 10000; background: #1c1f23;
|
||||
border: 1px solid #3a4047; border-radius: 7px; box-shadow: 0 8px 28px rgba(0,0,0,.5);
|
||||
font: ${POP_FONT}; color: #d7dde2; display: flex; flex-direction: column; }
|
||||
.ausboss-lora-pickhead { display: flex; align-items: center; gap: 6px; margin: 8px; }
|
||||
.ausboss-lora-pickhead .ausboss-lora-search { flex: 1 1 auto; min-width: 0; margin: 0; }
|
||||
/* Wide enough for either label, so the search box keeps its width. */
|
||||
.ausboss-lora-pickhead .ausboss-compact-action { min-width: 64px; }
|
||||
.ausboss-lora-search { margin: 8px; height: 26px; border: 1px solid #3a4047; border-radius: 5px;
|
||||
background: #23272c; color: inherit; padding: 0 8px; outline: none; }
|
||||
.ausboss-lora-search:focus { border-color: ${BRAND}; }
|
||||
@@ -1006,6 +1014,14 @@ let widestPickerLabel = 0;
|
||||
const COLLAPSED_FOLDERS_KEY = "AusBoss.lora_loader.collapsedFolders";
|
||||
let rememberedCollapsedFolders = new Set();
|
||||
|
||||
// "Start folded" (the default) opens the picker with every folder folded
|
||||
// and forgets folds when it closes. "Remember my folds" keeps them.
|
||||
const PICKER_FOLDERS_SETTING = "AusBoss.LoraLoader.PickerFolders";
|
||||
const START_FOLDED = "Start folded";
|
||||
const REMEMBER_FOLDS = "Remember my folds";
|
||||
const pickerStartsFolded = () =>
|
||||
(app.ui?.settings?.getSettingValue?.(PICKER_FOLDERS_SETTING) ?? START_FOLDED) !== REMEMBER_FOLDS;
|
||||
|
||||
function loadCollapsedFolders() {
|
||||
try {
|
||||
const raw = window.localStorage?.getItem(COLLAPSED_FOLDERS_KEY);
|
||||
@@ -1040,9 +1056,15 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
const search = el("input", "ausboss-lora-search");
|
||||
search.placeholder = "Search LoRAs...";
|
||||
search.setAttribute("aria-label", "Search LoRAs");
|
||||
// Folds or opens every folder at once. Hidden until the list has folders.
|
||||
const foldAll = compactAction("Fold all");
|
||||
foldAll.hidden = true;
|
||||
foldAll.addEventListener("keydown", keepKeyInField);
|
||||
const head = el("div", "ausboss-lora-pickhead");
|
||||
head.append(search, foldAll);
|
||||
const list = el("div", "ausboss-lora-list");
|
||||
list.append(el("div", "ausboss-lora-empty", "Loading..."));
|
||||
pop.append(search, list);
|
||||
pop.append(head, list);
|
||||
if (adding) pop.append(el("div", "ausboss-lora-picker-note",
|
||||
"Click a file to add it. Tick boxes (or Ctrl-click) to add several at once. Click a folder name to add all of it. Skips files already in this stack."));
|
||||
const anchorRect = anchor.getBoundingClientRect();
|
||||
@@ -1065,7 +1087,8 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
const inStack = () => new Set(state.rows.map((row) => pathKey(row.name)));
|
||||
let loadError = false;
|
||||
let highlight = -1;
|
||||
const collapsedFolders = loadCollapsedFolders();
|
||||
const startFolded = pickerStartsFolded();
|
||||
const collapsedFolders = startFolded ? new Set() : loadCollapsedFolders();
|
||||
// Search reveals matches without losing the user's usual folded view.
|
||||
let searchCollapsed = new Set();
|
||||
const currentFolds = () => search.value.trim() ? searchCollapsed : collapsedFolders;
|
||||
@@ -1073,15 +1096,21 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
// after: "highlight" keeps the folder highlighted for the search box's
|
||||
// arrow keys, "arrow" keeps focus on the fold arrow that was pressed with
|
||||
// the keyboard, "search" hands the keys back to the search box.
|
||||
const toggleFolder = (name, collapsed = !currentFolds().has(name), after = "highlight") => {
|
||||
// subtree: the folder's own folders fold or open with it (Alt- or
|
||||
// Shift-click on its arrow). A null name means every folder (Fold all).
|
||||
const toggleFolder = (name, collapsed = !currentFolds().has(name), after = "highlight", { subtree = false } = {}) => {
|
||||
const folds = currentFolds();
|
||||
if (collapsed) folds.add(name);
|
||||
if (subtree || name == null) {
|
||||
const next = setFolderFolds(folds, folders.keys(), collapsed, name);
|
||||
folds.clear();
|
||||
for (const folder of next) folds.add(folder);
|
||||
} else if (collapsed) folds.add(name);
|
||||
else folds.delete(name);
|
||||
if (folds === collapsedFolders) saveCollapsedFolders(folds);
|
||||
if (folds === collapsedFolders && !startFolded) saveCollapsedFolders(folds);
|
||||
const scrollTop = list.scrollTop;
|
||||
highlight = -1;
|
||||
renderList();
|
||||
if (after === "highlight" && adding) {
|
||||
if (after === "highlight" && adding && name != null) {
|
||||
highlight = options.findIndex((entry) => entry.kind === "folder" && entry.name === name);
|
||||
list.querySelector(`[data-ausboss-flat="${highlight}"]`)?.classList.add("highlight");
|
||||
}
|
||||
@@ -1098,15 +1127,16 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
button.dataset.folder = name;
|
||||
button.innerHTML = chevronIconSvg(false);
|
||||
button.setAttribute("aria-expanded", String(expanded));
|
||||
button.title = `${expanded ? "Collapse" : "Expand"} ${name}`;
|
||||
button.setAttribute("aria-label", button.title);
|
||||
button.setAttribute("aria-label", `${expanded ? "Collapse" : "Expand"} ${name}`);
|
||||
button.title = `${button.getAttribute("aria-label")} (Alt-click: and every folder inside it)`;
|
||||
button.addEventListener("keydown", keepKeyInField);
|
||||
button.addEventListener("click", (event) => {
|
||||
// Only the folder name adds files; its arrow is browse-only.
|
||||
event.stopPropagation();
|
||||
// A click made with a key (detail 0) stays on the arrow. A mouse click
|
||||
// goes back to the search box, so typing keeps searching.
|
||||
toggleFolder(name, !currentFolds().has(name), event.detail === 0 ? "arrow" : "search");
|
||||
toggleFolder(name, !currentFolds().has(name), event.detail === 0 ? "arrow" : "search",
|
||||
{ subtree: event.altKey || event.shiftKey });
|
||||
});
|
||||
row.append(button);
|
||||
};
|
||||
@@ -1329,6 +1359,10 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
for (const entry of entries) if (entry.kind === "file") entry.inStack = have.has(pathKey(entry.name));
|
||||
}
|
||||
options = entries.filter((entry) => adding || entry.kind === "file");
|
||||
const open = anyFolderOpen(entries, currentFolds());
|
||||
foldAll.hidden = !entries.some((entry) => entry.kind === "folder");
|
||||
foldAll.textContent = open ? "Fold all" : "Open all";
|
||||
foldAll.title = open ? "Fold every folder in this list" : "Open every folder in this list";
|
||||
if (highlight >= 0) highlight = clampHighlight(highlight, options.length);
|
||||
list.textContent = "";
|
||||
hideHoverThumb();
|
||||
@@ -1356,6 +1390,9 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
place();
|
||||
};
|
||||
|
||||
foldAll.addEventListener("click", () => {
|
||||
toggleFolder(null, foldAll.textContent === "Fold all", "search");
|
||||
});
|
||||
search.addEventListener("input", () => { highlight = -1; searchCollapsed = new Set(); renderList(); });
|
||||
search.addEventListener("keydown", (event) => {
|
||||
keepKeyInField(event);
|
||||
@@ -1365,9 +1402,18 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
highlight = moveHighlight(highlight, event.key === "ArrowDown" ? 1 : -1, options.length);
|
||||
renderList();
|
||||
} else if ((event.key === "ArrowLeft" || event.key === "ArrowRight")
|
||||
&& options[highlight]?.kind === "folder") {
|
||||
&& options[highlight]?.kind === "folder"
|
||||
&& !(event.key === "ArrowLeft" && currentFolds().has(options[highlight].name)
|
||||
&& parentFolder(options[highlight].name) && !event.altKey && !event.shiftKey)) {
|
||||
event.preventDefault();
|
||||
toggleFolder(options[highlight].name, event.key === "ArrowLeft");
|
||||
toggleFolder(options[highlight].name, event.key === "ArrowLeft", "highlight",
|
||||
{ subtree: event.altKey || event.shiftKey });
|
||||
} else if (event.key === "ArrowLeft" && adding && highlight >= 0
|
||||
&& parentFolder(options[highlight]?.name)) {
|
||||
// On a file, or on a folder that is already folded, Left folds the
|
||||
// folder it sits in and moves up to it, as in a file tree.
|
||||
event.preventDefault();
|
||||
toggleFolder(parentFolder(options[highlight].name), true);
|
||||
} else if (event.key === "Home" || event.key === "End") {
|
||||
event.preventDefault();
|
||||
highlight = event.key === "Home" ? 0 : options.length - 1;
|
||||
@@ -1396,6 +1442,13 @@ function openPicker(state, index, anchor, { keyboard = false } = {}) {
|
||||
if (!pop.isConnected) return;
|
||||
names = fetched;
|
||||
folders = new Map(loraFolders(fetched).map(({ folder, names }) => [folder, names]));
|
||||
if (startFolded) {
|
||||
for (const folder of folders.keys()) collapsedFolders.add(folder);
|
||||
// A row's own picker opens the way to that row's file.
|
||||
for (let folder = parentFolder(state.rows[index]?.name); folder; folder = parentFolder(folder)) {
|
||||
collapsedFolders.delete(folder);
|
||||
}
|
||||
}
|
||||
state.available = fetched;
|
||||
state.nameStatus = new Map();
|
||||
widestPickerLabel = widestLabel(names.map((name) => displayName(state, name))) + (adding ? 110 : 30);
|
||||
@@ -3351,6 +3404,18 @@ function installLoraNode(node) {
|
||||
|
||||
app.registerExtension({
|
||||
name: "AusBoss.LoraLoader",
|
||||
settings: [
|
||||
{
|
||||
id: PICKER_FOLDERS_SETTING,
|
||||
name: "+ LoRA list folders",
|
||||
type: "combo",
|
||||
options: [START_FOLDED, REMEMBER_FOLDS],
|
||||
defaultValue: START_FOLDED,
|
||||
category: ["🆎 AusBoss", "LoRA Loader", "Picker folders"],
|
||||
tooltip: "Start folded opens the + LoRA list with every folder folded. "
|
||||
+ "Remember my folds opens it the way you left it in this browser.",
|
||||
},
|
||||
],
|
||||
setup() {
|
||||
watchEnteredBoxes();
|
||||
ensureRedrawHook();
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ import { app } from "../../../scripts/app.js";
|
||||
// Must match `version` in pyproject.toml — scripts/release_preflight.py
|
||||
// enforces it. The backend serves its copy at /ausboss/pack_version; a
|
||||
// mismatch means the browser cached JavaScript from an older install.
|
||||
export const AUSBOSS_JS_VERSION = "2.26.4";
|
||||
export const AUSBOSS_JS_VERSION = "2.26.6";
|
||||
|
||||
export const BRAND = "#00b4aa"; // AusBoss teal — keep node accents consistent.
|
||||
export const BRAND_DARK = "#007f78";
|
||||
|
||||
@@ -599,6 +599,35 @@ export function loraPickerEntries(names, query = "", collapsedFolders = new Set(
|
||||
return visit(tree);
|
||||
}
|
||||
|
||||
// Fold or open many folders at once: every folder in `folders`, or with
|
||||
// `root` that folder and every folder inside it. Returns a new Set; folds
|
||||
// of folders not named in `folders` are kept as they were.
|
||||
export function setFolderFolds(collapsedFolders, folders, fold, root = null) {
|
||||
const next = new Set([...collapsedFolders].map(loraPath));
|
||||
const base = root == null ? null : loraPath(root);
|
||||
for (const name of folders) {
|
||||
const folder = loraPath(name);
|
||||
if (base != null && folder !== base && !folder.startsWith(`${base}/`)) continue;
|
||||
if (fold) next.add(folder);
|
||||
else next.delete(folder);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
|
||||
// The folder a file or folder sits in, or null at the top of the list. The
|
||||
// picker's Left key folds it and moves up to it.
|
||||
export function parentFolder(name) {
|
||||
const parts = loraPath(String(name ?? "")).split("/");
|
||||
return parts.length > 1 ? parts.slice(0, -1).join("/") : null;
|
||||
}
|
||||
|
||||
// The picker's fold-all control offers "Fold all" while any folder in view
|
||||
// is open, and "Open all" once every folder in view is folded.
|
||||
export function anyFolderOpen(entries, collapsedFolders) {
|
||||
const collapsed = new Set([...collapsedFolders].map(loraPath));
|
||||
return entries.some((entry) => entry.kind === "folder" && !collapsed.has(entry.name));
|
||||
}
|
||||
|
||||
// Append the folder in one step, preserving duplicates, disabled rows and
|
||||
// empty slots already in the stack. Deduplicate new files by full path.
|
||||
export function appendFolderRows(rows, names, defaultStrength = 1) {
|
||||
|
||||
@@ -50,6 +50,7 @@ export function isBlendIn(values) {
|
||||
// Hover hints on the rows blend in does not read.
|
||||
export const SEAM_MUTE_TITLES = {
|
||||
fix_edge_halo: "Blend in doesn't use Fix edge halo. Switch Seam back to classic in the gear menu to use it.",
|
||||
follow_changes: "Blend in doesn't use Follow changes. Switch Seam back to classic in the gear menu to use it.",
|
||||
};
|
||||
|
||||
// Room the corner tools take from every row's control, so the controls keep
|
||||
|
||||
@@ -125,6 +125,15 @@ const CARDS = {
|
||||
{ widget: "interpolation", label: "Filter", kind: "select" },
|
||||
],
|
||||
},
|
||||
// One node, many small jobs: a new job is a new choice in the list, and
|
||||
// its own rows show only while it is picked.
|
||||
AUSBOSS_NODES_ImageToolbox: {
|
||||
minWidth: 280,
|
||||
rows: [
|
||||
{ widget: "job", label: "Job", kind: "select" },
|
||||
{ widget: "pieces", label: "Pieces", when: isMode("job", "split sheet at gaps") },
|
||||
],
|
||||
},
|
||||
AUSBOSS_NODES_EditLock: {
|
||||
minWidth: 300,
|
||||
rows: [
|
||||
@@ -169,7 +178,7 @@ const CARDS = {
|
||||
// A workflow saved before Seam existed holds the card's own empty value
|
||||
// in the slot Seam now takes; it loads as classic. One saved with Seam
|
||||
// holds it in Paste onto's slot, and loads as crop.
|
||||
resetUnknown: { seam: "classic", paste_onto: "crop" },
|
||||
resetUnknown: { seam: "classic", paste_onto: "crop", follow_changes: false },
|
||||
// Seam and Paste onto have no row and no socket: the gear menu sets them.
|
||||
hide: ["seam", "paste_onto"],
|
||||
socketless: ["seam", "paste_onto"],
|
||||
@@ -177,6 +186,7 @@ const CARDS = {
|
||||
rows: [
|
||||
{ widget: "color_match", label: "Tone match" },
|
||||
{ widget: "fix_edge_halo", label: "Fix edge halo", mute: isBlendIn, muteTitle: SEAM_MUTE_TITLES.fix_edge_halo },
|
||||
{ widget: "follow_changes", label: "Follow changes", mute: isBlendIn, muteTitle: SEAM_MUTE_TITLES.follow_changes },
|
||||
],
|
||||
},
|
||||
AUSBOSS_NODES_CropForInpaint: {
|
||||
|
||||
@@ -518,6 +518,26 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"AUSBOSS_NODES_ImageToolbox": {
|
||||
"display_name": "图像工具箱 🆎",
|
||||
"description": "把几个小的图像任务放在一个节点里:从列表里选任务。split sheet at gaps 会把一排并列的图(比如角色设定图的四个视角)切成单独的图。每一刀都切在两张图之间的空隙,而不是按宽度平均切,所以不会有哪一张带上邻图的一部分。切好的图作为一个批次输出,尺寸相同,用设定图的背景色补齐。",
|
||||
"inputs": {
|
||||
"image": {
|
||||
"name": "图像"
|
||||
},
|
||||
"job": {
|
||||
"name": "任务"
|
||||
},
|
||||
"pieces": {
|
||||
"name": "份数"
|
||||
}
|
||||
},
|
||||
"outputs": {
|
||||
"0": {
|
||||
"name": "图像"
|
||||
}
|
||||
}
|
||||
},
|
||||
"AUSBOSS_NODES_Integer": {
|
||||
"display_name": "整数 🆎",
|
||||
"description": "一个独立的 INT 值。在一个地方设置步数、尺寸或数量,送给所有需要同一个数字的节点。",
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
"""Stitch Inpaint's Follow changes: paste what the model changed, not only the box.
|
||||
|
||||
A model that redraws the whole crop it is given (MiniMax H3 Image, and any
|
||||
edit model run at full denoise) does not keep to the box: a new person's
|
||||
boots, a plate's rim or a coat's collar reach past it, and a paste of the
|
||||
box alone cuts them off at its edge. The model can also draw the crop a
|
||||
touch zoomed or shifted, so the redrawn background no longer lines up with
|
||||
the picture around it.
|
||||
|
||||
Follow changes does two things before the usual classic paste:
|
||||
|
||||
1. It lines the model's crop up with the picture's own crop (the zoom and
|
||||
shift that Realign to Source measures). When the measurement does not
|
||||
hold up, the crop is used as it came back.
|
||||
2. It grows the paste from the box to every change that touches it: pixels
|
||||
where the lined-up crop differs from the picture, joined to the box. The
|
||||
grown edge fades out before the crop window's border, so nothing ends in
|
||||
a hard line. When the change covers most of the window outside the box,
|
||||
the model redrew everything, and the paste stays the box.
|
||||
|
||||
The work runs at most ``WORK_SIDE`` pixels on the long side, on the CPU,
|
||||
and the grown mask is scaled back to the window. Distances below are in
|
||||
pixels of the crop window at full size and scale with it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
from ._realign_helpers import crop_if_shift, measure, warp_to_source
|
||||
|
||||
WORK_SIDE = 768
|
||||
# A change this large (0..1, mean over RGB, after a light blur) counts.
|
||||
CHANGE_LEVEL = 0.10
|
||||
CHANGE_BLUR = 4.0
|
||||
# How close a change has to come to the box to join it, how far the joined
|
||||
# shape is closed and widened, and how soft its edge is.
|
||||
TOUCH = 8.0
|
||||
CLOSE = 6.0
|
||||
WIDEN = 10.0
|
||||
SOFT = 10.0
|
||||
# The paste fades to nothing over this many pixels before a window border
|
||||
# that lies inside the picture.
|
||||
BORDER_FADE = 24.0
|
||||
# When the change outside the box covers more than this share of the window
|
||||
# outside the box, the model redrew everything: keep the box.
|
||||
REDREW_ALL = 0.5
|
||||
MAX_ZOOM = 0.2
|
||||
|
||||
|
||||
def _blur(image: torch.Tensor, sigma: float) -> torch.Tensor:
|
||||
"""Gaussian blur of an HW map, edges extended."""
|
||||
if sigma <= 0.3:
|
||||
return image
|
||||
radius = max(1, int(round(sigma * 3)))
|
||||
x = torch.arange(-radius, radius + 1, dtype=torch.float32)
|
||||
kernel = torch.exp(-(x * x) / (2 * sigma * sigma))
|
||||
kernel = kernel / kernel.sum()
|
||||
out = image[None, None]
|
||||
out = F.conv2d(F.pad(out, (radius, radius, 0, 0), mode="replicate"), kernel.view(1, 1, 1, -1))
|
||||
out = F.conv2d(F.pad(out, (0, 0, radius, radius), mode="replicate"), kernel.view(1, 1, -1, 1))
|
||||
return out[0, 0]
|
||||
|
||||
|
||||
def _dilate(mask: torch.Tensor, radius: int) -> torch.Tensor:
|
||||
if radius <= 0:
|
||||
return mask
|
||||
k = 2 * radius + 1
|
||||
return F.max_pool2d(mask[None, None].float(), k, stride=1, padding=radius)[0, 0] > 0.5
|
||||
|
||||
|
||||
def _erode(mask: torch.Tensor, radius: int) -> torch.Tensor:
|
||||
return ~_dilate(~mask, radius)
|
||||
|
||||
|
||||
def _reconstruct(seed: torch.Tensor, allowed: torch.Tensor) -> torch.Tensor:
|
||||
"""Every pixel of ``allowed`` connected to ``seed`` (8-neighbour fill)."""
|
||||
region = seed & allowed
|
||||
# Steps of 2 px: a gap of a pixel or two in the change still joins,
|
||||
# and the fill takes a quarter of the passes.
|
||||
for _ in range(sum(allowed.shape)):
|
||||
grown = _dilate(region, 2) & allowed
|
||||
if torch.equal(grown, region):
|
||||
break
|
||||
region = grown
|
||||
return region
|
||||
|
||||
|
||||
def _fill_holes(mask: torch.Tensor) -> torch.Tensor:
|
||||
border = torch.zeros_like(mask)
|
||||
border[0, :] = border[-1, :] = border[:, 0] = border[:, -1] = True
|
||||
outside = _reconstruct(border & ~mask, ~mask)
|
||||
return ~outside
|
||||
|
||||
|
||||
def _border_ramp(height: int, width: int, fade: float, open_sides: tuple[bool, bool, bool, bool]) -> torch.Tensor:
|
||||
"""1 inside, falling to 0 at each window border inside the picture.
|
||||
open_sides: (top, bottom, left, right) borders that are the picture's own
|
||||
edge, where nothing is cut and nothing fades."""
|
||||
top, bottom, left, right = open_sides
|
||||
ys = torch.arange(height, dtype=torch.float32)
|
||||
xs = torch.arange(width, dtype=torch.float32)
|
||||
big = float(height + width)
|
||||
dy = torch.minimum(ys if not top else torch.full_like(ys, big),
|
||||
(height - 1 - ys) if not bottom else torch.full_like(ys, big))
|
||||
dx = torch.minimum(xs if not left else torch.full_like(xs, big),
|
||||
(width - 1 - xs) if not right else torch.full_like(xs, big))
|
||||
return (torch.minimum(dy[:, None], dx[None, :]) / max(fade, 1.0)).clamp(0.0, 1.0)
|
||||
|
||||
|
||||
def _resize_hw(mask: torch.Tensor, height: int, width: int) -> torch.Tensor:
|
||||
return F.interpolate(mask[None, None].float(), size=(height, width), mode="bilinear", align_corners=False)[0, 0]
|
||||
|
||||
|
||||
def realign_crop(source: torch.Tensor, patch: torch.Tensor) -> tuple[torch.Tensor, bool]:
|
||||
"""The patch (HWC, window size) lined up with the source crop (HWC).
|
||||
Returns (patch, moved); an unreliable measurement leaves it as it is."""
|
||||
height, width = int(source.shape[0]), int(source.shape[1])
|
||||
result = measure(source, patch, "zoom + shift", MAX_ZOOM)
|
||||
if not result.reliable:
|
||||
return patch, False
|
||||
out = crop_if_shift(patch, result.matrix, width, height)
|
||||
if out is None:
|
||||
out, _ = warp_to_source(patch, result.matrix, width, height, "source", source)
|
||||
return out, True
|
||||
|
||||
|
||||
def follow_mask(source: torch.Tensor, patch: torch.Tensor, box: torch.Tensor,
|
||||
open_sides: tuple[bool, bool, bool, bool]) -> tuple[torch.Tensor, dict]:
|
||||
"""The grown paste mask (HW, 0..1) for one frame, in window pixels.
|
||||
|
||||
source, patch: HWC at window size, patch already lined up. box: HW blend
|
||||
mask in the window. Returns (mask, info) where info says what was done."""
|
||||
height, width = int(box.shape[0]), int(box.shape[1])
|
||||
scale = min(1.0, WORK_SIDE / max(height, width))
|
||||
wh, ww = max(8, int(round(height * scale))), max(8, int(round(width * scale)))
|
||||
|
||||
def px(value: float) -> float:
|
||||
return value * scale
|
||||
|
||||
small = lambda img: F.interpolate(img.permute(2, 0, 1)[None, :3].float(), size=(wh, ww),
|
||||
mode="area")[0]
|
||||
diff = (small(patch) - small(source)).abs().mean(0)
|
||||
diff = _blur(diff, px(CHANGE_BLUR))
|
||||
core = _resize_hw(box, wh, ww) >= 0.5
|
||||
if not bool(core.any()):
|
||||
return box.clone(), {"grew": False, "why": "no box"}
|
||||
changed = diff > CHANGE_LEVEL
|
||||
joined = _reconstruct(_dilate(core, max(1, round(px(TOUCH)))) & changed, changed) | core
|
||||
outside = ~core
|
||||
added = (joined & outside).sum().item()
|
||||
room = max(1, outside.sum().item())
|
||||
if added / room > REDREW_ALL:
|
||||
return box.clone(), {"grew": False, "why": "the model redrew most of the window"}
|
||||
close = max(1, round(px(CLOSE)))
|
||||
joined = _erode(_dilate(joined, close), close) | core
|
||||
joined = _fill_holes(joined)
|
||||
joined = _dilate(joined, max(1, round(px(WIDEN))))
|
||||
soft = _blur(joined.float(), px(SOFT))
|
||||
soft = _resize_hw(soft, height, width).clamp(0.0, 1.0)
|
||||
ramp = _border_ramp(height, width, BORDER_FADE, open_sides)
|
||||
grown = torch.maximum(soft * ramp, box.float() * ramp)
|
||||
# The box itself always pastes as it did, ramp or not.
|
||||
grown = torch.maximum(grown, box.float() * (box >= 0.999).float())
|
||||
share = float((grown > 0.5).sum()) / max(1.0, float((box > 0.5).sum()))
|
||||
return grown, {"grew": True, "share": share}
|
||||
|
||||
|
||||
def follow_changes(stitcher: dict, patch: torch.Tensor, resize) -> tuple[torch.Tensor, dict, list[str]]:
|
||||
"""Line the patch up and grow the paste. Returns (patch at window size,
|
||||
a stitcher copy whose blend is the grown mask, one line per frame).
|
||||
|
||||
``resize(patch, width, height, algorithm)`` brings the patch to the
|
||||
window size the way the classic stitch does."""
|
||||
canvas = stitcher["canvas"]
|
||||
blend = stitcher["blend"]
|
||||
cx, cy, cw, ch = stitcher["crop_to_canvas"]
|
||||
if (patch.shape[1], patch.shape[2]) != (ch, cw):
|
||||
patch = resize(patch, cw, ch, stitcher.get("algorithm", "bilinear"))
|
||||
full_h, full_w = int(canvas.shape[1]), int(canvas.shape[2])
|
||||
open_sides = (cy <= 0, cy + ch >= full_h, cx <= 0, cx + cw >= full_w)
|
||||
frames = int(patch.shape[0])
|
||||
patches, blends, lines = [], [], []
|
||||
for index in range(frames):
|
||||
src = canvas[min(index, canvas.shape[0] - 1), cy:cy + ch, cx:cx + cw, :3].detach().float().cpu()
|
||||
edit = patch[index, ..., :3].detach().float().cpu()
|
||||
box = blend[min(index, blend.shape[0] - 1), cy:cy + ch, cx:cx + cw].detach().float().cpu()
|
||||
lined, moved = realign_crop(src, edit)
|
||||
grown, info = follow_mask(src, lined, box, open_sides)
|
||||
if patch.shape[-1] > 3:
|
||||
lined = torch.cat([lined, patch[index, ..., 3:].detach().float().cpu()], dim=-1)
|
||||
patches.append(lined)
|
||||
whole = blend[min(index, blend.shape[0] - 1)].detach().float().cpu().clone()
|
||||
whole[cy:cy + ch, cx:cx + cw] = grown
|
||||
blends.append(whole)
|
||||
what = "lined up" if moved else "not moved"
|
||||
if info["grew"]:
|
||||
lines.append(f"Follow changes: {what}; paste grown to {info['share']:.2f}x the box.")
|
||||
else:
|
||||
lines.append(f"Follow changes: {what}; paste kept to the box ({info['why']}).")
|
||||
out_patch = torch.stack(patches).to(device=patch.device, dtype=patch.dtype)
|
||||
new = dict(stitcher)
|
||||
new["blend"] = torch.stack(blends).to(device=blend.device, dtype=blend.dtype)
|
||||
return out_patch, new, lines
|
||||
@@ -966,15 +966,12 @@ def inner_tone_offset(
|
||||
diff = new - old
|
||||
frames = diff.shape[0]
|
||||
whole = (blend > 0.999).to(diff.dtype)
|
||||
size = 2 * INNER_RIM_PX + 1
|
||||
# A pixel is deeper than the rim when nothing within INNER_RIM_PX of it
|
||||
# is outside the whole paste. The crop's own border does not count as
|
||||
# outside: the painted area simply runs off the crop there.
|
||||
# One pass along each axis: the same square reach at a fraction of the cost.
|
||||
outside = (1.0 - whole).unsqueeze(1)
|
||||
outside = functional.max_pool2d(outside, (1, size), stride=1, padding=(0, INNER_RIM_PX))
|
||||
outside = functional.max_pool2d(outside, (size, 1), stride=1, padding=(INNER_RIM_PX, 0))
|
||||
deep = 1.0 - outside.squeeze(1)
|
||||
outside = grow_shrink_mask(1.0 - whole, INNER_RIM_PX)
|
||||
deep = 1.0 - outside
|
||||
rim = (whole > 0) & (deep < 0.5)
|
||||
rim = torch.where(rim.flatten(1).any(dim=1).view(-1, 1, 1), rim, whole > 0)
|
||||
pasted = whole > 0
|
||||
|
||||
+73
-11
@@ -63,6 +63,41 @@ def _as_bhw(mask: torch.Tensor) -> torch.Tensor:
|
||||
MASK_CHUNK = 8
|
||||
|
||||
|
||||
def _within_support(mask: torch.Tensor, reach: int, run) -> torch.Tensor:
|
||||
"""Run a neighbourhood filter only where it can change anything.
|
||||
|
||||
``run`` is a grow, shrink or blur whose output pixel reads the input no
|
||||
further than ``reach`` pixels away, and gives exactly 0 where all it
|
||||
reads is 0. Outside the nonzero pixels grown by ``reach`` the result is
|
||||
therefore 0, so the filter runs on a window around them, grown by twice
|
||||
the reach: every pixel kept from it reads only what it would read on the
|
||||
whole frame, and at the frame's own edge the window ends there too, so
|
||||
edge padding behaves the same. A box drawn on a big photo then costs the
|
||||
box, not the photo; an empty mask costs one scan.
|
||||
"""
|
||||
if mask.ndim != 3 or mask.numel() == 0:
|
||||
return run(mask)
|
||||
height, width = int(mask.shape[1]), int(mask.shape[2])
|
||||
nonzero = (mask != 0).any(dim=0)
|
||||
rows = torch.nonzero(nonzero.any(dim=1)).flatten()
|
||||
if rows.numel() == 0:
|
||||
return torch.zeros_like(mask)
|
||||
cols = torch.nonzero(nonzero.any(dim=0)).flatten()
|
||||
top, bottom = int(rows[0]), int(rows[-1]) + 1
|
||||
left, right = int(cols[0]), int(cols[-1]) + 1
|
||||
wy0, wy1 = max(0, top - 2 * reach), min(height, bottom + 2 * reach)
|
||||
wx0, wx1 = max(0, left - 2 * reach), min(width, right + 2 * reach)
|
||||
# Most of the frame anyway: the copies would cost more than they save.
|
||||
if (wy1 - wy0) * (wx1 - wx0) * 2 > height * width:
|
||||
return run(mask)
|
||||
window = run(mask[:, wy0:wy1, wx0:wx1].contiguous())
|
||||
oy0, oy1 = max(0, top - reach), min(height, bottom + reach)
|
||||
ox0, ox1 = max(0, left - reach), min(width, right + reach)
|
||||
result = torch.zeros_like(mask)
|
||||
result[:, oy0:oy1, ox0:ox1] = window[:, oy0 - wy0 : oy1 - wy0, ox0 - wx0 : ox1 - wx0]
|
||||
return result
|
||||
|
||||
|
||||
def grow_shrink_mask(mask: torch.Tensor, pixels: int) -> torch.Tensor:
|
||||
"""Dilate (positive) or erode (negative) by whole pixels; soft values survive.
|
||||
|
||||
@@ -77,17 +112,40 @@ def grow_shrink_mask(mask: torch.Tensor, pixels: int) -> torch.Tensor:
|
||||
steps = abs(int(pixels))
|
||||
if steps == 0:
|
||||
return mask
|
||||
return _within_support(mask, steps, lambda part: _grow_shrink_full(part, pixels, steps))
|
||||
|
||||
|
||||
def _grow_shrink_full(mask: torch.Tensor, pixels: int, steps: int) -> torch.Tensor:
|
||||
if mask.shape[0] > MASK_CHUNK:
|
||||
return torch.cat([grow_shrink_mask(part, pixels) for part in mask.split(MASK_CHUNK)])
|
||||
size = 2 * steps + 1
|
||||
grown = mask.unsqueeze(1)
|
||||
return torch.cat([_grow_shrink_full(part, pixels, steps) for part in mask.split(MASK_CHUNK)])
|
||||
if pixels > 0:
|
||||
grown = functional.max_pool2d(grown, kernel_size=(1, size), stride=1, padding=(0, steps))
|
||||
grown = functional.max_pool2d(grown, kernel_size=(size, 1), stride=1, padding=(steps, 0))
|
||||
else:
|
||||
grown = -functional.max_pool2d(-grown, kernel_size=(1, size), stride=1, padding=(0, steps))
|
||||
grown = -functional.max_pool2d(-grown, kernel_size=(size, 1), stride=1, padding=(steps, 0))
|
||||
return grown.squeeze(1)
|
||||
return _running_max(_running_max(mask, steps, 2), steps, 1)
|
||||
return -_running_max(_running_max(-mask, steps, 2), steps, 1)
|
||||
|
||||
|
||||
def _running_max(values: torch.Tensor, steps: int, dim: int) -> torch.Tensor:
|
||||
"""Max over the ``2 * steps + 1`` pixels centred on each pixel along ``dim``.
|
||||
|
||||
The same numbers as a max pool with that kernel and ``steps`` of -inf
|
||||
padding, but by doubling: after k passes each pixel holds the max of the
|
||||
2**k pixels from it on, and two such overlapping runs cover the whole
|
||||
window. Max is exact in any order, so this matches the pool to the bit,
|
||||
in about log2 of the window passes instead of one read per window pixel.
|
||||
"""
|
||||
size = 2 * steps + 1
|
||||
length = values.shape[dim]
|
||||
pad_shape = list(values.shape)
|
||||
pad_shape[dim] = steps
|
||||
edge = values.new_full(pad_shape, float("-inf"))
|
||||
run = torch.cat((edge, values, edge), dim=dim)
|
||||
width = 1
|
||||
while width * 2 <= size:
|
||||
count = run.shape[dim] - width
|
||||
run = torch.maximum(run.narrow(dim, 0, count), run.narrow(dim, width, count))
|
||||
width *= 2
|
||||
if width == size:
|
||||
return run.narrow(dim, 0, length).contiguous()
|
||||
return torch.maximum(run.narrow(dim, 0, length), run.narrow(dim, size - width, length))
|
||||
|
||||
|
||||
def _torch_fill_holes(solid: torch.Tensor) -> torch.Tensor:
|
||||
@@ -194,9 +252,13 @@ def fill_mask_holes(mask: torch.Tensor, max_hole_size: float = 0.0) -> torch.Ten
|
||||
def blur_mask(mask: torch.Tensor, sigma: float) -> torch.Tensor:
|
||||
if sigma <= 0.0:
|
||||
return mask
|
||||
if mask.shape[0] > MASK_CHUNK:
|
||||
return torch.cat([blur_mask(part, sigma) for part in mask.split(MASK_CHUNK)])
|
||||
radius = max(1, int(math.ceil(float(sigma) * 3.0)))
|
||||
return _within_support(mask, radius, lambda part: _blur_full(part, sigma, radius))
|
||||
|
||||
|
||||
def _blur_full(mask: torch.Tensor, sigma: float, radius: int) -> torch.Tensor:
|
||||
if mask.shape[0] > MASK_CHUNK:
|
||||
return torch.cat([_blur_full(part, sigma, radius) for part in mask.split(MASK_CHUNK)])
|
||||
coords = torch.arange(-radius, radius + 1, dtype=torch.float32, device=mask.device)
|
||||
kernel = torch.exp(-(coords**2) / (2.0 * float(sigma) ** 2))
|
||||
kernel = kernel / kernel.sum()
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
"""Split a sheet of side-by-side pictures at the gaps between them.
|
||||
|
||||
A generated sheet (a character turnaround, a row of close-ups) rarely puts
|
||||
each picture exactly on its share of the width. Cutting into equal parts then
|
||||
lands a neighbour's sleeve in one piece and cuts another's off. Here each cut
|
||||
moves to the cleanest column near its equal-share line: the column where the
|
||||
fewest pixels differ from the sheet's backdrop.
|
||||
|
||||
Every piece is then placed on a backdrop-coloured canvas as wide as the widest
|
||||
piece, so the pieces form one batch. The outer pieces keep the sheet's own
|
||||
left and right edges at the canvas edge; the inner ones are centred.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import torch
|
||||
|
||||
# How far a cut may move from its equal-share line, as a part of one share.
|
||||
SEARCH = 0.4
|
||||
# A pixel this far from the backdrop colour (0-1, any channel) counts as content.
|
||||
CONTENT_STEP = 0.1
|
||||
# Border strip, in pixels, that the backdrop colour is read from.
|
||||
BORDER = 8
|
||||
|
||||
|
||||
def backdrop_color(image: torch.Tensor) -> torch.Tensor:
|
||||
"""The median colour of the picture's border: the sheet's backdrop."""
|
||||
height, width, channels = image.shape
|
||||
strip = max(1, min(BORDER, height // 4, width // 4))
|
||||
border = torch.cat([
|
||||
image[:strip].reshape(-1, channels),
|
||||
image[-strip:].reshape(-1, channels),
|
||||
image[:, :strip].reshape(-1, channels),
|
||||
image[:, -strip:].reshape(-1, channels),
|
||||
])
|
||||
return border.median(dim=0).values
|
||||
|
||||
|
||||
def column_content(image: torch.Tensor, backdrop: torch.Tensor) -> torch.Tensor:
|
||||
"""For each column, how many pixels are not backdrop."""
|
||||
return ((image - backdrop).abs().amax(dim=-1) > CONTENT_STEP).sum(dim=0)
|
||||
|
||||
|
||||
def cut_columns(image: torch.Tensor, pieces: int) -> list[int]:
|
||||
"""Cut positions for one HWC picture: 0, the inner cuts, then the width."""
|
||||
width = int(image.shape[1])
|
||||
pieces = max(1, min(int(pieces), width))
|
||||
if pieces == 1:
|
||||
return [0, width]
|
||||
content = column_content(image, backdrop_color(image))
|
||||
share = width / pieces
|
||||
reach = int(share * SEARCH)
|
||||
cuts = [0]
|
||||
for index in range(1, pieces):
|
||||
centre = round(index * share)
|
||||
low = max(cuts[-1] + 1, centre - reach)
|
||||
high = min(width - (pieces - index), centre + reach + 1)
|
||||
if high <= low:
|
||||
cuts.append(min(max(centre, cuts[-1] + 1), width - (pieces - index)))
|
||||
continue
|
||||
window = content[low:high]
|
||||
cleanest = torch.nonzero(window == window.min()).flatten()
|
||||
# The middle of the longest run of cleanest columns; on a tie the run
|
||||
# nearest the equal-share line.
|
||||
breaks = torch.nonzero(cleanest[1:] - cleanest[:-1] > 1).flatten() + 1
|
||||
runs = torch.tensor_split(cleanest, breaks.tolist())
|
||||
best = max(runs, key=lambda run: (len(run), -abs(int(run.float().mean()) + low - centre)))
|
||||
cuts.append(low + int(round(float(best.float().mean()))))
|
||||
cuts.append(width)
|
||||
return cuts
|
||||
|
||||
|
||||
def split_sheet(images: torch.Tensor, pieces: int) -> torch.Tensor:
|
||||
"""Split every picture of a BHWC batch into ``pieces`` side by side.
|
||||
|
||||
Returns one batch: the first picture's pieces from left to right, then the
|
||||
next picture's. All pieces share the widest piece's width.
|
||||
"""
|
||||
if not isinstance(images, torch.Tensor) or images.ndim != 4:
|
||||
raise ValueError("Image Toolbox expected a BHWC IMAGE batch.")
|
||||
pieces = int(pieces)
|
||||
if pieces < 1:
|
||||
raise ValueError("Pieces must be 1 or more.")
|
||||
if pieces == 1:
|
||||
return images
|
||||
cut_sets = [cut_columns(image, pieces) for image in images]
|
||||
backdrops = [backdrop_color(image) for image in images]
|
||||
widest = max(b - a for cuts in cut_sets for a, b in zip(cuts, cuts[1:]))
|
||||
out = []
|
||||
for image, cuts, backdrop in zip(images, cut_sets, backdrops):
|
||||
height = int(image.shape[0])
|
||||
spans = list(zip(cuts, cuts[1:]))
|
||||
for index, (start, end) in enumerate(spans):
|
||||
span = end - start
|
||||
canvas = backdrop.to(image.dtype).expand(height, widest, image.shape[-1]).clone()
|
||||
if index == 0:
|
||||
offset = 0
|
||||
elif index == len(spans) - 1:
|
||||
offset = widest - span
|
||||
else:
|
||||
offset = (widest - span) // 2
|
||||
canvas[:, offset:offset + span] = image[:, start:end]
|
||||
out.append(canvas)
|
||||
return torch.stack(out)
|
||||
@@ -393,8 +393,9 @@ def transform_pil_batch(
|
||||
)
|
||||
image_array = np.asarray(output, dtype=np.float32) / 255.0
|
||||
mask_array = np.asarray(mask, dtype=np.float32) / 255.0
|
||||
frames.append(torch.from_numpy(image_array.copy()))
|
||||
masks.append(torch.from_numpy(mask_array.copy()))
|
||||
# The division already made fresh arrays, so no copy is needed.
|
||||
frames.append(torch.from_numpy(image_array))
|
||||
masks.append(torch.from_numpy(mask_array))
|
||||
views.append(prompt_view)
|
||||
|
||||
if not frames or first_geometry is None:
|
||||
@@ -575,6 +576,15 @@ def resize_then_pad(output, mask, geometry, fill_color, megapixels, method, step
|
||||
return place(output), resized, None if view is None else place(view)
|
||||
|
||||
|
||||
def has_see_through(images: Iterable[Image.Image]) -> bool:
|
||||
"""True when any frame has see-through parts (:func:`see_through_kept`),
|
||||
so :func:`original_image_batch` would differ with ``keep_see_through``."""
|
||||
return any(
|
||||
see_through_kept(image if image.mode == "RGBA" else image.convert("RGBA")) is not None
|
||||
for image in images
|
||||
)
|
||||
|
||||
|
||||
def original_image_batch(images: Iterable[Image.Image], keep_see_through: bool = False) -> torch.Tensor:
|
||||
"""Untransformed, EXIF-oriented RGB source frames for reference outputs.
|
||||
|
||||
@@ -586,7 +596,7 @@ def original_image_batch(images: Iterable[Image.Image], keep_see_through: bool =
|
||||
"""
|
||||
frames = []
|
||||
for image in images:
|
||||
array = np.asarray(image.convert("RGB"), dtype=np.float32).copy()
|
||||
array = np.array(image.convert("RGB"), dtype=np.float32)
|
||||
kept = None if keep_see_through else see_through_kept(image if image.mode == "RGBA" else image.convert("RGBA"))
|
||||
if kept is not None:
|
||||
array[~kept] = SEE_THROUGH_BACKDROP
|
||||
|
||||
@@ -6,6 +6,7 @@ from ._execution_helpers import ignore_extra_inputs
|
||||
from ._media_helpers import list_input_images, load_image_frames, resolve_input_path
|
||||
from ._inpaint_crop_helpers import build_transform_stitcher, remember_original
|
||||
from ._transform_engine import (
|
||||
has_see_through,
|
||||
original_image_batch,
|
||||
resize_then_pad,
|
||||
stable_file_fingerprint,
|
||||
@@ -138,13 +139,20 @@ class AusBossImageCropRotatePad:
|
||||
source="Image Crop + Rotate + Pad",
|
||||
)
|
||||
# The picture as stored: a MaskEditor stroke keeps what is under it.
|
||||
remember_original(stitcher, original_image_batch(frames, True), geometry, spec.normalized().rotation_degrees)
|
||||
stored = original_image_batch(frames, True)
|
||||
remember_original(stitcher, stored, geometry, spec.normalized().rotation_degrees)
|
||||
# With nothing see-through both copies hold the same pixels: copy
|
||||
# the one already made instead of converting the picture again.
|
||||
if keep_picture or not has_see_through(frames):
|
||||
original = stored.clone()
|
||||
else:
|
||||
original = original_image_batch(frames, False)
|
||||
# Nothing see-through: the prompt view is the image itself, as a copy
|
||||
# so no consumer can change one through the other.
|
||||
if prompt_image is None:
|
||||
prompt_image = output.clone()
|
||||
return (
|
||||
output, mask, stitcher, original_image_batch(frames, keep_picture),
|
||||
output, mask, stitcher, original,
|
||||
int(output.shape[2]), int(output.shape[1]), prompt_image,
|
||||
)
|
||||
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
"""Image Toolbox 🆎: small picture jobs behind one node.
|
||||
|
||||
Each job is a choice in the ``job`` list, so a new job is a new choice, not a
|
||||
new node. The first job splits a sheet of side-by-side pictures at the gaps
|
||||
between them (``_sheet_split_helpers``).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from ._sheet_split_helpers import split_sheet
|
||||
|
||||
SPLIT_SHEET = "split sheet at gaps"
|
||||
JOBS = [SPLIT_SHEET]
|
||||
|
||||
|
||||
class AusBossImageToolbox:
|
||||
CATEGORY = "🆎 AusBoss/Image"
|
||||
DESCRIPTION = (
|
||||
"Small picture jobs in one node: pick the job from the list. "
|
||||
"split sheet at gaps cuts a row of pictures, such as a character "
|
||||
"sheet's views, into separate pictures. Each cut goes to the gap "
|
||||
"between two pictures, not to an equal share of the width, so no "
|
||||
"piece gets part of its neighbour. The pieces come out as one batch, "
|
||||
"all the same size, padded with the sheet's backdrop colour."
|
||||
)
|
||||
SEARCH_ALIASES = [
|
||||
"toolbox",
|
||||
"split sheet",
|
||||
"character sheet",
|
||||
"turnaround",
|
||||
"split views",
|
||||
"cut into pieces",
|
||||
"slice image",
|
||||
"ausboss",
|
||||
]
|
||||
|
||||
@classmethod
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
"image": (
|
||||
"IMAGE",
|
||||
{"tooltip": "The picture to work on. A batch is worked on picture by picture."},
|
||||
),
|
||||
"job": (
|
||||
JOBS,
|
||||
{
|
||||
"default": SPLIT_SHEET,
|
||||
"tooltip": "What to do with the picture. split sheet at gaps: cut a row of pictures apart at the gaps between them.",
|
||||
},
|
||||
),
|
||||
"pieces": (
|
||||
"INT",
|
||||
{
|
||||
"default": 4,
|
||||
"min": 1,
|
||||
"max": 16,
|
||||
"step": 1,
|
||||
"tooltip": "How many pictures sit side by side on the sheet. 4 for a four-view character sheet.",
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
RETURN_NAMES = ("images",)
|
||||
OUTPUT_TOOLTIPS = (
|
||||
"The result. For split sheet at gaps: the pieces from left to right, one batch, all the same size.",
|
||||
)
|
||||
FUNCTION = "run"
|
||||
|
||||
def run(self, image, job, pieces):
|
||||
if job == SPLIT_SHEET:
|
||||
return (split_sheet(image, pieces),)
|
||||
raise ValueError(f"Image Toolbox has no job named {job!r}.")
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {"AUSBOSS_NODES_ImageToolbox": AusBossImageToolbox}
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {"AUSBOSS_NODES_ImageToolbox": "Image Toolbox 🆎"}
|
||||
|
||||
__all__ = ["NODE_CLASS_MAPPINGS", "NODE_DISPLAY_NAME_MAPPINGS"]
|
||||
@@ -10,11 +10,13 @@ from ._inpaint_crop_helpers import (
|
||||
RESIZE_ALGORITHMS,
|
||||
SEAM_CLASSIC,
|
||||
SEAM_MODES,
|
||||
_resize_image,
|
||||
apply_stitch,
|
||||
build_crop,
|
||||
paste_on_original,
|
||||
stitch_blend_mask,
|
||||
)
|
||||
from ._follow_changes_helpers import follow_changes as _follow_changes
|
||||
from ._unpainted_helpers import unpainted_notice, unpainted_share
|
||||
|
||||
# A workflow saved before Seam existed can hold the card's empty value in
|
||||
@@ -367,7 +369,11 @@ class AusBossStitchInpaint:
|
||||
"rim. The blend_mask output marks what the stitch changed, in the "
|
||||
"stitched image's own coordinates, ready for a downstream color match. "
|
||||
"After a hand crop in Image Crop + Rotate + Pad 🆎, set Paste onto "
|
||||
"to original to get your whole picture back with the edit in place."
|
||||
"to original to get your whole picture back with the edit in place. "
|
||||
"Turn on Follow changes when the model draws past the box (a boot or "
|
||||
"a plate rim cut off at its edge): the paste then grows to every "
|
||||
"change that touches the box, after lining the model's crop up with "
|
||||
"your picture."
|
||||
)
|
||||
SEARCH_ALIASES = [
|
||||
"stitch inpaint",
|
||||
@@ -455,6 +461,19 @@ class AusBossStitchInpaint:
|
||||
),
|
||||
},
|
||||
),
|
||||
"follow_changes": (
|
||||
"BOOLEAN",
|
||||
{
|
||||
"default": False,
|
||||
"tooltip": (
|
||||
"Paste what the model changed next to the box too, "
|
||||
"so feet, rims and collars that reach past the box "
|
||||
"are not cut off. It also undoes a small zoom or "
|
||||
"shift the model drew. Turn it on for edit models "
|
||||
"that redraw the whole crop."
|
||||
),
|
||||
},
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
@@ -474,12 +493,20 @@ class AusBossStitchInpaint:
|
||||
FUNCTION = "stitch"
|
||||
|
||||
def stitch(
|
||||
self, stitcher, inpainted, fix_edge_halo=False, color_match=0.0, seam=SEAM_CLASSIC, paste_onto=PASTE_ONTO_CROP
|
||||
self, stitcher, inpainted, fix_edge_halo=False, color_match=0.0, seam=SEAM_CLASSIC, paste_onto=PASTE_ONTO_CROP,
|
||||
follow_changes=False,
|
||||
):
|
||||
if seam in _UNSET_SEAM:
|
||||
seam = SEAM_CLASSIC
|
||||
if seam not in SEAM_MODES:
|
||||
raise ValueError(f"Stitch Inpaint: seam must be 'classic' or 'blend in', not {seam!r}.")
|
||||
if follow_changes is True and seam == SEAM_CLASSIC and isinstance(stitcher, dict) \
|
||||
and "canvas" in stitcher and stitcher.get("source_bbox") is None:
|
||||
# An inpaint crop only: an outpaint's new area has no picture
|
||||
# under it to compare against.
|
||||
inpainted, stitcher, lines = _follow_changes(stitcher, inpainted, _resize_image)
|
||||
for line in lines:
|
||||
print(f"[AusBoss] Stitch Inpaint: {line}")
|
||||
image = apply_stitch(stitcher, inpainted, bool(fix_edge_halo), float(color_match), seam)
|
||||
if paste_onto not in _UNSET_PASTE_ONTO and paste_onto not in PASTE_ONTO_MODES:
|
||||
raise ValueError(f"Stitch Inpaint: paste_onto must be 'crop' or 'original', not {paste_onto!r}.")
|
||||
|
||||
+3
-2
@@ -2,8 +2,8 @@
|
||||
name = "ausboss-nodes"
|
||||
# Manager/registry search matches against this text, so it names the actual
|
||||
# nodes instead of describing the collection abstractly.
|
||||
description = "ComfyUI-AusBoss (AusBoss nodes): image and video nodes with compact controls: Image and Video Crop + Rotate + Pad (frame or clip), Load Image, Load Image + Pad, Image Folder, Image Resize, Align Image, Image Size, Color Match, Image Compare A/B, Realign to Source (experimental), Save Image (PNG, WebP/JXL, captions), Load Video, Load Audio, Save Video, Select Frame, Frame Interpolate, Mask Refine, Mask by Name and Mask by Touch, LaMa Inpaint, Crop For Inpaint, Stitch Inpaint, Tiled Upscale and Tiled Upscale Stitch, FlashVSR Upscale, Edit Lock and Edit Lock Restore, LoRA Loader, Krea 2 Encode and Outpaint Model Patch, Latent Size, Layout Boxes, Seed, Select Every Nth, Split Batch, Merge Batches, Text, Text Lines, Prompt Variations, H3 Prompt Writer, Integer, Float, Math Expression, Show Text, Free Memory, Workflow Note, Workflow Note Tile, Callout, Callout Tile, Workflow Switches, Run Timer, and Step Preview. Example workflows for Qwen Image 2.1, Krea 2, Klein 9B and LTX 2.3."
|
||||
version = "2.26.4"
|
||||
description = "ComfyUI-AusBoss (AusBoss nodes): image and video nodes with compact controls: Image and Video Crop + Rotate + Pad (frame or clip), Load Image, Load Image + Pad, Image Folder, Image Resize, Align Image, Image Size, Color Match, Image Compare A/B, Image Toolbox, Realign to Source (experimental), Save Image (PNG, WebP/JXL, captions), Load Video, Load Audio, Save Video, Select Frame, Frame Interpolate, Mask Refine, Mask by Name and Mask by Touch, LaMa Inpaint, Crop For Inpaint, Stitch Inpaint, Tiled Upscale and Tiled Upscale Stitch, FlashVSR Upscale, Edit Lock and Edit Lock Restore, LoRA Loader, Krea 2 Encode and Outpaint Model Patch, Latent Size, Layout Boxes, Seed, Select Every Nth, Split Batch, Merge Batches, Text, Text Lines, Prompt Variations, H3 Prompt Writer, Integer, Float, Math Expression, Show Text, Free Memory, Workflow Note, Workflow Note Tile, Callout, Callout Tile, Workflow Switches, Run Timer, and Step Preview. Examples for Qwen Image 2.1, Krea 2, Klein 9B and LTX 2.3."
|
||||
version = "2.26.6"
|
||||
# comfy-cli serializes this to JSON verbatim, so `file` publishes the literal
|
||||
# string {"file": "LICENSE"} to the registry listing. `text` puts a readable
|
||||
# name there instead. Both forms are supported; the LICENSE file is unchanged.
|
||||
@@ -22,6 +22,7 @@ keywords = [
|
||||
"tiled upscale", "upscale", "tiles", "restore", "layout boxes", "bounding boxes", "moss image", "replace text", "rotate box",
|
||||
"step preview", "live preview", "stop run",
|
||||
"text lines", "prompt list", "prompt variations", "wildcards", "flashvsr", "video upscale", "edit lock", "load image",
|
||||
"image toolbox", "split sheet", "character sheet",
|
||||
]
|
||||
|
||||
# Read by comfy-cli into the registry's supported_os field. Nothing in the pack
|
||||
|
||||
@@ -67,6 +67,7 @@ PUBLIC_NODE_IDS = {
|
||||
"AUSBOSS_NODES_ImageFolder",
|
||||
"AUSBOSS_NODES_ImageResize",
|
||||
"AUSBOSS_NODES_ImageSize",
|
||||
"AUSBOSS_NODES_ImageToolbox",
|
||||
"AUSBOSS_NODES_Integer",
|
||||
"AUSBOSS_NODES_Krea2Encode",
|
||||
"AUSBOSS_NODES_Krea2OutpaintModelPatch",
|
||||
|
||||
Vendored
+16
-1
@@ -469,6 +469,20 @@
|
||||
]
|
||||
]
|
||||
},
|
||||
"AUSBOSS_NODES_ImageToolbox": {
|
||||
"required": [
|
||||
"image",
|
||||
"job",
|
||||
"pieces"
|
||||
],
|
||||
"optional": [],
|
||||
"outputs": [
|
||||
[
|
||||
"IMAGE",
|
||||
"images"
|
||||
]
|
||||
]
|
||||
},
|
||||
"AUSBOSS_NODES_Integer": {
|
||||
"required": [
|
||||
"value"
|
||||
@@ -1095,7 +1109,8 @@
|
||||
"fix_edge_halo",
|
||||
"color_match",
|
||||
"seam",
|
||||
"paste_onto"
|
||||
"paste_onto",
|
||||
"follow_changes"
|
||||
],
|
||||
"outputs": [
|
||||
[
|
||||
|
||||
@@ -27,6 +27,9 @@ import {
|
||||
loaderLoraEntries,
|
||||
loraFolders,
|
||||
loraPickerEntries,
|
||||
setFolderFolds,
|
||||
parentFolder,
|
||||
anyFolderOpen,
|
||||
loraStackKeyAction,
|
||||
mergeImportedRows,
|
||||
middleEllipsis,
|
||||
@@ -1177,3 +1180,48 @@ test("the master switch turns groups back on, and its memory brings them back of
|
||||
const third = cycleMasterToggle(second.rows, second.snapshot);
|
||||
assert.deepEqual(third.rows.map((row) => [row.enabled, Boolean(row.group_off)]), [[true, false], [true, true], [false, true]]);
|
||||
});
|
||||
|
||||
test("fold all folds every folder and open all opens them, keeping unrelated folds", () => {
|
||||
const names = ["styles/ink/a.safetensors", "styles/ink/deep/b.safetensors",
|
||||
"styles/ink-old/c.safetensors", "faces/d.safetensors", "root.safetensors"];
|
||||
const folders = loraFolders(names).map(({ folder }) => folder);
|
||||
const before = new Set(["gone/folder"]);
|
||||
const folded = setFolderFolds(before, folders, true);
|
||||
assert.deepEqual(loraPickerEntries(names, "", folded).map(({ name }) => name),
|
||||
["styles", "faces", "root.safetensors"], "only top folders and root files stay in view");
|
||||
assert.equal(anyFolderOpen(loraPickerEntries(names, "", folded), folded), false);
|
||||
assert.ok(folded.has("gone/folder"), "a remembered fold for a folder not listed now is kept");
|
||||
assert.deepEqual([...before], ["gone/folder"], "the caller's Set is not changed");
|
||||
const opened = setFolderFolds(folded, folders, false);
|
||||
assert.deepEqual([...opened], ["gone/folder"]);
|
||||
assert.equal(anyFolderOpen(loraPickerEntries(names, "", opened), opened), true);
|
||||
});
|
||||
|
||||
test("folding a folder with its subtree leaves similarly named siblings alone", () => {
|
||||
const names = ["styles/ink/a.safetensors", "styles/ink/deep/b.safetensors",
|
||||
"styles/ink-old/c.safetensors", "styles/paint/d.safetensors"];
|
||||
const folders = loraFolders(names).map(({ folder }) => folder);
|
||||
const folded = setFolderFolds(new Set(), folders, true, "styles/ink");
|
||||
assert.deepEqual([...folded].sort(), ["styles/ink", "styles/ink/deep"]);
|
||||
const reopened = setFolderFolds(new Set([...folded, "styles/paint"]), folders, false, "styles\\ink");
|
||||
assert.deepEqual([...reopened], ["styles/paint"], "Windows separators name the same folder");
|
||||
});
|
||||
|
||||
test("fold-all label follows the folders in view, so a search view decides for itself", () => {
|
||||
const names = ["styles/ink/hit.safetensors", "faces/other.safetensors"];
|
||||
const searched = loraPickerEntries(names, "hit");
|
||||
assert.equal(anyFolderOpen(searched, new Set()), true);
|
||||
const folds = new Set(["styles"]);
|
||||
assert.equal(anyFolderOpen(loraPickerEntries(names, "hit", folds), folds), false,
|
||||
"with the only top folder in view folded, the control offers Open all");
|
||||
assert.equal(anyFolderOpen(loraPickerEntries(["root.safetensors"]), new Set()), false);
|
||||
});
|
||||
|
||||
test("Left moves up to the folder a file or folder sits in", () => {
|
||||
assert.equal(parentFolder("Krea2/Body/curvy.safetensors"), "Krea2/Body");
|
||||
assert.equal(parentFolder("Krea2\\Body\\curvy.safetensors"), "Krea2/Body", "Windows paths name the same folder");
|
||||
assert.equal(parentFolder("Krea2/Body"), "Krea2");
|
||||
assert.equal(parentFolder("Krea2"), null);
|
||||
assert.equal(parentFolder("root.safetensors"), null);
|
||||
assert.equal(parentFolder(undefined), null);
|
||||
});
|
||||
|
||||
@@ -162,7 +162,7 @@ const APPENDED_SINCE = {
|
||||
AUSBOSS_NODES_Resolution: { workflow_sizes: "workflow-policy" },
|
||||
// Added in 2.4.0; 2.0.0 - 2.3.0 saves hold the card's value there.
|
||||
AUSBOSS_NODES_CropForInpaint: { keep_inside: "toggle" },
|
||||
AUSBOSS_NODES_StitchInpaint: { seam: "combo", paste_onto: "combo" },
|
||||
AUSBOSS_NODES_StitchInpaint: { seam: "combo", paste_onto: "combo", follow_changes: "toggle" },
|
||||
// Added in 2.0.0; 1.x saves hold the preview panel's value there (Select
|
||||
// Frame's from 1.2.0), or the LoRA panel's. Mask Refine's max_hole_size
|
||||
// came after 2.4.0; 2.x saves hold the card's value there.
|
||||
|
||||
@@ -64,8 +64,9 @@ test("blend in mutes the rows and widens the corner; classic does neither", () =
|
||||
}
|
||||
assert.equal(seamCornerReserve({ seam: "classic" }), 30);
|
||||
assert.equal(seamCornerReserve({ seam: "blend in" }), 84);
|
||||
// Tone match works in both seams; only the halo fix is classic's alone.
|
||||
assert.deepEqual(Object.keys(SEAM_MUTE_TITLES), ["fix_edge_halo"]);
|
||||
// Tone match works in both seams; the halo fix and Follow changes are
|
||||
// classic's alone.
|
||||
assert.deepEqual(Object.keys(SEAM_MUTE_TITLES), ["fix_edge_halo", "follow_changes"]);
|
||||
for (const title of Object.values(SEAM_MUTE_TITLES)) {
|
||||
assert.match(title, /^Blend in doesn't use/);
|
||||
assert.match(title, /gear menu/);
|
||||
|
||||
@@ -0,0 +1,304 @@
|
||||
"""The box-edit path costs the box, not the picture, and gives the same pixels.
|
||||
|
||||
Crop + Rotate + Pad, Crop For Inpaint and Stitch Inpaint used to grow and
|
||||
blur masks across the whole frame: a 17 MP photo with a small box drawn on it
|
||||
spent about 5 s on CPU before the sampler started. The filters now run on a
|
||||
window around the mask's nonzero pixels, and grows use an exact doubling
|
||||
running max instead of a wide max pool.
|
||||
|
||||
Two kinds of test:
|
||||
|
||||
- Pixel match. The old full-frame filters live on here as references and are
|
||||
patched back into the helpers. Grows and shrinks must match to the bit.
|
||||
A blur on a window can round its last bit differently from the same blur
|
||||
on the whole frame (conv2d picks its kernel by size), so blurred values,
|
||||
and node outputs that use them, match within FLOAT_ROUNDING; pixels the
|
||||
stitch leaves alone stay bit-identical either way.
|
||||
- Timing. A 17 MP no-op Crop + Rotate + Pad, a box Crop For Inpaint and its
|
||||
Stitch Inpaint, each with a bound several times the fixed cost and well
|
||||
under the old one, so a slow runner passes and a full-frame regression
|
||||
does not.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from contextlib import ExitStack
|
||||
import importlib.util
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
import torch
|
||||
import torch.nn.functional as functional
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
COMFY_ROOT = os.environ.get("AUSBOSS_COMFY_ROOT")
|
||||
if COMFY_ROOT:
|
||||
sys.path.append(COMFY_ROOT)
|
||||
HAS_COMFY = importlib.util.find_spec("comfy") is not None
|
||||
if "nodes" in sys.modules and not hasattr(sys.modules["nodes"], "__path__"):
|
||||
del sys.modules["nodes"]
|
||||
|
||||
from nodes import _mask_helpers as mask_helpers
|
||||
from nodes._inpaint_crop_helpers import stitch_blend_from_mask
|
||||
from nodes._mask_helpers import blur_mask, grow_shrink_mask
|
||||
from nodes.node_image_crop_rotate_pad import AusBossImageCropRotatePad
|
||||
from nodes.node_inpaint_crop_stitch import AusBossCropForInpaint, AusBossStitchInpaint
|
||||
|
||||
|
||||
# --- the old full-frame filters, kept as references ---------------------------
|
||||
|
||||
|
||||
def pooled_running_max(values: torch.Tensor, steps: int, dim: int) -> torch.Tensor:
|
||||
"""The max pool grow_shrink_mask used before, one axis at a time."""
|
||||
size = 2 * steps + 1
|
||||
grown = values.unsqueeze(1)
|
||||
if dim == 2:
|
||||
grown = functional.max_pool2d(grown, kernel_size=(1, size), stride=1, padding=(0, steps))
|
||||
else:
|
||||
grown = functional.max_pool2d(grown, kernel_size=(size, 1), stride=1, padding=(steps, 0))
|
||||
return grown.squeeze(1)
|
||||
|
||||
|
||||
def whole_frame(mask, reach, run):
|
||||
return run(mask)
|
||||
|
||||
|
||||
def old_filters():
|
||||
"""Patch the old behaviour back in: whole-frame filters, max pool grows."""
|
||||
stack = ExitStack()
|
||||
stack.enter_context(patch.object(mask_helpers, "_within_support", whole_frame))
|
||||
stack.enter_context(patch.object(mask_helpers, "_running_max", pooled_running_max))
|
||||
return stack
|
||||
|
||||
|
||||
def photo(height: int, width: int, seed: int = 0) -> np.ndarray:
|
||||
"""A smooth picture with grain, like a photo, as HWC uint8."""
|
||||
rng = np.random.default_rng(seed)
|
||||
rows, cols = np.mgrid[0:height, 0:width]
|
||||
picture = np.stack(
|
||||
[cols * 255 // max(1, width), rows * 255 // max(1, height), (rows + cols) * 127 // max(1, height + width)],
|
||||
axis=-1,
|
||||
).astype(np.int16)
|
||||
return np.clip(picture + rng.integers(-20, 20, picture.shape), 0, 255).astype(np.uint8)
|
||||
|
||||
|
||||
def box_mask(height: int, width: int, top: int, left: int, box_h: int, box_w: int, value: float = 1.0):
|
||||
mask = torch.zeros((1, height, width), dtype=torch.float32)
|
||||
mask[:, top : top + box_h, left : left + box_w] = value
|
||||
return mask
|
||||
|
||||
|
||||
# One float32 step at 1.0 is 1.2e-7; a tenth of an 8-bit level is 4e-4.
|
||||
FLOAT_ROUNDING = 1e-6
|
||||
|
||||
|
||||
def assert_same(case: unittest.TestCase, new, old, where: str = "", tolerance: float = 0.0) -> None:
|
||||
if isinstance(new, torch.Tensor):
|
||||
case.assertTrue(isinstance(old, torch.Tensor), where)
|
||||
case.assertEqual(tuple(new.shape), tuple(old.shape), where)
|
||||
if tolerance and new.dtype.is_floating_point:
|
||||
diff = float((new - old).abs().max()) if new.numel() else 0.0
|
||||
case.assertLessEqual(diff, tolerance, f"{where}: max diff {diff}")
|
||||
else:
|
||||
case.assertTrue(torch.equal(new, old), f"{where}: max diff {float((new - old).abs().max())}")
|
||||
elif isinstance(new, dict):
|
||||
case.assertEqual(sorted(new), sorted(old), where)
|
||||
for key in new:
|
||||
assert_same(case, new[key], old[key], f"{where}.{key}", tolerance)
|
||||
elif isinstance(new, (list, tuple)):
|
||||
case.assertEqual(len(new), len(old), where)
|
||||
for index, (a, b) in enumerate(zip(new, old)):
|
||||
assert_same(case, a, b, f"{where}[{index}]", tolerance)
|
||||
else:
|
||||
case.assertEqual(new, old, where)
|
||||
|
||||
|
||||
# --- pixel match ---------------------------------------------------------------
|
||||
|
||||
|
||||
class FilterMatchTests(unittest.TestCase):
|
||||
def masks(self, height, width):
|
||||
generator = torch.Generator().manual_seed(height * 1000 + width)
|
||||
noise = torch.rand((2, height, width), generator=generator)
|
||||
yield "noise", noise
|
||||
yield "sparse soft", (noise > 0.9).float() * torch.rand((2, height, width), generator=generator)
|
||||
yield "inner box", box_mask(height, width, height // 3, width // 3, max(1, height // 5), max(1, width // 6), 0.7)
|
||||
yield "box on the left edge", box_mask(height, width, height // 4, 0, max(1, height // 3), max(1, width // 7))
|
||||
yield "box in a corner", box_mask(height, width, height - max(1, height // 6), width - max(1, width // 6), height, width)
|
||||
yield "one pixel", box_mask(height, width, height // 2, width // 2, 1, 1)
|
||||
yield "empty", torch.zeros((1, height, width))
|
||||
frames = torch.zeros((3, height, width))
|
||||
frames[0, : height // 4, : width // 4] = 1.0
|
||||
frames[2, -max(1, height // 5) :, width // 2 :] = 0.4
|
||||
yield "frames in different places", frames
|
||||
|
||||
def test_grow_and_shrink_match_the_max_pool(self):
|
||||
for height, width in ((1, 1), (5, 9), (64, 48), (211, 307)):
|
||||
for name, mask in self.masks(height, width):
|
||||
for pixels in (1, 2, 3, 5, 8, 16, 31, 48, 100, -1, -3, -8, -48):
|
||||
with self.subTest(size=(height, width), mask=name, pixels=pixels):
|
||||
new = grow_shrink_mask(mask, pixels)
|
||||
with old_filters():
|
||||
old = grow_shrink_mask(mask, pixels)
|
||||
assert_same(self, new, old)
|
||||
|
||||
def test_blur_matches_the_whole_frame_blur(self):
|
||||
for height, width in ((1, 1), (5, 9), (64, 48), (211, 307)):
|
||||
for name, mask in self.masks(height, width):
|
||||
for sigma in (0.5, 2.0, 16.0, 48 / 3.0):
|
||||
with self.subTest(size=(height, width), mask=name, sigma=sigma):
|
||||
new = blur_mask(mask, sigma)
|
||||
with old_filters():
|
||||
old = blur_mask(mask, sigma)
|
||||
assert_same(self, new, old, tolerance=FLOAT_ROUNDING)
|
||||
# Where the old blur gave exactly 0, so does the new one.
|
||||
self.assertTrue(torch.equal(new == 0, old == 0))
|
||||
|
||||
def test_the_stitch_blend_matches(self):
|
||||
mask = box_mask(300, 220, 40, 60, 90, 70)
|
||||
for blend, grow in ((0, 0), (16, 0), (48, 8), (32, -6)):
|
||||
with self.subTest(blend=blend, grow=grow):
|
||||
new = stitch_blend_from_mask(mask, blend, grow)
|
||||
with old_filters():
|
||||
old = stitch_blend_from_mask(mask, blend, grow)
|
||||
assert_same(self, new, old, tolerance=FLOAT_ROUNDING)
|
||||
self.assertTrue(torch.equal(new == 0, old == 0))
|
||||
|
||||
|
||||
class NodeMatchTests(unittest.TestCase):
|
||||
"""Whole nodes, every output and the stitcher, before and after."""
|
||||
|
||||
def crop_and_stitch(self, image, mask, **settings):
|
||||
crop = AusBossCropForInpaint().crop(image, mask, **settings)
|
||||
generated = (crop[0] * 0.85 + 0.1).clamp(0.0, 1.0)
|
||||
outputs = [crop]
|
||||
for options in ({}, {"color_match": 1.0}):
|
||||
outputs.append(AusBossStitchInpaint().stitch(crop[2], generated, **options))
|
||||
return outputs
|
||||
|
||||
def test_crop_for_inpaint_and_stitch_match(self):
|
||||
height, width = 420, 300
|
||||
image = torch.from_numpy(photo(height, width)).float().unsqueeze(0) / 255.0
|
||||
cases = {
|
||||
"the box-edit settings": dict(
|
||||
context_factor=1.0, blend_pixels=48, output_multiple=32, context_pixels=96, mask_grow=8,
|
||||
mask_blur=2.0, target_megapixels=0.05, rescale_algorithm="bicubic", keep_inside=True,
|
||||
),
|
||||
"defaults": dict(context_factor=1.2, blend_pixels=16, output_multiple=32),
|
||||
"shrink and pad past the edge": dict(
|
||||
context_factor=2.0, blend_pixels=24, output_multiple=64, mask_grow=-4, mask_blur=6.0,
|
||||
keep_inside=False,
|
||||
),
|
||||
"inverted": dict(context_factor=1.0, blend_pixels=8, output_multiple=8, invert_mask=True, mask_grow=3),
|
||||
"outpaint": dict(context_factor=1.0, blend_pixels=16, output_multiple=8, extend_left=40, extend_down=24, mask_grow=4),
|
||||
}
|
||||
masks = {
|
||||
"inner box": box_mask(height, width, 150, 90, 80, 60),
|
||||
"box on the edge": box_mask(height, width, 0, 200, 70, 100),
|
||||
"empty": torch.zeros((1, height, width)),
|
||||
}
|
||||
for case, settings in cases.items():
|
||||
for name, mask in masks.items():
|
||||
with self.subTest(settings=case, mask=name):
|
||||
new = self.crop_and_stitch(image, mask, **settings)
|
||||
with old_filters():
|
||||
old = self.crop_and_stitch(image, mask, **settings)
|
||||
assert_same(self, new, old, tolerance=FLOAT_ROUNDING)
|
||||
# The stitched picture is the original wherever the old
|
||||
# blend was 0, to the bit.
|
||||
stitcher = old[0][2]
|
||||
ox, oy, ow, oh = stitcher["canvas_to_original"]
|
||||
untouched = stitcher["blend"][0, oy : oy + oh, ox : ox + ow] == 0
|
||||
source = stitcher["canvas"][0, oy : oy + oh, ox : ox + ow]
|
||||
self.assertTrue(torch.equal(new[1][0][0][untouched], source[untouched]))
|
||||
|
||||
def load(self, frames, **values):
|
||||
with patch("nodes.node_image_crop_rotate_pad.resolve_input_path", return_value=Path("source.png")), patch(
|
||||
"nodes.node_image_crop_rotate_pad.load_image_frames", return_value=frames
|
||||
):
|
||||
return AusBossImageCropRotatePad().load_transform("source.png", **values)
|
||||
|
||||
def test_crop_rotate_pad_matches(self):
|
||||
opaque = Image.fromarray(photo(180, 140, seed=1), "RGB").convert("RGBA")
|
||||
cutout = opaque.copy()
|
||||
alpha = np.full((180, 140), 255, np.uint8)
|
||||
alpha[30:90, 20:70] = 0
|
||||
cutout.putalpha(Image.fromarray(alpha))
|
||||
layouts = {
|
||||
"nothing to do": {},
|
||||
"padded": dict(pad_left=24, pad_bottom=40),
|
||||
"turned and cropped": dict(rotation_degrees=-11.0, crop_x=8, crop_y=6, crop_width=120, crop_height=150),
|
||||
"feathered pad, wide blend": dict(pad_top=32, pad_right=16, feather=6, stitch_blend=48, stitch_grow=-4),
|
||||
}
|
||||
if HAS_COMFY: # the megapixel resize runs through comfy.utils
|
||||
layouts["resized"] = dict(pad_left=16, resize_to_megapixels=True, megapixels=0.05)
|
||||
for picture_name, picture in (("opaque", opaque), ("see-through", cutout)):
|
||||
for painted in ("fill", "keep picture"):
|
||||
for layout, values in layouts.items():
|
||||
with self.subTest(picture=picture_name, painted_area=painted, layout=layout):
|
||||
new = self.load([picture], painted_area=painted, **values)
|
||||
with old_filters():
|
||||
old = self.load([picture], painted_area=painted, **values)
|
||||
assert_same(self, new, old, tolerance=FLOAT_ROUNDING)
|
||||
# Two outputs, two tensors: no consumer changes one through the other.
|
||||
self.assertIsNot(new[3], new[2]["original"]["frames"])
|
||||
|
||||
|
||||
# --- timing ----------------------------------------------------------------------
|
||||
|
||||
# 3360 x 5024, the size of the photo the slowdown was found on.
|
||||
BIG_W, BIG_H = 3360, 5024
|
||||
|
||||
|
||||
def best_of(runs: int, call):
|
||||
best, result = None, None
|
||||
for _ in range(runs):
|
||||
start = time.perf_counter()
|
||||
result = call()
|
||||
took = time.perf_counter() - start
|
||||
best = took if best is None else min(best, took)
|
||||
return best, result
|
||||
|
||||
|
||||
class BigPictureTimingTests(unittest.TestCase):
|
||||
"""Bounds for a CI runner; on two CPU threads the old code took several
|
||||
times each one (see the PR for the before and after numbers)."""
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
cls.picture = Image.fromarray(photo(BIG_H, BIG_W), "RGB").convert("RGBA")
|
||||
cls.image = torch.from_numpy(np.asarray(cls.picture.convert("RGB"), dtype=np.float32) / 255.0).unsqueeze(0)
|
||||
cls.mask = box_mask(BIG_H, BIG_W, BIG_H // 3, BIG_W // 3, BIG_H // 6, BIG_W // 5)
|
||||
|
||||
def test_a_no_op_crop_rotate_pad_is_quick(self):
|
||||
def run():
|
||||
with patch("nodes.node_image_crop_rotate_pad.resolve_input_path", return_value=Path("source.png")), patch(
|
||||
"nodes.node_image_crop_rotate_pad.load_image_frames", return_value=[self.picture]
|
||||
):
|
||||
return AusBossImageCropRotatePad().load_transform("source.png")
|
||||
|
||||
took, outputs = best_of(2, run)
|
||||
self.assertFalse(bool(outputs[1].any()))
|
||||
self.assertLess(took, 2.5, f"Crop + Rotate + Pad with nothing to do took {took:.2f} s at 17 MP")
|
||||
|
||||
def test_a_box_crop_and_stitch_are_quick(self):
|
||||
settings = dict(
|
||||
context_factor=1.0, blend_pixels=48, output_multiple=32, context_pixels=96, mask_grow=8,
|
||||
mask_blur=2.0, target_megapixels=1.9, rescale_algorithm="bicubic", keep_inside=True,
|
||||
)
|
||||
took, crop = best_of(2, lambda: AusBossCropForInpaint().crop(self.image, self.mask, **settings))
|
||||
self.assertLess(took, 1.5, f"Crop For Inpaint took {took:.2f} s for a box on a 17 MP picture")
|
||||
generated = (crop[0] * 0.9 + 0.05).contiguous()
|
||||
took, _ = best_of(2, lambda: AusBossStitchInpaint().stitch(crop[2], generated))
|
||||
self.assertLess(took, 1.0, f"Stitch Inpaint took {took:.2f} s for a box on a 17 MP picture")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,110 @@
|
||||
"""Stitch Inpaint 🆎 Follow changes (nodes/_follow_changes_helpers.py).
|
||||
|
||||
A model that redraws the whole crop draws a new thing a little past the
|
||||
box; the classic paste cut it at the box's edge. Follow changes pastes the
|
||||
box plus every change that touches it, after undoing a small zoom."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
if "nodes" in sys.modules and not hasattr(sys.modules["nodes"], "__path__"):
|
||||
del sys.modules["nodes"]
|
||||
|
||||
import torch
|
||||
import torch.nn.functional as F
|
||||
|
||||
from nodes._inpaint_crop_helpers import build_crop
|
||||
from nodes.node_inpaint_crop_stitch import AusBossStitchInpaint
|
||||
|
||||
H, W = 600, 800
|
||||
|
||||
|
||||
def picture():
|
||||
"""A textured picture: smooth gradients plus a fine grid the realign can lock onto."""
|
||||
ys = torch.linspace(0, 1, H)[:, None]
|
||||
xs = torch.linspace(0, 1, W)[None, :]
|
||||
grid = ((torch.arange(H)[:, None] // 12 + torch.arange(W)[None, :] // 12) % 2).float()
|
||||
r = 0.3 + 0.3 * xs + 0.1 * grid
|
||||
g = 0.3 + 0.3 * ys + 0.1 * grid
|
||||
b = 0.5 + 0.0 * xs + 0.1 * (1 - grid)
|
||||
return torch.stack([r.expand(H, W), g.expand(H, W), b.expand(H, W)], -1)[None].clamp(0, 1)
|
||||
|
||||
|
||||
BOX = (300, 200, 500, 400) # x0, y0, x1, y1
|
||||
|
||||
|
||||
def crop():
|
||||
image = picture()
|
||||
mask = torch.zeros(1, H, W)
|
||||
x0, y0, x1, y1 = BOX
|
||||
mask[:, y0:y1, x0:x1] = 1
|
||||
_, _, stitcher = build_crop(image, mask, 1.0, 8, 8, context_pixels=96)
|
||||
return image, stitcher
|
||||
|
||||
|
||||
def redraw(stitcher, zoom=1.0):
|
||||
"""What such a model returns: the crop, a red block that reaches 40 px
|
||||
below the box, all optionally zoomed about the centre."""
|
||||
cx, cy, cw, ch = stitcher["crop_to_canvas"]
|
||||
out = stitcher["canvas"][:, cy:cy + ch, cx:cx + cw, :].clone()
|
||||
x0, y0, x1, y1 = BOX
|
||||
out[:, y0 - cy + 40:y1 - cy + 40, x0 - cx + 40:x1 - cx - 40, :] = torch.tensor([0.9, 0.1, 0.1])
|
||||
if zoom != 1.0:
|
||||
theta = torch.tensor([[[1 / zoom, 0, 0], [0, 1 / zoom, 0]]], dtype=torch.float32)
|
||||
grid = F.affine_grid(theta, (1, 3, ch, cw), align_corners=False)
|
||||
out = F.grid_sample(out.permute(0, 3, 1, 2), grid, padding_mode="border",
|
||||
align_corners=False).permute(0, 2, 3, 1)
|
||||
return out
|
||||
|
||||
|
||||
class FollowChangesTests(unittest.TestCase):
|
||||
def stitch(self, follow, zoom=1.0):
|
||||
image, stitcher = crop()
|
||||
result, mask = AusBossStitchInpaint().stitch(stitcher, redraw(stitcher, zoom), follow_changes=follow)
|
||||
return image, result, mask
|
||||
|
||||
def test_off_cuts_the_new_thing_at_the_box(self):
|
||||
_, result, _ = self.stitch(False)
|
||||
x0, _, x1, y1 = BOX
|
||||
below = result[0, y1 + 15:y1 + 30, x0 + 60:x1 - 60]
|
||||
self.assertLess(float(below[..., 0].mean()), 0.7)
|
||||
|
||||
def test_on_pastes_what_reaches_past_the_box(self):
|
||||
_, result, mask = self.stitch(True)
|
||||
x0, _, x1, y1 = BOX
|
||||
below = result[0, y1 + 15:y1 + 30, x0 + 60:x1 - 60]
|
||||
self.assertGreater(float(below[..., 0].mean()), 0.85)
|
||||
self.assertGreater(float(mask[0, y1 + 20, (x0 + x1) // 2]), 0.9)
|
||||
|
||||
def test_on_leaves_the_picture_away_from_the_change(self):
|
||||
image, result, _ = self.stitch(True)
|
||||
x0, y0, x1, _ = BOX
|
||||
# Left of the box and above it the model drew nothing new.
|
||||
self.assertTrue(torch.equal(result[0, :, : x0 - 120], image[0, :, : x0 - 120]))
|
||||
self.assertTrue(torch.equal(result[0, : y0 - 120], image[0, : y0 - 120]))
|
||||
|
||||
def test_on_undoes_a_small_zoom(self):
|
||||
image, off, _ = self.stitch(False, zoom=1.03)
|
||||
_, on, _ = self.stitch(True, zoom=1.03)
|
||||
x0, y0, x1, y1 = BOX
|
||||
# Inside the box, away from the red block: the grid lines up again.
|
||||
area = (slice(y0 + 5, y0 + 35), slice(x0 + 5, x1 - 5))
|
||||
miss_off = float((off[0][area] - image[0][area]).abs().mean())
|
||||
miss_on = float((on[0][area] - image[0][area]).abs().mean())
|
||||
self.assertLess(miss_on, miss_off * 0.5)
|
||||
|
||||
def test_an_old_workflow_empty_value_stays_off(self):
|
||||
image, stitcher = crop()
|
||||
node = AusBossStitchInpaint()
|
||||
a, _ = node.stitch(stitcher, redraw(stitcher), follow_changes="")
|
||||
b, _ = node.stitch(stitcher, redraw(stitcher), follow_changes=False)
|
||||
self.assertTrue(torch.equal(a, b))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -697,7 +697,7 @@ class EdgeHaloTests(unittest.TestCase):
|
||||
stitch_cls = NODE_CLASS_MAPPINGS["AUSBOSS_NODES_StitchInpaint"]
|
||||
types = stitch_cls.INPUT_TYPES()
|
||||
self.assertEqual(list(types["required"]), ["stitcher", "inpainted"])
|
||||
self.assertEqual(list(types["optional"]), ["fix_edge_halo", "color_match", "seam", "paste_onto"])
|
||||
self.assertEqual(list(types["optional"]), ["fix_edge_halo", "color_match", "seam", "paste_onto", "follow_changes"])
|
||||
kind, options = types["optional"]["fix_edge_halo"]
|
||||
self.assertEqual(kind, "BOOLEAN")
|
||||
self.assertIs(options["default"], False)
|
||||
|
||||
@@ -64,7 +64,7 @@ class SavedFallbackTests(unittest.TestCase):
|
||||
cls.fallbacks = saved_fallbacks()
|
||||
|
||||
def test_the_known_fallbacks_are_read(self):
|
||||
self.assertEqual(self.fallbacks["AUSBOSS_NODES_StitchInpaint"], {"seam": "classic", "paste_onto": "crop"})
|
||||
self.assertEqual(self.fallbacks["AUSBOSS_NODES_StitchInpaint"], {"seam": "classic", "paste_onto": "crop", "follow_changes": False})
|
||||
self.assertEqual(self.fallbacks["AUSBOSS_NODES_CropForInpaint"], {"keep_inside": True})
|
||||
self.assertEqual(self.fallbacks["AUSBOSS_NODES_RefineMask"], {"preview": True, "max_hole_size": 0})
|
||||
for node_id in ("AUSBOSS_NODES_LaMaInpaint", "AUSBOSS_NODES_SelectFrame"):
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
import sys
|
||||
import unittest
|
||||
|
||||
import torch
|
||||
|
||||
ROOT = Path(__file__).resolve().parent.parent
|
||||
sys.path.insert(0, str(ROOT))
|
||||
if "nodes" in sys.modules and not hasattr(sys.modules["nodes"], "__path__"):
|
||||
del sys.modules["nodes"]
|
||||
|
||||
from nodes._sheet_split_helpers import cut_columns, split_sheet
|
||||
|
||||
WHITE = 1.0
|
||||
|
||||
|
||||
def sheet(spans: list[tuple[int, int]], width: int = 400, height: int = 60) -> torch.Tensor:
|
||||
"""A white HWC sheet with one solid block per span; block i has value i / 10."""
|
||||
image = torch.full((height, width, 3), WHITE)
|
||||
for index, (start, end) in enumerate(spans):
|
||||
image[10:50, start:end] = (index + 1) / 10
|
||||
return image
|
||||
|
||||
|
||||
def values_in(piece: torch.Tensor) -> set[float]:
|
||||
return {round(float(v), 2) for v in piece[..., 0].unique()} - {WHITE}
|
||||
|
||||
|
||||
class CutColumnTests(unittest.TestCase):
|
||||
def test_cuts_land_in_the_gaps_not_on_equal_shares(self):
|
||||
# Equal quarters are at 100, 200, 300; the gaps are at 115-125, 190-205, 280-290.
|
||||
cuts = cut_columns(sheet([(5, 115), (125, 190), (205, 280), (290, 395)]), 4)
|
||||
self.assertEqual(cuts[0], 0)
|
||||
self.assertEqual(cuts[-1], 400)
|
||||
self.assertTrue(115 <= cuts[1] <= 125, cuts)
|
||||
self.assertTrue(190 <= cuts[2] <= 205, cuts)
|
||||
self.assertTrue(280 <= cuts[3] <= 290, cuts)
|
||||
|
||||
def test_touching_pictures_cut_where_least_is_lost(self):
|
||||
image = sheet([(5, 110), (110, 200), (200, 300), (300, 395)])
|
||||
image[10:50, 105:115] = 0.5 # an overlap: the cut still has to go somewhere
|
||||
image[30:50, 105:115] = WHITE # thinnest at its upper half only
|
||||
cuts = cut_columns(image, 4)
|
||||
self.assertEqual(len(cuts), 5)
|
||||
self.assertEqual(cuts, sorted(set(cuts)))
|
||||
|
||||
def test_one_piece_is_the_whole_width(self):
|
||||
self.assertEqual(cut_columns(sheet([(5, 395)]), 1), [0, 400])
|
||||
|
||||
|
||||
class SplitSheetTests(unittest.TestCase):
|
||||
def test_each_piece_holds_one_picture_and_all_share_a_size(self):
|
||||
image = sheet([(5, 115), (125, 190), (205, 280), (290, 395)])
|
||||
pieces = split_sheet(image[None], 4)
|
||||
self.assertEqual(pieces.shape[0], 4)
|
||||
self.assertEqual(len({tuple(p.shape) for p in pieces}), 1)
|
||||
for index, piece in enumerate(pieces):
|
||||
self.assertEqual(values_in(piece), {round((index + 1) / 10, 2)})
|
||||
|
||||
def test_outer_pieces_keep_the_sheet_edge_at_their_edge(self):
|
||||
# Pictures that run to the sheet's edges stay flush there after padding.
|
||||
image = sheet([(0, 115), (125, 190), (205, 280), (290, 400)])
|
||||
pieces = split_sheet(image[None], 4)
|
||||
self.assertLess(float(pieces[0][30, 0, 0]), WHITE)
|
||||
self.assertLess(float(pieces[-1][30, -1, 0]), WHITE)
|
||||
|
||||
def test_backdrop_padding_matches_a_coloured_sheet(self):
|
||||
image = sheet([(5, 115), (125, 190), (205, 280), (290, 395)])
|
||||
image[image == WHITE] = 0.9
|
||||
pieces = split_sheet(image[None], 4)
|
||||
self.assertAlmostEqual(float(pieces[1][0, 0, 0]), 0.9, places=5)
|
||||
|
||||
def test_a_batch_gives_every_picture_its_pieces_in_order(self):
|
||||
first = sheet([(5, 115), (125, 190), (205, 280), (290, 395)])
|
||||
second = sheet([(5, 90), (110, 190), (215, 300), (320, 395)])
|
||||
pieces = split_sheet(torch.stack([first, second]), 4)
|
||||
self.assertEqual(pieces.shape[0], 8)
|
||||
self.assertEqual(values_in(pieces[4]), {0.1})
|
||||
self.assertEqual(values_in(pieces[7]), {0.4})
|
||||
|
||||
def test_one_piece_returns_the_batch_unchanged(self):
|
||||
image = sheet([(5, 395)])[None]
|
||||
self.assertIs(split_sheet(image, 1), image)
|
||||
|
||||
def test_more_pieces_than_columns_still_cuts(self):
|
||||
pieces = split_sheet(torch.ones((1, 4, 3, 3)), 16)
|
||||
self.assertEqual(pieces.shape[0], 3)
|
||||
|
||||
def test_rejects_a_non_batch(self):
|
||||
with self.assertRaises(ValueError):
|
||||
split_sheet(torch.ones((4, 4, 3)), 2)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -303,23 +303,29 @@ test("Mask Refine saved since keeps its Max hole size", () => {
|
||||
|
||||
test("Stitch Inpaint saved before Seam still opens classic", () => {
|
||||
const names = widgetNames("AUSBOSS_NODES_StitchInpaint", ["stitcher", "inpainted"]);
|
||||
const types = { fix_edge_halo: "toggle", seam: "combo", paste_onto: "combo" };
|
||||
const types = { fix_edge_halo: "toggle", seam: "combo", paste_onto: "combo", follow_changes: "toggle" };
|
||||
const choices = (list) => {
|
||||
list.find((widget) => widget.name === "seam").options = { values: ["classic", "blend in"] };
|
||||
list.find((widget) => widget.name === "paste_onto").options = { values: ["crop", "original"] };
|
||||
};
|
||||
const widgets = restoreByPosition(names, [false, 0.5, ""], types);
|
||||
choices(widgets);
|
||||
assert.deepEqual(resetUnknownValues(widgets, cardFallbacks("AUSBOSS_NODES_StitchInpaint")), ["seam", "paste_onto"]);
|
||||
assert.deepEqual(widgets.map((widget) => widget.value), [false, 0.5, "classic", "crop", undefined]);
|
||||
assert.deepEqual(resetUnknownValues(widgets, cardFallbacks("AUSBOSS_NODES_StitchInpaint")), ["seam", "paste_onto", "follow_changes"]);
|
||||
assert.deepEqual(widgets.map((widget) => widget.value), [false, 0.5, "classic", "crop", false, undefined]);
|
||||
// Saved with Seam: its choice stays, and the card's empty value is crop.
|
||||
const seamed = restoreByPosition(names, [false, 0.5, "blend in", ""], types);
|
||||
choices(seamed);
|
||||
assert.deepEqual(resetUnknownValues(seamed, cardFallbacks("AUSBOSS_NODES_StitchInpaint")), ["paste_onto"]);
|
||||
assert.deepEqual(resetUnknownValues(seamed, cardFallbacks("AUSBOSS_NODES_StitchInpaint")), ["paste_onto", "follow_changes"]);
|
||||
assert.equal(seamed.find((widget) => widget.name === "seam").value, "blend in");
|
||||
assert.equal(seamed.find((widget) => widget.name === "paste_onto").value, "crop");
|
||||
// Saved with Paste onto, before Follow changes: the card's empty value
|
||||
// lands in Follow changes, which opens off.
|
||||
const pasted = restoreByPosition(names, [false, 0.5, "blend in", "original", ""], types);
|
||||
choices(pasted);
|
||||
assert.deepEqual(resetUnknownValues(pasted, cardFallbacks("AUSBOSS_NODES_StitchInpaint")), ["follow_changes"]);
|
||||
assert.equal(pasted.find((widget) => widget.name === "follow_changes").value, false);
|
||||
// A real choice is left alone.
|
||||
const chosen = restoreByPosition(names, [false, 0.5, "blend in", "original", ""], types);
|
||||
const chosen = restoreByPosition(names, [false, 0.5, "blend in", "original", true, ""], types);
|
||||
choices(chosen);
|
||||
assert.deepEqual(resetUnknownValues(chosen, cardFallbacks("AUSBOSS_NODES_StitchInpaint")), []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user