Ashwin
Ashwin

Reputation: 333

OpenCV erosion and dilation on colour images

Erosion on a binary image decreases the white regions, while dilation increases it. I tried the same on colour images using OpenCV and got similar results. I tried do erode/dilate on binary jpeg images. Due to lossy compression, the image had intensities in [0,5] and [250,255]. The results I found were interesting. Erosion causes the image to search for the smallest value within a structuring element and replace it. Dilation uses the largest value.

In case of colour images,how are colours considered to be smaller or larger? Do they indirectly convert values to gray, see the intensity and then decide which is larger? Or do they use the mean of the three colours? A third possibility is that they erode/dilate separately on all three colours(R,G,B). Which one of these methods is used?

Upvotes: 8

Views: 12485

Answers (2)

user1196549
user1196549

Reputation:

These morphological operations are uneasy to define for color images as colors convey a vector information (three components) and cannot be compared as smaller/larger.

The common implementations just treat the color planes independently. This has the disadvantage of having no good mathematical justification and introduces colors that aren't present in the original image.

Another option is possible, but nowhere in use, it seems: if you choose one arbitrary color, you can dilate/erode by choosing the color of the pixel which is closest/farthest from the chosen one, in the neighborhoods considered.

Upvotes: 4

Kamyar Infinity
Kamyar Infinity

Reputation: 2759

Each of R,G and B channels are processed separately.

From the manual (emphasis mine):

The function dilates the source image using the specified structuring element that determines the shape of a pixel neighborhood over which the maximum is taken ... The function supports the in-place mode. Dilation can be applied several ( iterations ) times. In case of multi-channel images, each channel is processed independently.

Upvotes: 2

Related Questions