图像中的彩色边缘检测

时间:2019-05-23 00:54:35

标签: python python-3.x filter edge-detection

如该图所示,我想用紫色标记三个分支的边缘,并将其他区域过滤为纯白色(或其他背景颜色)。我使用Laplacian和sober进行图像梯度处理,然后使用canny方法进行边缘检测。但是,这没有达到我的期望。

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

2 个答案:

答案 0 :(得分:1)

尝试改进它以实现您的目标:

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

答案 1 :(得分:0)

我提出了以下解决方案,

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)