h0bb3's log

4 min read

Image Forge: the tool I kept not building

The generated animals in Noatun are 3D models, and a generated 3D model usually starts as a picture. An image generator draws the thing from the front, the side and the back, often all on one sheet, and a second tool builds a model from those views. Between the two sits a chore: cut the sheet apart, remove the background, export each view at the same size, name the files. I did it by hand in an image editor, every time, and it took ages every time.

This morning I asked the agent for the tool I was missing. This afternoon it is public: h0bb3.github.io/image-forge.

One minute. Nobody held the mouse: a script drives the page in a headless browser, draws the pointer and the captions, and joins the screenshots into a film.

What it does

You drop a sheet on the page, or paste it. The background goes, and each separate figure gets a box. You say which is the front, the back, the left, the right, the top and the bottom: one click each, or one key each. Then you export, and get name_front.png, name_back.png and so on, trimmed, centred, and all at the same size so the views keep their scale to each other.

A sheet of four views is four clicks. That was the whole brief: “I want this streamlined.”

It runs in the browser and nothing is uploaded. There is no build step and no dependency: it is a page, a stylesheet and a few JavaScript files. The licence is MIT.

What it grew

The first version was built while I was away from my desk. Everything after that came from using it on a real sheet and saying what annoyed me.

“We need some mouse driven way to get the tagging done.” The first version wanted keys. Now a small bar with the six views sits at the selected figure, above it or next to where you clicked, and jumps to the next figure when you have chosen.

“I get areas that should be transparent, e.g. area between legs.” Removing a background by colour starts from the border of the picture and eats inward, which is what keeps a white eye alive on a white sheet. It is also what leaves the white between two legs. So there is a tool where you click such an area and it goes, two brushes to erase and to bring back, and undo.

One view from another. Generators rarely draw both sides. Left can now be “the right view, mirrored”, in one click, and the choice is remembered for the next sheet.

Projects. One file holds the pictures, the boxes, what was erased by hand and every setting, so a sheet can be picked up again later.

A stand-in in 3D. The views stood up as flat pictures in space, crossed through the middle or on the sides of a cube, to turn about with the mouse and to save as a .glb. It is six pictures at most, and from the wrong angle it looks like a folded card. It is still a quick way to see whether the views agree with each other.

The views of the sample robot stood up as the sides of a cube The cube style, caught at the angle where it is least convincing.

A model in the page

Then I asked whether there was an AI model for removing backgrounds, and whether it could run locally in the browser. The answer was yes to both, followed by an afternoon of finding out which yes.

The first choice, BiRefNet, ran out of memory on the processor and broke a shader limit on the graphics card. The second, IS-Net, works: about fifteen seconds a picture, on the processor, in a worker so the page stays alive. The graphics card would be faster, but the runtime cannot run this model there yet.

There was a licence detail in it too. One popular conversion of IS-Net for the browser is published under AGPL. The original model is Apache 2.0, and another conversion keeps that. The agent had told me the wrong one from memory, checked before building, and said so. For a tool whose output may end up in something I sell, that difference matters.

The model is 180 MB and is downloaded only if you choose it. What it buys is in the picture below: keying by colour leaves the soft shadow under the feet, and the model does not consider a shadow part of a robot.

The feet of the sample robot: with a shadow left by colour keying, and without it after the model Left: by colour. Right: colour and model together, which gave the cleanest cut on this sheet.

What went wrong

Shorter than last time, but not empty.

The brush that made a dot. The eraser was published drawing a single dab where you pressed and nothing along the stroke. It was caught at the first try on the live page, which is also where it should not have been found.

The clock that wasn’t. To check that a saved project opens again, the agent ran the page in a browser with a simulated clock. In that clock, decoding a picture never finishes, so the check hung while the feature worked. The time went into the instrument, not the thing measured.

Names. The two 3D styles were first called “Crossed” and “Box”. I suggested adding a cube style and a centered style, having only looked at the screenshots, and was told politely that those were the two buttons. They are now called Centered and Cube.

And one honest limit: almost all testing was done on one drawn robot. Beyond that there are my own sheets, which is a sample of one user.

The numbers

Metric Value
From the first commit to the film about five and a half hours
Commits 13
Lines, tests included about 2,400
Tests of the image code 17
Dependencies 0
Clicks for a sheet of four views 4
Model, if you want one IS-Net, 180 MB, about 15 s a picture
Pictures uploaded anywhere 0

Take it

It is at h0bb3.github.io/image-forge, and the code is at github.com/h0bb3/image-forge under the MIT licence. There is a sample sheet behind a link on the empty page if you have none of your own.

If you make 3D models from generated pictures, with Tripo (my invite link) or anything else that takes views, this is the chore I am not doing by hand any more. Tell me what your sheets do that mine don’t.