# Erode without keep borders original brightness

**URL:** https://forum.opencv.org/t/erode-without-keep-borders-original-brightness/4758
**Category:** Uncategorized
**Tags:** imgproc
**Created:** [August 14, 2021, 3:28am UTC](https://forum.opencv.org/t/erode-without-keep-borders-original-brightness/4758 "2021-08-14T03:28:25Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sn4k3](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sn4k3/32/2049_2.png) [@sn4k3](https://forum.opencv.org/u/sn4k3)
#### Post date: [August 14, 2021, 3:28am UTC](https://forum.opencv.org/t/erode-without-keep-borders-original-brightness/4758/1 "2021-08-14T03:28:26Z")

</div>

**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)

 ![UVtools_2021-08-14_04-21-45](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/3/35b935957ae344cee3728b2633378f334dc19e08.png)

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

 ![UVtools_2021-08-14_04-25-03](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/b/b9b1ab3a44d9fd882f64486ffe806ac96ace5fd9.png)

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?

---

<div class="post-metadata">

### Author: ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)
#### Post date: [August 14, 2021, 10:22am UTC](https://forum.opencv.org/t/erode-without-keep-borders-original-brightness/4758/2 "2021-08-14T10:22:15Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![sn4k3](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sn4k3/32/2049_2.png) [@sn4k3](https://forum.opencv.org/u/sn4k3)
#### Post date: [August 14, 2021, 5:04pm UTC](https://forum.opencv.org/t/erode-without-keep-borders-original-brightness/4758/3 "2021-08-14T17:04:09Z")

</div>

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:

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

```
