How to exaggerate color differences with OpenCV?


I am trying to make it easier for Canny Edge detection to find edges by exaggerating differences in colors in an image.

For example, giving it the following image:
Image Given

Canny returns:

Image Output

As you can see, Canny omits most of the border of the countertop because the colours are way too similar to be picked up.

Is there a way to increase the contrast or exaggerate color differences in the image?


Unfortunately, this isn’t built-in to opencv from some research.

But, I did find a method on increasing the contrast of an image on the opencv documentation. Try stealing the code from here.

The specific portion you may be looking for:

alpha = 1.0 # Simple contrast control
beta = 0    # Simple brightness control

for y in range(image.shape[0]):
for x in range(image.shape[1]):
    for c in range(image.shape[2]):
        new_image[y,x,c] = np.clip(alpha*image[y,x,c] + beta, 0, 255)

Answered By – jvyden

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published