Makogan
Makogan

Reputation: 9540

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?

Upvotes: 2

Views: 1065

Answers (2)

FabianT17
FabianT17

Reputation: 11

With big image i suggest to work with numpy array like this :

#Open as uint32 prevent values >255 to become negatives
img = np.asarray(cv.imread(fileName),dtype=np.uint32())

alpha=2
beta=0

img=(img*alpha+beta).clip(0,255,out=img)

#back to uint8 type

img2=np.asarray(img,dtype=np.uint8())

Upvotes: 1

jvyden
jvyden

Reputation: 89

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)

Upvotes: 3

Related Questions