Tensorflow를 사용하여 Canny 알고리즘을 구현합니다 (이것은 경계를 평가 척도로 사용하는 데 필요하지만 주제는 아닙니다). 하나의 단계는 "최대가 아닌 억제 (Non-maximum Suppression)"를 계산하는 것인데, 이는 특정 이웃이 더 작지 않은 한 3x3 영역에서 중심 요소를 제로화하는 것입니다. 더 자세한 내용 here.인접 요소와 관련된 텐서의 조건 값
Tensorflow를 사용하여이 작업을 수행하려면 어떻게해야합니까?
내가 실제로 Keras를 사용하고 있지만, Tensorflow 솔루션은 참조를 위해 잘 작동합니다, 내 코드는 지금까지 다음과 같습니다
def canny(img):
'''Canny border detection. The input should be a grayscale image.'''
gauss_kernel = np.array([[2, 4, 5, 4, 2],
[4, 9, 12, 9, 4],
[5, 12, 15, 12, 5],
[4, 9, 12, 9, 4],
[2, 4, 5, 4, 2]]).reshape(5, 5, 1, 1)
gauss_kernel = K.variable(1./159 * gauss_kernel)
Gx = K.variable(np.array([[-1., 0. ,1.],
[-2., 0., 2.],
[-1., 0., 1.]]).reshape(3, 3, 1, 1))
Gy = K.variable(np.array([[-1., -2., -1.],
[ 0., 0., 0.],
[ 1., 2., 1.]]).reshape(3, 3, 1, 1))
# Smooth image
smoothed = K.conv2d(img, gauss_kernel, padding='same')
# Derivative in x
Dx = K.conv2d(smoothed, Gx, padding='same')
# Derivative in y
Dy = K.conv2d(smoothed, Gy, padding='same')
# Take gradient strength
G = K.sqrt(K.square(Dx) + K.square(Dy))
# TODO: Non-maximum Suppression & Hysteresis Thresholding
return G
다른 접근 방식으로 시도했지만이 아이디어는 완벽했습니다. 고맙습니다! –