SLIC_new_cityscapes_training_server_1.py 文件源码

python
阅读 58 收藏 0 点赞 0 评论 0

项目:SLIC_cityscapes 作者: wpqmanu 项目源码 文件源码
def gradient_img(colorsrc):
    '''
        http://docs.opencv.org/doc/tutorials/imgproc/imgtrans/sobel_derivatives/sobel_derivatives.html
    '''
    SCALE = 1
    DELTA = 0
    DDEPTH = cv2.CV_16S  ## to avoid overflow

    # grayscale image
    if len(colorsrc.shape)==2:
        graysrc = cv2.GaussianBlur(colorsrc, (3, 3), 0)

        ## gradient X ##
        gradx = cv2.Sobel(graysrc, DDEPTH, 1, 0, ksize=3, scale=SCALE, delta=DELTA)
        gradx = cv2.convertScaleAbs(gradx)

        ## gradient Y ##
        grady = cv2.Sobel(graysrc, DDEPTH, 0, 1, ksize=3, scale=SCALE, delta=DELTA)
        grady = cv2.convertScaleAbs(grady)

        grad = cv2.addWeighted(gradx, 0.5, grady, 0.5, 0)

        return grad

    # multi-channel image
    else:
        gradx_total = np.zeros((colorsrc.shape[0], colorsrc.shape[1]))
        grady_total = np.zeros((colorsrc.shape[0], colorsrc.shape[1]))
        for index in range(colorsrc.shape[2]):
            graysrc=colorsrc[:,:,index]
            graysrc = cv2.GaussianBlur(graysrc, (3, 3), 0)

            ## gradient X ##
            gradx = cv2.Sobel(graysrc, DDEPTH, 1, 0, ksize=3, scale=SCALE, delta=DELTA)
            gradx = cv2.convertScaleAbs(gradx)
            gradx_total=gradx_total+gradx

            ## gradient Y ##
            grady = cv2.Sobel(graysrc, DDEPTH, 0, 1, ksize=3, scale=SCALE, delta=DELTA)
            grady = cv2.convertScaleAbs(grady)
            grady_total = grady_total + grady

            grad = cv2.addWeighted(gradx_total, 0.5, grady_total, 0.5, 0)

        return grad
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号