Back Where we Started

Cleaning up for a fresh start

Me:

Ah… that makes sense. 😄

I guess you learned something from this too.

Since MediaPipe wasn’t actually running before, we’ve been relying on the TF.js fallback and piling on workarounds.

Now that MediaPipe is finally working, we should probably clean all of those up, right?

Claude:

Exactly.

Looking back, most of the landmark-based patches we added—face exclusion, shoulder cutoffs, front hair reinforcement—were only compensating for weaknesses in the TF.js + HSV fallback mask.

Now that MediaPipe is working properly, it’s better to strip the pipeline back to the basics.

Let’s start with the raw MediaPipe segmentation, apply only minimal post-processing, and add fixes back only if we can reproduce a real problem.

The next round of testing confirmed it.

MediaPipe was finally working as intended.

Landmarks were stable.

The segmentation mask was being generated correctly.

Claude:

Nice!

MediaPipe is definitely running now.

But I do notice a couple of new issues.

There’s a gray artifact around the forehead.

And I’m also seeing hair-like patterns appearing in the background.

This looks different from the previous problems.

It seems like stray strands are completely ignoring the segmentation boundary, allowing traceStrand() to draw across the entire canvas.

After reading that, I went back to the code.

Then something suddenly felt wrong.

Iterative Fixes and Architectural Redesign

Me:

Wait a second…

The original hair flow doesn’t even have those stray strands on the sides.

So why would they suddenly appear just because I changed the hairstyle?

Shouldn’t every style adjustment start from the original result, and only modify what comes after it?

Claude:

You’re right.

Looking at the implementation, traceStrand() isn’t extending the existing path.

It’s rebuilding the entire strand from scratch based on the final target length.

Because stepLen scales with scaledLen, even the base section gets recalculated along a different path.

That seems to be the root cause.

Me:

I get what you mean.

But that’s not really the point I’m trying to make.

We’ve already removed those stray strands from the original hair flow.

So when a style adjustment is applied, it should always begin from that cleaned-up result.

The adjustment only happens after the original path ends.

Those stray strands should never come back in the first place.

That single sentence completely changed the design direction.

Claude:

You’re absolutely right.

The style adjustment shouldn’t recreate the original path.

It should inherit the original path exactly as it is.

That means:

Inside the segmentation mask, the path must remain identical to the original.
Only after reaching the end of the original path should the extension be generated—even if it goes beyond the segmentation boundary.

With that, the new pipeline became much simpler.

Inside Segmentation
(Original Hair Path)

Reach Original End

Generate Extension
(Style Adjustment Only)

Instead of recalculating everything from the beginning, the style now extends what already exists.

Sometimes the biggest improvement isn’t a new algorithm.

It’s realizing that the algorithm was starting from the wrong place all along.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *