Jeremy_Tamu
Jeremy_Tamu

Reputation: 755

Color Edge Detection in an image

As shown in this image, I want to label the edges of three branches with purple color and filter other area as purely white color (or other background color). I use Laplacian and sober to do image gradient and then use canny method to do edge detection. However, it does not reach my expectation.

import cv2
import numpy as np
from matplotlib import pyplot as plt

if __name__ == '__main__' :

    # Read image
    im = cv2.imread("crop.jpg")

    # Calculation of Laplacian 
    laplacian = cv2.Laplacian(imCrop,cv2.CV_64F) 

    edges = cv2.Canny(laplacian,35,35)

enter image description here

Upvotes: 1

Views: 2664

Answers (2)

Jeremy_Tamu
Jeremy_Tamu

Reputation: 755

I came up with a solution as below,

import cv2
import numpy as np
from matplotlib import pyplot as plt

if __name__ == '__main__' :

    # Read image
    im = cv2.imread("crop.jpg")
    a=np.copy(im)

    a[:,:,0]=255
    a[:,:,1]=255
    a[a>150]=255

    plt.imshow(a)

Upvotes: 0

Freddy Daniel
Freddy Daniel

Reputation: 389

Try to improve it to get your goal:

import cv2

image = cv2.imread("test.jpg")
#convert to hsv
i = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
i[: ,:, 0]=0
i[: ,:, 2]=0
#s channel 
cv2.imshow("s channel", i)

Image output with s channel

Upvotes: 1

Related Questions