# SpriteDX - PhotoRoom Test

For background removal, strong worry-free alternative is to use PhotoRoom API.

Let’s do some testing.

Given:

Following sprite sheet without transparency (1024×1024):

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768597601797/eb23130b-3562-4f7d-92c8-30a023b221e7.png align="center")

we can run create a transparent version(1024×1024):

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768597748898/14d4e1d6-fbd4-4593-b90f-c234056018d8.png align="center")

Let’s replace the background to see things better:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768597771086/053a404a-8d2c-418f-8e5c-6605f12e5d31.jpeg align="center")

Alpha Channel:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768597814877/b81d0364-6877-4122-ba8e-29370acd4eb5.png align="center")

There are some alpha bleeds.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768597861864/30485c0a-42db-4cdb-9321-3baebddc2f4c.png align="center")

Let’s threshold it at half way point.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768597895417/29f553bd-c17c-45e8-90cf-6a40c7df3d9e.png align="center")

Result

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598571579/44f8d0f9-777d-4800-b1b8-e47d5fc1211e.png align="center")

Let’s zoom in on them

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598629081/59bc2b64-6f6b-432b-88ea-a60721a12440.png align="center")

I do see some artifacts around the edges.

Thresholding at 0.75 instead of half way point (0.5) does the trick to make it better.

Zoomed in:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598717639/1678899f-fe59-4a47-9b67-0f44c398a0fb.png align="center")

Full result:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598689688/577e858c-415f-408e-ae5b-d2455de97d58.png align="center")

It’s not perfect.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598749444/d14a2319-3f5f-4c75-be67-ac319a0b6e98.png align="center")

but very good most of the time.

Using 0.8128 as thresholding criteria seems to give better result in black BG

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598824730/2fff1fdc-0b52-47fc-8d7c-947fa5977f76.png align="center")

But, now, it loses continuity of lines against white bgs.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768598859552/32af4d82-e768-4a7d-9f47-ffe294c06bc0.png align="center")

I think it may behave little differently because I am passing it the whole spritesheet at once.

Just doing it on one frame:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768599133784/c6fc055f-5025-4aac-af9e-9861499207f3.png align="center")

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768599144301/b617f021-ca48-4bf5-bb5d-209fa63a313a.png align="center")

seems to give much better result.

To do this per frame, cost is 0.02 per frame.

120 frames would cost 2.4 dollars.

even if I reduce it to 50 frames, it would cost a dollar.

I could run 2×2 grid at a time

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768599457108/3503260a-8d64-47ef-b66b-35af4ecfa0db.png align="center")

Quality is slightly (can’t tell visually) reduced.

and cut the cost by4. that would be around 0.25 cents which would be competitive against our old Flux1.Kontext approach but nowhere close enough to argue against open source or custom model alternatives.

4×4 grid gives me 0.0625 cents which is rather competitive.

---

So what……..

I’m not sure.

I want to go back to not having to use magenta color backgrounds when inferencing at least the stage 1 character gen because it impacts the types of characters being generated.

It is subtle but:

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768601405743/0c3cc7ea-8f29-4720-a960-8c8bc981d827.png align="center")

vs

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768601412141/f7eaef1a-bae6-4019-bec5-d377b2544f5d.png align="center")

The colors used in the magenta backgrounds are more vibrant (**less pastel-ly**).

With PhotoRoom API, we could go back to generating characters on white. Then apply a purple background later.

Alternatively, we could improve the anti-corruption model to be able to perform well on white backgrounds.

---

We also tried ReCraft (through comfy) on character sheet, quality is not the best…… There may be a way to improve it through color bleeding where for each partial transparency, we look neighboring pixels to less-transparent-pixel (or pixel group) then use their color. and dilute it further. We should try that.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1768603330773/44dece6c-4698-4d0a-be45-57033c4c8a0f.png align="center")

---

I will… not change status quo now, but keep this in mind.

I want to rather improve the Anti-corruption model because it is more cost effective.

So two items:

1. I want to revert the template BG back to white.
    
2. I want to get more cost effective inference for matting.
    
3. After inferencing on Whites, we should **change the background dynamically to a color that isn’t used** much in the character. Then we animate on that color, then perform RMBG.
    

— Sprited Dev 🐛
