faceswap icon indicating copy to clipboard operation
faceswap copied to clipboard

Histogram matching overreach?

Open Kirin-kun opened this issue 8 years ago • 8 comments

Not sure if it's unavoidable (and it's not the optimal use case), but when the face is partially hidden, the color of the obstacle, if really different from the colors of the face, spills into the converted face in patches with histogram matching:

With Seamless and no histogram matching (a bit blurry on the border, but that's to be expected):

tae0256a

Without Seamless but with histogram matching, becomes a leper:

tae0256

With Seamless AND histogram matching:

tae0256c

Maybe if the color deviates too much, it can be ignored?

Kirin-kun avatar Mar 10 '18 19:03 Kirin-kun

How do you detect that the color deviates too much though?

oatssss avatar Mar 11 '18 07:03 oatssss

same problem 37238911-ea9ea790-2449-11e8-8e44-724d7aa98104 1

iperov avatar Mar 11 '18 07:03 iperov

@oatssss I don't know precisely. If we have an histogram of the colors, there should be a peak, compared to the dominant color, corresponding to the "odd" color(s). With setting a threshold, you could drop them before doing your matching.

Just a suggestion, I'm not knowledgeable enough in image processing to know if it's possible or not.

Kirin-kun avatar Mar 11 '18 08:03 Kirin-kun

On this frame, landmarks debug shows this:

tae0256_0

I suppose the landmarks for mouth and chin are defaults calculated relatively to eyes and nose? The chin is much shorter than the real one.

Would there be a way to store in the alignments file which landmarks were effectively detected, and then at convert time, cut them out? I don't know if the face detector is able to output that information.

Kirin-kun avatar Mar 11 '18 17:03 Kirin-kun

@Kirin-kun That's an interesting idea, we need a method to detect which landmarks weren't effectively detected though. Dlib doesn't have this feature out-of-the-box. We could do what you suggest and have some threshold for the ratio of distances between eyes/nose vs chin/mouth but this seems very specific to your use case where the mouth is covered. Training another classifier as suggested by the dlib author may be the way to go.

oatssss avatar Mar 12 '18 16:03 oatssss

@oatssss it would probably be also useful with other kind of obstacles, like hair in front of eyes, hats covering eyebrows, scarves, in order to avoid for their color to spill on the color correction.

In @iperov 's case, it's the background that interferes with the histogram matching.

Kirin-kun avatar Mar 12 '18 21:03 Kirin-kun

I wonder if we can use the mask from GAN for color matching too. Since it's designed to help find these obstructions and minimize the facial changes.

bryanlyon avatar Mar 12 '18 21:03 bryanlyon

Also, I'm not sure why it appears in blotches. That it would show on the edges of the merged face would be understandable, but why does it appear between the eyes or on the cheeks? And as blotches.

Kirin-kun avatar Mar 13 '18 13:03 Kirin-kun