Ask Your Question
0

change colour of canny output

asked 2017-04-14 15:03:48 -0600

kadil gravatar image

I have a small script to visualise focus on an image, and very happy with the result but I want to be able to change the highlighted edges (currently white) to a different colour before overlaying on to the original image. My (cut-and-paste) code below, please help.

import cv2
import numpy as np
import matplotlib.pyplot as plot

im = cv2.imread('tests.jpg',0)
im2 = cv2.imread('tests.jpg')
edges = cv2.Canny(im,100,200)
out = np.bitwise_or(im2, edges[:,:,np.newaxis])
implot = plot.imshow(cv2.cvtColor(out, cv2.COLOR_BGR2RGB))
plot.show()

Thanks in advance

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2017-04-15 01:21:59 -0600

berak gravatar image

updated 2017-04-15 04:30:43 -0600

 # step 1: make a3 channel, bgr or rgb image from the canny output:
 edges = cv2.Canny(m,100,200)
 rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB) # RGB for matplotlib, BGR for imshow() !

 # step 2: now all edges are white (255,255,255). to make it red, multiply with another array:
 rgb *= np.array((1,0,0),np.uint8) # set g and b to 0, leaves red :)

 # step 3: compose:
 out = np.bitwise_or(im2, rgb)
edit flag offensive delete link more
0

answered 2018-11-02 06:12:39 -0600

C++ implementation:

cv::Canny(im, edges, 100, 200);
// convert canny to BGR
cv::cvtColor(edges, edges, CV_GRAY2BGR); 
// multiply to make it red
red_canny = edges.mul(cv::Scalar(255, 0, 0), 1);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-04-14 15:01:45 -0600

Seen: 4,771 times

Last updated: Apr 15 '17