|
Download README.md from Kazzze/sd-text-fix: direct link, hf CLI and curl.
- Browser
- Download file 23.8 kB
-
https://huggingface.co/Kazzze/sd-text-fix/resolve/main/README.md
- Command line
-
hf download hf://Kazzze/sd-text-fix/README.md
-
curl -L -o README.md https://huggingface.co/Kazzze/sd-text-fix/resolve/main/README.md
23.8 kB
| license: agpl-3.0 | |
| tags: | |
| - a1111-stable-diffusion-webui | |
| - comfyui | |
| - comfyui-custom-node | |
| - comfyui-nodes | |
| - custom-nodes | |
| - extension | |
| - forge | |
| - image-editing | |
| - inpainting | |
| - opencv | |
| - python | |
| - react | |
| - reforge | |
| - stable-diffusion | |
| - stable-diffusion-webui | |
| - text | |
| - text-replacement | |
| - typescript | |
| - typography | |
| # Text Fix | |
| > Mirror of [KazeKaze93/sd-text-fix](https://github.com/KazeKaze93/sd-text-fix) at release `v0.9.0`. Install, updates and issues: GitHub. | |
| **Replace the gibberish text an image model draws on clothes, signs and equipment, without opening an image editor.** | |
| Image models write `POLLICE` on a police vest and `LTAANING` over a bakery. Text Fix finds that text, wipes it and writes yours in its place: same spot, size, slant, bend and color, lit the way the surface under it is lit. The model then blends the letters in with a light inpainting pass. | |
| One repository, two hosts: an **extension for AUTOMATIC1111 / Forge / reForge** and a **custom node for ComfyUI**. | |
|  | |
| > **Status: MVP, in active development.** It works and is useful today, but the search still misses some text and finds some that is not there. What comes next is in the [roadmap](ROADMAP.md). | |
| ## Contents | |
| - [What it does](#what-it-does) | |
| - [Requirements](#requirements) | |
| - [Install](#install) | |
| - [Quick start](#quick-start) | |
| - [The editor](#the-editor) | |
| - [Several lines at once](#several-lines-at-once) | |
| - [Shaping the selection](#shaping-the-selection) | |
| - [A block of lines](#a-block-of-lines) | |
| - [Erasing](#erasing) | |
| - [Along a path, bent by hand](#along-a-path-bent-by-hand) | |
| - [The look of the letters](#the-look-of-the-letters) | |
| - [Finding and reading the text](#finding-and-reading-the-text) | |
| - [Without opening the editor](#without-opening-the-editor) | |
| - [Settings](#settings) | |
| - [The model pass](#the-model-pass) | |
| - [ComfyUI](#comfyui) | |
| - [Fonts](#fonts) | |
| - [Limits](#limits) | |
| - [Roadmap](#roadmap) | |
| - [For developers](#for-developers) | |
| - [License](#license) | |
| ## What it does | |
| | | | | |
| |---|---| | |
| | **Finds the text** | Every line that looks like text is outlined when an image arrives. A click finds what the search missed. | | |
| | **Erases it** | The old letters are painted over with the surface they were written on. | | |
| | **Writes yours** | Same place, size, slant and bend. Strokes as thick as the old ones, the old color, the light and shadow of the surface. | | |
| | **A visual editor** | Opens over the WebUI page or from the ComfyUI node. The new text shows at once and follows every setting, with no model involved. | | |
| | **Blends it in** | One light inpainting pass over that spot, so the letters take on the texture of the surface. | | |
| | **Several lines** | Pick any number of texts and give each its own line. | | |
| | **A look of its own** | Outline, shadow, two colors, and materials: embroidery, a worn stencil, neon, engraving. `Match` finds the fonts most like the old letters. | | |
| | **Any shape** | Text along a path drawn by hand, bent by a grid, or following the folds of the cloth. | | |
| | **30 fonts** | 16 bundled, a few system ones, and any you drop into `fonts/`. | | |
|  | |
| ## Requirements | |
| | | | | |
| |---|---| | |
| | Host | AUTOMATIC1111, Forge or reForge; or ComfyUI | | |
| | Python packages | `numpy`, `opencv-python`, `Pillow` 9.2 or newer. Both hosts already ship them: nothing is installed. | | |
| | Node.js | Not needed. The editor comes built. | | |
| | Models | None needed. The model pass uses the checkpoint you have loaded. The optional text detector and reader (PaddleOCR's PP-OCR in ONNX, Apache-2.0) are fetched by a button in the editor: 12.6 MB for the light detector and the reader, 88 MB more for the full detector. They run on `onnxruntime`, which both hosts already ship. | | |
| ## Install | |
| **AUTOMATIC1111 / Forge / reForge.** Open `Extensions` → `Install from URL`, paste the address below and press `Install`. Then restart the web UI. | |
| ``` | |
| https://github.com/KazeKaze93/sd-text-fix | |
| ``` | |
| Or from a terminal: | |
| ``` | |
| cd extensions | |
| git clone https://github.com/KazeKaze93/sd-text-fix.git | |
| ``` | |
| **ComfyUI.** | |
| ``` | |
| cd ComfyUI/custom_nodes | |
| git clone https://github.com/KazeKaze93/sd-text-fix.git | |
| ``` | |
| Restart ComfyUI. The node is `Text Fix`, in the category `image/postprocessing`. | |
| **Update** either one with `git pull` in the `sd-text-fix` folder, then restart the host and refresh the browser page. | |
| ## Quick start | |
| 1. Generate an image. Press the icon with the letter **A** in the row of tools under `Generate`. | |
|  | |
| 2. The editor opens over the page with the image. The text found on it is outlined in yellow. Click the one to replace. | |
| 3. Type the new text. The image shows it at once. | |
| 4. Press `Blend in with the model`, then `To gallery` or `Save`. | |
| The 🔤 button under the gallery of txt2img and img2img opens the editor the same way. In the editor, a file can also be dropped in, pasted, or opened with the folder icon. | |
| ## The editor | |
|  | |
| | | | | |
| |---|---| | |
| | **Top bar** | How a click picks text, the search, and what is done with the result. | | |
| | **Image** | Yellow: what the search found. Green with a number: what is selected. `Original` and `Result` switch between the image and the new text (the `O` key does the same); `Compare` puts them side by side under a divider. The mouse wheel zooms, a drag moves the image. | | |
| | **Side panel** | A text field for every selected line, the look of the letters, and the model pass. | | |
| | **Status line** | What to do next, and what went wrong when something did. | | |
| `Use as the image` makes the result the image to go on with the next text. `Undo` takes that back. `Save` writes the result to the host's output folder for images (the img2img one, unless a common folder is set), with the generation parameters of the source image kept. `To gallery` puts the result into the gallery of the tab the image came from and closes the editor. `img2img` and `Inpaint` put it there too, then send it on to that tab with the generation parameters, as the host's own buttons under the gallery do. `Esc` closes the editor. | |
| The settings of the look and of the model pass are kept between sessions. `Preset`, at the top of `Letters`, keeps a whole look (font, colors, outline, shadow, material and the rest) under a name: `Save` stores the look as it is, the list brings one back, the bin deletes it. The auto mode and a whole folder can use presets too. | |
| ## Finding and reading the text | |
| Out of the box the text is found by looks: thin marks of one height and color in a row. That misses large, heavy and hand-written lettering, and now and then takes a lock of hair or an eye for a line. `Finding the text`, in the side panel, adds a neural text detector that does much better at both: | |
| | | | | |
| |---|---| | |
| | **Search** | `Detector when it is here` (the default: the light detector once its models are fetched, by looks until then), `Detector, light`, `Detector, full`, or `By looks alone`. The line under it says which one is looking now. | | |
| | **Get it** | Fetches a detector's models from Hugging Face into `models/text_fix` of the host (A1111 family: the WebUI's `models` folder; ComfyUI: its `models` folder). Light: 4.7 MB detector plus the 7.8 MB reader. Full: an 88 MB detector, slower, better on small badges and patches. | | |
| | **Start with the old text** | A new line's text field starts with what its old letters say, read by the detector's reader (English letters and signs). The model's gibberish reads as gibberish, of course: correct it rather than type the whole line. | | |
| The detector is used by `Find text`, the auto mode, a whole folder and the ComfyUI node alike. A click on the image still finds text by looks, around the click. | |
| ## Without opening the editor | |
| **The auto mode.** Under the generation settings of txt2img and img2img, `Text Fix: replace the text by itself` puts a list of new texts onto every image the generation makes, before it is saved. One line for each text found: the first line goes onto the most prominent text (the largest), the second onto the next one, and so on. An empty line leaves that text as it is; a line with only a dash (`-`) erases it. `Look` is the editor's look or one of its presets (🔄 reads the presets again); `Blend in with the model` runs the model pass over the new letters inside the generation, at the given strength, with the generation's own prompt cleaned of words that ask for text. `Keep the image as generated too` (on by default) puts the untouched image into the gallery after the changed ones, and saves it with `-before-textfix` in its name when the host saves images. | |
| The auto mode is only as good as the search, which goes by looks alone: it can take a row of hair, an eye or a seam for a line of text and paint over it, and it often misses large, heavy lettering. Keep the image as generated, or look at the results before using them. | |
| **A whole folder.** The folder icon in the editor's top bar opens `A whole folder at once`: the path of a folder, and the same list of new texts. Every PNG, JPG and WebP in it gets the list, with the look of the side panel and, when asked, the model pass with the prompt each image carries. The results go into a new folder `textfix-<date>` in the host's output folder for images (ComfyUI: its output folder); the originals stay as they are. A folder can be named only when the host is reached from this computer alone (not with `--listen` or `--share`). | |
| ## Several lines at once | |
| Switch the click to `Add a line` and click each text in turn. They are numbered in the order of the clicks, and each gets its own text field. A line left empty leaves that text as it is. | |
|  | |
| When the search splits one line in two, or a click misses a letter, switch to `Extend` and click the missing part: it joins the active line. | |
| ## Shaping the selection | |
| The selected line you work on (the active one, with a frame in the side panel) has handles: | |
| | | | | |
| |---|---| | |
| | **The four corners** | Where the new text goes. Pull one corner to make the text taller at that end, or to fit it to a sign seen at an angle. | | |
| | **The round handle above the line** | The bend: drag it up or down and the line arcs over a mug, a banner, a sleeve. | | |
| | **The handle in the middle** | Moves the whole place for the text. | | |
| The handles change only where the new text is written: the old letters are erased where they were. `Shape` in the line's row puts the place back where the letters gave it. A click on a selected line makes it the active one. | |
| ## A block of lines | |
| The lines of a speech bubble or a sign belong together. Select them with `Add a line`, then press `Join` in the `Text` header: they become one block, with one text field. A line break in it starts a new line of the new text; the lines share the block's height and each is centered. `Split` takes the block apart again. | |
|  | |
| ## Erasing | |
| `Erase only` in a line's row erases the old letters and writes nothing in their place. | |
| What the search left behind (a stray letter, an underline, a mark next to the text) is painted over with the `Brush`: pick the line, switch to `Brush`, set its size and paint. The strokes are erased together with that line's letters. `Strokes` in the line's row removes them; `Esc` leaves the brush. | |
| ## Along a path, bent by hand | |
| `Path` writes the new text of the active line along a line you draw: drag from where the text should start to where it should end, in any curve. The old letters are still erased where they were, so the new text can go somewhere else entirely, around a badge or along a ribbon. `Path` in the line's row puts the text back in the old place. | |
| `Warp` shows a grid of points over the new text of the active line: three rows (the top of the letters, their middle, their bottom) and four columns along the line. Drag a point and the letters near it follow, smoothly, as over a bump, a seam or a fold. `Warp` in the line's row undoes it. | |
| `Follow the folds` in `On the surface` does the same by itself: where the cloth is lit it bulges, where it is in shade it sinks, and the letters are carried along as a displacement map carries them. | |
| ## The look of the letters | |
| `Match`, beside the font list, measures the old letters of the active line (stroke thickness, how much thick and thin strokes differ, letter width, slant) and lists the five fonts most like them. It is a guess by shape, not a reading of the letters: on 51 test lines in 30 fonts the right font came first in about a third of them and among the five in four of five. | |
| | | | | |
| |---|---| | |
| | **Second color** | The lower half of each line in another color, with a sharp edge or a smooth gradient. | | |
| | **Outline** | Around the letters, in a color of its own, as on patches, stickers and signs. | | |
| | **Shadow** | Cast by the letters and their outline: direction, softness and darkness. | | |
| | **Material** | `Embroidery`: satin stitches on a slant, darker where the thread enters the cloth, standing a little off it. `Worn stencil`: bridges across the letters and patches where the paint did not take. `Neon`: a tube with a white-hot core and a glow on the wall. `Engraving`: cut into the surface, with the light catching one wall of each cut. `Strength` turns each one down. | | |
| ## Settings | |
| **Top bar** | |
| | | | | |
| |---|---| | |
| | Select, Add a line, Extend, Brush | What a click on the image does: select one line and only it; add one more line; join a missed letter or a second word to the active line; paint over what has to be erased with the active line. | | |
| | Path, Warp | Draw the line the new text of the active line follows; bend its letters with a grid. | | |
| | Find text | Looks for text over the whole image again. It also runs by itself when an image arrives. | | |
| | The eye | Hides the yellow outlines when they are in the way. | | |
| | Reach | How far from a click the letters are looked for. It grows by itself when the line runs out of it. | | |
| **Text** | |
| | | | | |
| |---|---| | |
| | The fields | One for each selected line, in the font chosen below. A line break starts a new line of text. The swatch shows the color the letters will have. | | |
| | Erase only, Shape, Strokes, Path, Warp, Split | Under each field: erase without writing; undo the hand-set shape; remove the brush strokes; write in the old place again; undo the hand warp; take a block apart. | | |
| | Join, Clear | In the header: take all the selected lines as one block; unselect everything. | | |
| **Letters** | |
| | | | | |
| |---|---| | |
| | Font | The fonts in `fonts/`, the 16 bundled ones, then a few system fonts. Each is shown in its own face. `Match` lists the five most like the old letters. | | |
| | Color, Old letters' color | On: every line keeps the color its old letters had. Picking a color turns it off. | | |
| | Second color | The lower part of each line in `Lower color`. `Sharp / smooth`: 0 meets at the middle of the line, 100% runs one color into the other. | | |
| | Size | 1.00 gives letters as tall as the old ones. | | |
| | Spread to the old width | A text shorter than the old one is spread towards the old width: first by spacing the letters, then by widening them a little. | | |
| | Strokes as thick as the old letters' | Thickens or thins the font's strokes to match the old text. Off: `Thinner / bolder` sets it by hand. | | |
| | Hand-made unevenness | Tilts, shifts and resizes each letter a little, as hand lettering is. The button beside it rolls the dice again. | | |
| **Outline and shadow** | |
| | | | | |
| |---|---| | |
| | Outline, Width | The outline's color, and its width in letter heights. 0: no outline. | | |
| | Shadow, Strength | The shadow's color, and how dark it is. 0: no shadow. | | |
| | Right, Down, Blur | Where the shadow falls and how soft it is, in letter heights. | | |
| **Material** | |
| | | | | |
| |---|---| | |
| | The letters are | `Paint`, `Embroidery`, `Worn stencil`, `Neon` or `Engraving`. | | |
| | Strength | How much of the material shows. | | |
| **On the surface** | |
| | | | | |
| |---|---| | |
| | Light and shadow of the surface | Where the surface under a letter is brighter or darker, so is the letter: highlights and folds run over the text. | | |
| | Follow the folds | The letters bend with the folds and bumps of the surface, as its light and shadow show them. | | |
| | Opacity, Soft edges | How solid the paint is, and how sharp its edges are. | | |
| | Move right, Move down | A nudge, in letter heights. `Place` puts the text back. | | |
| ## The model pass | |
| `Blend in with the model` (or `Ctrl + Enter`) runs img2img inpainting over the text alone, at a low denoising strength, with the checkpoint that is loaded. The letters keep their shape; the model adds what paint on that surface would have. | |
|  | |
| | | | | |
| |---|---| | |
| | Denoising strength | How much the model may repaint. 0.25 to 0.35 keeps the letters readable. Higher values bring the gibberish back, one letter at a time. | | |
| | Guide by the letters' edges | Shown when the host has ControlNet models (built into Forge and reForge; the ControlNet extension in AUTOMATIC1111). A canny or lineart model holds the edges of the drawn letters, so the strength can go up to about 0.45 and the surface takes more of the model's texture while the letters keep their shape. `Guide weight` sets how firmly. It doubles the time of a pass. | | |
| | Variants | 1 to 4 passes, each with a seed of its own. They show close up under the image; a click makes one the result. Each takes as long as one pass. | | |
| | Prompt | Filled from the image when it carries its generation parameters. An empty prompt works too. | | |
| | Leave out words that ask for text | On by default. Tags such as `large text printed on hoodie`, `sign that says "OPEN"`, `logo` or `english text` make the model write letters of its own, so they are left out of this pass (the field keeps them), and `text, letters, watermark` goes into the negative. LoRA calls are kept whatever their names say. The status line names what was left out. | | |
| | Sampler, Steps, CFG | As in img2img. | | |
| | Resolution | The size the spot is enlarged to for the pass. 1024 for SDXL models, 512 to 768 for SD 1.5. | | |
| | Context | How much of the surroundings the model sees. | | |
| The pass has a random seed. When it changes a letter, pick another variant, press the button again or lower the strength. | |
| `Compare`, beside `Original` and `Result`, shows the image before on the left and after on the right; drag the divider across the text. | |
| ## ComfyUI | |
| Place `Text Fix` after `VAE Decode` and run the workflow once. Then press `Open editor` on the node: the same editor opens with the image the node received. What you select and type there, and the look, are kept in the node, and the next run of the workflow gives the picture the editor showed. | |
| The model pass belongs to the workflow in ComfyUI. The `Text Fix Blend` node does it in one step: feed it the `image` and `mask` of `Text Fix`, and the model, the two conditionings and the VAE of the workflow. Like the A1111 family's pass, it cuts out the place of the new text with `padding` pixels around it, enlarges it to `resolution`, repaints it at a low `denoise` (0.25 to 0.35) and pastes it back with soft edges. Leave the words that ask for text out of the positive prompt and put `text, letters, watermark` in the negative. | |
| | `Text Fix Blend` input | | | |
| |---|---| | |
| | `image`, `mask` | From `Text Fix`. | | |
| | `model`, `positive`, `negative`, `vae` | From the checkpoint and the text encoders of the workflow. | | |
| | `seed`, `steps`, `cfg`, `sampler_name`, `scheduler`, `denoise` | As in a KSampler. | | |
| | `resolution`, `padding` | The size the spot is enlarged to (1024 for SDXL, 512 to 768 for SD 1.5), and how much of the surroundings the model sees. | | |
| Without the editor, the node picks the text itself: | |
| | Input | | | |
| |---|---| | |
| | `text` | One line for each text found, in the order of the numbers on the `found` output. An empty line leaves that text as it is. Not used once lines are picked in the editor. | | |
| | `font`, `color` | `color` is `auto` (the color of the old letters) or `#rrggbb`. | | |
| | `point_x`, `point_y` | Both at 0: the text is looked for over the whole image. Otherwise the place of the one text to replace, as a share of the width and the height. | | |
| | `size`, `spread`, `match_stroke`, `unevenness`, `shading`, `opacity`, `soften`, `seed`, `weight`, `shift_x`, `shift_y` | The look of the letters, as in the settings above. The editor writes them too. Outline, shadow, the second color, the material and `Follow the folds` have no inputs of their own: the editor keeps them in the node with the selected lines. | | |
| | Output | | | |
| |---|---| | |
| | `image` | The image with the text replaced. | | |
| | `mask` | The places that were written on, for the inpainting pass. | | |
| | `found` | The image with everything that was found outlined, and what is replaced numbered. | | |
| ## Fonts | |
| Sixteen fonts are bundled in `fonts/bundled/` (their licenses are in `fonts/bundled/licenses/`), and a few plain, heavy system fonts are listed after them. Put your own `.ttf` / `.otf` files into `fonts/` and reload: they come first in the list. | |
| ## Limits | |
| - **Without the detector the search goes by looks alone.** A line has to show at least three marks of one height, color and stroke in a row, clearly unlike what surrounds them. Short, faint, large or handwritten text is missed, and now and then a lock of hair, an eye or the edge of a collar is taken for text. The detector (see [Finding and reading the text](#finding-and-reading-the-text)) does much better; a click finds what any search missed. | |
| - **Large decorative lettering** is often found in parts. Use `Extend the last line`. | |
| - **Bent text** is followed as far as a smooth curve goes: a mug, a sleeve, a banner. Text across sharp folds will not follow them; `Warp` and `Follow the folds` bend the new text by hand or by the light, but `Follow the folds` is a guess from brightness, not a model of the surface. | |
| - **The auto mode and a whole folder** work without a click, so they inherit every false find of the search: by looks alone, an eye and the hair over it were once taken for a line and painted over (the detector found the real lettering on the same image and left the eyes alone). Use the detector, and keep the originals (the auto mode does by default; a folder never touches them). | |
| - **Font matching** goes by the shapes of the old letters, which a model draws blurred and uneven. Take its list as five fonts to try, not as the answer. | |
| - **Text tilted by more than about 25 degrees** is found letter by letter. | |
| - **Very small text**, a few pixels high, is found poorly. | |
| - **Speech bubbles** are found line by line. Lettering a whole bubble is what [Comic Lettering](https://github.com/KazeKaze93/sd-comic-lettering) is for. | |
| ## Roadmap | |
| The plan, with everything that has been proposed so far, is in [ROADMAP.md](ROADMAP.md): several variants of the model pass, a model pass guided by the outline of the letters, presets, an automatic mode and batch work. | |
| ## For developers | |
| | | | | |
| |---|---| | |
| | [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md) | The layers, and how text is found, erased and written. | | |
| | [docs/DEVELOPMENT.md](docs/DEVELOPMENT.md) | Working on the code: layout, reloading, checking a change. | | |
| ## License | |
| GNU Affero General Public License v3.0. See [LICENSE](LICENSE). The bundled fonts keep their own licenses, in `fonts/bundled/licenses/`. | |