Erode without keep borders original brightness

Grayscale 8 bit images
When eroding a object, the borders if different brightness will be kept on that same brightness.
How can i erode by eat/remove the pixels instead of interpolating them?

Example of a normal erode: (Borders brightness are kept)

What i actually need after erode: (Pixels get removed to inner of the object so the border is cleaned)

Please note i can’t threshold the image, as i require the pixels to keep thier original brightness.

The only solution i see is to erode → Copy original to a new Mat with mask of erode. But is there a more direct way with the erode function?

this is expected and intended behavior of grayscale erosion.

if you need your data binarized, binarize it (threshold). use that as a mask to clear pixels you don’t want, while leaving the rest untouched.

Ok thanks for confirm, i thought i could use some border type / value to actually do that…
In this case i will keep with my method which use the erode result as mask:

CvInvoke.Erode(target, erode, kernel, anchor, wallThickness, BorderType.Reflect101, default);
originalRoi.CopyTo(target, erode);